-
Notifications
You must be signed in to change notification settings - Fork 280
C front-end: initializer lists do not initialise anonymous members #5688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportBase: 78.34% // Head: 78.34% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #5688 +/- ##
========================================
Coverage 78.34% 78.34%
========================================
Files 1644 1645 +1
Lines 190313 190381 +68
========================================
+ Hits 149097 149156 +59
- Misses 41216 41225 +9
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
f57b412
to
55c955a
Compare
a1076c7
to
ac8dd60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The small part that touches area I maintain looks OK. I'm not sure the tests have enough context for me to really check what is going on with them.
@@ -1,6 +1,6 @@ | |||
CORE | |||
main.c | |||
|
|||
--i386-win32 | |||
^EXIT=0$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unrelated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is a relevant change. We previously wrongly supported the code in this test on all platforms: it uses anonymous (but tagged) union members.
ac8dd60
to
8df2a13
Compare
8df2a13
to
b21e6b5
Compare
91e47de
to
1ab17a4
Compare
1ab17a4
to
e908072
Compare
Are zero-width bit-fields considered when processing initialiser lists? |
The C standard requires "The expression that specifies the width of a bit-field [...]. If the value is zero, the declaration shall have no declarator." GCC and Clang enforce this, we did not. I'll put together a PR to ensure our C front-end becomes equally strict. |
e908072
to
ee50473
Compare
src/ansi-c/c_typecheck_type.cpp
Outdated
if( | ||
(new_component.type().id() != ID_struct_tag && | ||
new_component.type().id() != ID_union_tag) || | ||
follow(new_component.type()).find(ID_tag).is_not_nil()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the follow do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to distinguish untagged (anonymous) structs/unions from ones that are named.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have extended the comment above this code now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest using to_tag_type
to make this clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rewritten it to use to_struct_tag_type
and to_union_tag_type
.
8e16ac6
to
1f2aea9
Compare
e650662
to
af9a202
Compare
af9a202
to
6b0241c
Compare
6b0241c
to
a9b5182
Compare
a9b5182
to
e80a063
Compare
Compilers differ in their handling of anonymous members, also depending on the type of the anonymous member. Make sure we accurately model this while type checking. Consequently, regression tests need to be amened to either be compiler-specific or not rely on anonymous or empty compound types, which dump-c also must not spuriously generate (from incomplete structs or unions). New tests are based on a case found by C-Reduce when starting from an SV-COMP task. Behaviour across different compilers confirmed with Compiler Explorer (https://godbolt.org/).
e80a063
to
5d3e9a8
Compare
We already took care of this in another place in
c_typecheck_initializer, but did not handle initializer lists correctly.
The test is based on a case found by C-Reduce when starting from an
SV-COMP task.