-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support for comma-separated list of declarations with attributes in non-leading position #77
Conversation
@@ -956,7 +956,20 @@ static_assert_declaration: | |||
; | |||
init_declarator_list: /* ISO 6.7 */ | |||
init_declarator { [$1] } | |||
| init_declarator COMMA init_declarator_list { $1 :: $3 } | |||
| init_declarator COMMA init_declarator_attr_list { $1 :: $3 } |
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 guess if Frama-C uses this, it should be fine, but I'm now curious about how the first init_declarator
is handled differently now: it cannot have attributes while all the others can. I guess you can still write attributes before the first declarator, but aren't those attributes of the type itself, not of the particular variable being declared? And if that's part of the type, then that applies to all the variables being declared, no?
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.
An attribute specifier list may appear immediately before a declarator (other than the first) in a comma-separated list of declarators in a declaration of more than one identifier using a single list of specifiers and qualifiers. Such attribute specifiers apply only to the identifier before whose declarator they appear.
https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
So GCC also treats the first element differently here. If one wants to attach an attribute to the first declaration, one can put the entire thing into parens, and then it is unambiguous once again.
And yes, I think any attributes appearing there are then considered to be part of the type. But tbh, after reading this section of the GCC manual, it seems to me like this entire attribute business is a huge mess. Luckily, we don't really do much with most of them.
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.
Maybe just add a TODO there with some link, so if attributes on the first declaration ever become an issue, we know we don't properly handle them.
for first declarator in comma-separated list
CHANGES: * Wrap library into `GoblintCil` module (goblint/cil#107). * Remove all MSVC support (goblint/cil#52, goblint/cil#88). * Port entire build process from configure/make to dune (goblint/cil#104). * Add C11 `_Generic` support (goblint/cil#48). * Add C11 `_Noreturn` support (goblint/cil#58). * Add C11 `_Static_assert` support (goblint/cil#62). * Add C11 `_Alignof` support (goblint/cil#66). * Add C11 `_Alignas` support (goblint/cil#93, goblint/cil#108). * Add partial C11 `_Atomic` support (goblint/cil#61). * Add `_Float32`, `_Float64`, `_Float32x` and `_Float64x` type support (goblint/cil#8, goblint/cil#60). * Add Universal Character Names, `char16_t` and `char32_t` type support (goblint/cil#80). * Change locations to location spans and add additional expression locations (goblint/cil#51). * Add synthetic marking for CIL-inserted statement locations (goblint/cil#98). * Expose list of files from line control directives (goblint/cil#73). * Add parsed location transformation hook (goblint/cil#89). * Use Zarith for integer constants (goblint/cil#47, goblint/cil#53). * Fix constant folding overflows (goblint/cil#59). * Add option to disable constant branch removal (goblint/cil#103). * Add standalone expression parsing and checking (goblint/cil#97, goblint/cil#96). * Improve inline function merging (goblint/cil#72, goblint/cil#85, goblint/cil#84, goblint/cil#86). * Fix some attribute parsing cases (goblint/cil#71, goblint/cil#75, goblint/cil#76, goblint/cil#77). * Fix global NaN initializers (goblint/cil#78, goblint/cil#79). * Fix `cilly` binary installation (goblint/cil#99, goblint/cil#100, goblint/cil#102). * Remove batteries dependency to support OCaml 5 (goblint/cil#106).
CHANGES: * Wrap library into `GoblintCil` module (goblint/cil#107). * Remove all MSVC support (goblint/cil#52, goblint/cil#88). * Port entire build process from configure/make to dune (goblint/cil#104). * Add C11 `_Generic` support (goblint/cil#48). * Add C11 `_Noreturn` support (goblint/cil#58). * Add C11 `_Static_assert` support (goblint/cil#62). * Add C11 `_Alignof` support (goblint/cil#66). * Add C11 `_Alignas` support (goblint/cil#93, goblint/cil#108). * Add partial C11 `_Atomic` support (goblint/cil#61). * Add `_Float32`, `_Float64`, `_Float32x` and `_Float64x` type support (goblint/cil#8, goblint/cil#60). * Add Universal Character Names, `char16_t` and `char32_t` type support (goblint/cil#80). * Change locations to location spans and add additional expression locations (goblint/cil#51). * Add synthetic marking for CIL-inserted statement locations (goblint/cil#98). * Expose list of files from line control directives (goblint/cil#73). * Add parsed location transformation hook (goblint/cil#89). * Use Zarith for integer constants (goblint/cil#47, goblint/cil#53). * Fix constant folding overflows (goblint/cil#59). * Add option to disable constant branch removal (goblint/cil#103). * Add standalone expression parsing and checking (goblint/cil#97, goblint/cil#96). * Improve inline function merging (goblint/cil#72, goblint/cil#85, goblint/cil#84, goblint/cil#86). * Fix some attribute parsing cases (goblint/cil#71, goblint/cil#75, goblint/cil#76, goblint/cil#77). * Fix global NaN initializers (goblint/cil#78, goblint/cil#79). * Fix `cilly` binary installation (goblint/cil#99, goblint/cil#100, goblint/cil#102). * Remove batteries dependency to support OCaml 5 (goblint/cil#106).
Fixes #76. In later declarations attributes may appear without leading parenthesis. A naive fix would introduce tons of conflicts once again.
The fix here is imported from the (absorbed) CIL fork used by Frama-C (allowed by the license of the components that used to be part of
frontc
/CIL) at https://git.frama-c.com/pub/frama-c/-/blob/master/src/kernel_internals/parsing/cparser.mly.