Skip to content

Commit 63d6ac8

Browse files
committed
Add field-sensitivity tests
These look at various cases of struct-field assignment, directly and via pointers; only one case is identified as not using the field-sensitivity machinery so far (that of a pointer that may point to several different offsets within the same target allocation). These are added now so that forthcoming changes to field-sensitivity have a reasonably comprehensive regression test suite to check against.
1 parent 69a9528 commit 63d6ac8

File tree

26 files changed

+402
-0
lines changed

26 files changed

+402
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <assert.h>
2+
3+
struct A {
4+
int x;
5+
int y;
6+
};
7+
8+
int main(int argc, char **argv) {
9+
10+
struct A a;
11+
a.x = argc;
12+
a.y = argc + 1;
13+
assert(a.x == argc);
14+
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
main::1::a!0@1#2\.\.x = main::argc!0@1#1
5+
main::1::a!0@1#2\.\.y = 1 \+ main::argc!0@1#1
6+
--
7+
main::1::a!\d+@\d+#\d+\.x
8+
main::1::a!\d+@\d+#\d+\.y
9+
--
10+
Fields A::x and A::y should be referred to as atomic symbols (a..x and a..y) but not using
11+
member operators (a.x and a.y).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
struct A {
4+
int x;
5+
int y;
6+
int z;
7+
};
8+
9+
int main(int argc, char **argv) {
10+
11+
struct A a1, a2;
12+
char *field = (argc % 2 ? (char*)&a1.y : (char*)&a2.z) + 1;
13+
*field = (char)argc;
14+
assert(a1.y == argc);
15+
assert(a2.z == argc);
16+
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
main::1::a1!0@1#2\.\.y =
5+
main::1::a2!0@1#2\.\.z =
6+
--
7+
main::1::a[12]!\d+@\d+#\d+\.[xyz]
8+
--
9+
Fields A::y and A::z should be referred to as atomic symbols (a[12]..y and a[12]..z) but not using
10+
member operators (a[12].[xyz]).
11+
While the field is aliased with a different type, the typecast is successfully reduced to address just
12+
one field, rather than using a byte-update operation against the whole structure.
13+
This is like field-sensitivity8 except the pointer leads into the middle of a field.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
struct A {
4+
int x;
5+
int y;
6+
};
7+
8+
int main(int argc, char **argv) {
9+
10+
struct A a1, a2;
11+
a1.x = argc;
12+
a1.y = argc + 1;
13+
a2 = a1;
14+
assert(a2.x == argc);
15+
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
main::1::a1!0@1#2\.\.x = main::argc!0@1#1
5+
main::1::a1!0@1#2\.\.y = 1 \+ main::argc!0@1#1
6+
main::1::a2!0@1#2\.\.x = main::1::a1!0@1#2\.\.x
7+
main::1::a2!0@1#2\.\.y = main::1::a1!0@1#2\.\.y
8+
--
9+
main::1::a[12]!\d+@\d+#\d+\.[xy]
10+
--
11+
Fields A::x and A::y should be referred to as atomic symbols (a[12]..x and a[12]..y) but not using
12+
member operators (a[12].x and a[12].y).
13+
This test looks at the particular case of whole-struct assignment.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
3+
struct A {
4+
int x;
5+
int y;
6+
};
7+
8+
int main(int argc, char **argv) {
9+
10+
struct A a1, a2;
11+
a1.x = argc;
12+
a1.y = argc + 1;
13+
struct A *aptr = argc % 2 ? &a1 : &a2;
14+
*aptr = a1;
15+
assert(a2.x == argc);
16+
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
main::1::a1!0@1#2\.\.x = main::argc!0@1#1
5+
main::1::a1!0@1#2\.\.y = 1 \+ main::argc!0@1#1
6+
main::1::a1!0@1#3\.\.x = main::1::a1!0@1#2\.\.x
7+
main::1::a1!0@1#3\.\.y = main::1::a1!0@1#2\.\.y
8+
main::1::a2!0@1#2\.\.x =
9+
main::1::a2!0@1#2\.\.y =
10+
--
11+
main::1::a[12]!\d+@\d+#\d+\.[xy]
12+
--
13+
Fields A::x and A::y should be referred to as atomic symbols (a[12]..x and a[12]..y) but not using
14+
member operators (a[12].x and a[12].y).
15+
This test looks at the particular case of whole-struct assignment when the target of the assignment
16+
is uncertain due to pointer indirection.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
3+
struct A {
4+
int x;
5+
int y;
6+
};
7+
8+
struct B {
9+
struct A a;
10+
int z;
11+
};
12+
13+
int main(int argc, char **argv) {
14+
15+
struct B b1, b2;
16+
b1.a.x = argc;
17+
b1.a.y = argc + 1;
18+
struct A *aptr = argc % 2 ? &b1.a : &b2.a;
19+
*aptr = b1.a;
20+
assert(b2.a.x == argc);
21+
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
main::1::b1!0@1#2\.\.a\.\.x = main::argc!0@1#1
5+
main::1::b1!0@1#2\.\.a\.\.y = 1 \+ main::argc!0@1#1
6+
main::1::b1!0@1#3\.\.a\.\.x = main::1::b1!0@1#2\.\.a\.\.x
7+
main::1::b1!0@1#3\.\.a\.\.y = main::1::b1!0@1#2\.\.a\.\.y
8+
main::1::b2!0@1#2\.\.a\.\.x =
9+
main::1::b2!0@1#2\.\.a\.\.y =
10+
--
11+
main::1::b[12]!\d+@\d+#\d+\.a
12+
--
13+
Fields A::x and A::y should be referred to as atomic symbols (b[12]..a..x and b[12]..a..y) but not using
14+
member operators (b[12].a.x and b[12].a.y).
15+
This test looks at the particular case of whole-struct assignment when the target of the assignment
16+
is uncertain due to pointer indirection.

0 commit comments

Comments
 (0)