Skip to content

Commit 6672791

Browse files
authored
Merge pull request #5688 from tautschnig/anonymous-members
C front-end: initializer lists do not initialise anonymous members
2 parents 8ed5e40 + 5d3e9a8 commit 6672791

File tree

36 files changed

+218
-49
lines changed

36 files changed

+218
-49
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
int blah(void);
22
; // empty!
33

4+
#ifndef _MSC_VER
45
struct some
56
{
67
; // empty
78
};
9+
#endif
810

911
int main() {
1012
}

regression/ansi-c/Union_Initialization2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33

4-
union member designator found for empty union
4+
(union member designator found for empty union|C requires that a struct or union has at least one member)
55
^SIGNAL=0$
66
^EXIT=(1|64)$
77
--

regression/ansi-c/_Generic1/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
struct some: 5 \
1414
)
1515

16+
#ifdef __GNUC__
1617
struct some
1718
{
1819
} s;
@@ -22,7 +23,6 @@ char ch;
2223
long double ld;
2324
short sh;
2425

25-
#ifdef __GNUC__
2626
STATIC_ASSERT(G(i)==3);
2727
STATIC_ASSERT(G(sh)==10);
2828
STATIC_ASSERT(G(ld)==1);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1+
#ifdef _MSC_VER
2+
// No _Static_assert in Visual Studio
3+
# define _Static_assert(condition, message) static_assert(condition, message)
4+
#endif
5+
16
struct S
27
{
38
struct
49
{
510
int : 1;
11+
#ifndef _MSC_VER
612
int;
13+
#endif
714
int named;
815
};
916
};
1017

18+
_Static_assert(sizeof(struct S) == sizeof(int) * 2, "ignore int;");
19+
1120
struct S s = {.named = 0};
1221

22+
struct S1
23+
{
24+
struct S2
25+
{
26+
int : 1;
27+
int named;
28+
};
29+
};
30+
31+
#ifdef _MSC_VER
32+
_Static_assert(sizeof(struct S1) == sizeof(int) * 2, "");
33+
#else
34+
_Static_assert(sizeof(struct S1) == 0, "");
35+
#endif
36+
1337
int main()
1438
{
1539
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#define static_assert(x) \
2+
struct \
3+
{ \
4+
char some[(x) ? 1 : -1]; \
5+
}
6+
7+
struct a
8+
{
9+
};
10+
struct c
11+
{
12+
struct a;
13+
void *d;
14+
} e =
15+
{
16+
#ifdef not_permitted
17+
{},
18+
#endif
19+
0},
20+
e2;
21+
struct
22+
{
23+
struct c f;
24+
} * g;
25+
int main()
26+
{
27+
g->f;
28+
static_assert(sizeof(e) == sizeof(void *));
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE gcc-only
2+
main.c
3+
-Dnot_permitted
4+
cannot initialize 'void \*' with an initializer list
5+
^CONVERSION ERROR$
6+
^EXIT=(1|64)$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE gcc-only
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
typedef void(keyhandler_fn_t)(void);
2+
typedef void(irq_keyhandler_fn_t)(int);
3+
4+
void foo()
5+
{
6+
}
7+
8+
struct keyhandler
9+
{
10+
union
11+
{
12+
keyhandler_fn_t *fn;
13+
irq_keyhandler_fn_t *irq_fn;
14+
};
15+
const char *desc;
16+
_Bool x, y;
17+
} key_table[3] = {[0] = {{(keyhandler_fn_t *)(foo)}, "text", 1, 0}};
18+
19+
int main()
20+
{
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/ansi-c/sizeof3/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define STATIC_ASSERT(condition) \
55
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
66

7+
#ifndef _MSC_VER
78
struct empty_struct { };
89
union empty_union { };
910

@@ -16,6 +17,7 @@ struct combination {
1617
STATIC_ASSERT(sizeof(struct empty_struct)==0);
1718
STATIC_ASSERT(sizeof(union empty_union)==0);
1819
STATIC_ASSERT(sizeof(struct combination)==sizeof(int));
20+
#endif
1921

2022
int main()
2123
{

regression/ansi-c/struct5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
3+
--i386-win32
44
^EXIT=0$
55
^SIGNAL=0$
66
--

regression/cbmc-concurrency/invalid_object1/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct OpenEthState
134134

135135
struct device
136136
{
137+
int dummy;
137138
};
138139

139140
struct napi_struct

regression/cbmc-library/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ else()
66
add_test_pl_profile(
77
"cbmc-library"
88
"$<TARGET_FILE:cbmc>"
9-
"-C;-X;unix"
9+
"-C;-X;unix;-X;gcc-only"
1010
"CORE"
1111
)
1212
endif()

regression/cbmc-library/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ include ../../src/common
55

66
ifeq ($(BUILD_ENV_),MSVC)
77
unix_only = -X unix
8+
gcc_only = -X gcc-only
89
endif
910

1011
test:
11-
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(unix_only)
12+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(unix_only) $(gcc_only)
1213

1314
tests.log: ../test.pl
14-
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(unix_only)
15+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(unix_only) $(gcc_only)
1516

1617
clean:
1718
find . -name '*.out' -execdir $(RM) '{}' \;

regression/cbmc-library/memcpy-06/test.desc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
function 'memcpy' is not declared
@@ -8,3 +8,6 @@ parameter "memcpy::dst" type mismatch
88
--
99
^warning: ignoring
1010
Invariant check failed
11+
--
12+
This test requires support for empty structs, which aren't supported by Visual
13+
Studio.

regression/cbmc-library/memcpy-09/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^VERIFICATION SUCCESSFUL$

regression/cbmc/Anonymous_Struct2/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// The member without name is a Visual Studio feature
22
// https://msdn.microsoft.com/en-us/library/z2cx9y4f.aspx
33

4+
#ifdef _MSC_VER
5+
# include <assert.h>
6+
47
struct X
58
{
69
struct
@@ -47,3 +50,8 @@ int main()
4750
assert(s2.y==1);
4851
assert(s2.z==1);
4952
}
53+
#else
54+
int main()
55+
{
56+
}
57+
#endif

regression/cbmc/Anonymous_Struct3/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <assert.h>
2-
31
// The member without name is a Visual Studio feature
42
// https://msdn.microsoft.com/en-us/library/z2cx9y4f.aspx
53
typedef union my_U {
@@ -19,7 +17,7 @@ int main()
1917
x.f1 = 1;
2018

2119
if(*(char *)&word==1)
22-
assert(x.raw==2); // little endian
20+
__CPROVER_assert(x.raw == 2, "little endian");
2321
else
24-
assert(x.raw==64); // big endian
22+
__CPROVER_assert(x.raw == 64, "big endian");
2523
}

regression/cbmc/Anonymous_Struct3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
3+
-win32
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

regression/cbmc/Empty_struct1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc/Empty_struct2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc/Empty_struct3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--json-ui
44
VERIFICATION FAILED

regression/cbmc/Malloc10/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <assert.h>
12
#include <stdlib.h>
23

34
void __blast_assert()
@@ -7,6 +8,7 @@ void __blast_assert()
78

89
struct list_head
910
{
11+
int dummy;
1012
};
1113

1214
struct list_head *elem = (struct list_head *)((void *)0);

regression/cbmc/Union_Initialization2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=10$

regression/cbmc/atomic_section_seq1/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct OpenEthState$link4
200200

201201
struct device
202202
{
203+
int dummy;
203204
};
204205

205206
struct napi_struct
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
33

44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
--
88
^warning: ignoring
9-
--
10-
This test involves empty structs, which the SMT2 back-end does not currently
11-
support.

regression/cbmc/empty_compound_type1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc/empty_compound_type2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--pointer-check
44
^EXIT=10$

regression/cbmc/empty_compound_type3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=10$

regression/cbmc/empty_compound_type4/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33
--trace
44
^VERIFICATION FAILED$

regression/cbmc/struct1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE gcc-only
22
main.c
33

44
^EXIT=0$

regression/cbmc/union/union_member.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
struct s
44
{
5-
union U
5+
union
66
{
77
char b[2];
88
};

regression/goto-cc-goto-analyzer/instrument_preconditions_locations/s2n_hash_inlined.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct s2n_evp_digest
1717
const void *ctx;
1818
};
1919
union s2n_hash_low_level_digest {
20+
void *dummy; // for MSVC compatibility
2021
};
2122
struct s2n_hash_evp_digest
2223
{

0 commit comments

Comments
 (0)