C front-end: fix processing of alignment and packing attributes#8454
C front-end: fix processing of alignment and packing attributes#8454tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8454 +/- ##
===========================================
+ Coverage 80.01% 80.02% +0.01%
===========================================
Files 1700 1700
Lines 188344 188382 +38
Branches 73 78 +5
===========================================
+ Hits 150701 150754 +53
+ Misses 37643 37628 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| power(2, align_int->floorPow2()) != *align_int) | ||
| { | ||
| throw errort().with_location(type.source_location()) | ||
| << "alignment is not a positive power of 2"; |
There was a problem hiding this comment.
Is that a requirement in the standard?
There was a problem hiding this comment.
C11 6.2.8 "Alignment of objects" includes the following sentence: "Every valid alignment value shall be a nonnegative integral power of two."
5eea045 to
0367e2c
Compare
0367e2c to
42011e8
Compare
There was a problem hiding this comment.
Pull request overview
Fixes C front-end handling of GCC packed and aligned attributes so packing is applied during type definition while alignment also affects later uses, and ignores attribute placements that GCC accepts but ignores.
Changes:
- Update grammar action for
sue_declaration_specifierto drop ignoredpacked/alignedattributes before merging specifiers. - Add alignment validation (power-of-two) and introduce
align_toto combine alignments across redefinitions / typedef uses. - Add a regression test covering many attribute placements and interactions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/ansi-c/parser.y |
Filters out ignored packed/aligned attributes in a specific specifier context to match GCC behavior. |
src/ansi-c/c_typecheck_type.cpp |
Validates alignment values and combines alignments when reusing/redefining types. |
regression/ansi-c/gcc_attributes16/test.desc |
Adds expected-output configuration for the new regression test. |
regression/ansi-c/gcc_attributes16/main.c |
Adds C source covering many packed/aligned placements and expected sizeof results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Packing needs to be evaluated as part of the definition of the type while alignment applies also when using a type. The position of the attribute also requires extra care as some positions are accepted by GCC (and warned about by Clang) while actually being ignored. Fixes: diffblue#8443 Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
42011e8 to
200002c
Compare
Packing needs to be evaluated as part of the definition of the type while alignment applies also when using a type. The position of the attribute also requires extra care as some positions are accepted by GCC (and warned about by Clang) while actually being ignored.
Fixes: #8443