Skip to content

Commit 4548fc1

Browse files
author
Daniel Kroening
committed
fix anonymous struct member initialization
The C front-end needs to ignore the unnamed bit-field during struct initialization; issue #3709.
1 parent 5419894 commit 4548fc1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

regression/cbmc/Struct_Initialization1/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
struct tag1 {
44
int f;
55
int : 32; // unnamed bit-field, ignored during initialization
6-
int g;
6+
union {
7+
int g;
8+
}; // anonymous, but not ignored
79
int *p;
810
int a[2];
911
} x;

regression/cbmc/Struct_Initialization1/test.desc

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

44
^EXIT=0$

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,16 @@ void c_typecheck_baset::increment_designator(designatort &designator)
665665
assert(components.size()==entry.size);
666666

667667
// we skip over any padding or code
668-
while(entry.index<entry.size &&
668+
// we also skip over anonymous members
669+
while(entry.index < entry.size &&
669670
(components[entry.index].get_is_padding() ||
670-
components[entry.index].type().id()==ID_code))
671+
(components[entry.index].get_anonymous() &&
672+
components[entry.index].type().id() != ID_struct_tag &&
673+
components[entry.index].type().id() != ID_union_tag) ||
674+
components[entry.index].type().id() == ID_code))
675+
{
671676
entry.index++;
677+
}
672678

673679
if(entry.index<entry.size)
674680
entry.subtype=components[entry.index].type();

0 commit comments

Comments
 (0)