This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81656] New: incompatible _Alignas silently accepted
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 01 Aug 2017 20:15:45 +0000
- Subject: [Bug c/81656] New: incompatible _Alignas silently accepted
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81656
Bug ID: 81656
Summary: incompatible _Alignas silently accepted
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
While testing my improvements to detect mutually exclusive attribute
specifications I came across another problem, this one specific to the _Alignas
specifier (but it should also apply to attribute aligned. both on objects and
functions).
In 6.7.5, p7, C11 specifies the following two requirements on _Alignas:
If the definition of an object has an alignment specifier, any other
declaration of that object shall either specify equivalent alignment or have no
alignment specifier. If the definition of an object does not have an alignment
specifier, any other declaration of that object shall also have no alignment
specifier.
The test case below violates both of these requirements and so should be
diagnosed but isn't. The problem seems to be (as in bug 81544 and some
others) that the handle_aligned_attribute() function in c-family/c-attribs.c
doesn't have access to the last declaration as it processes a new one. That
GCC manages to do the reasonable thing despite it (i.e., use the most
restrictive alignment) means that some other mechanism must detect and resolve
the conflict, but without diagnosing it.
$ cat b.c && gcc -O2 -S -Wall -Wextra -Wpedantic -o /dev/stdout b.c
extern _Alignas (32) int a;
_Alignas (8) int a = 32; // violates sentence 1
extern _Alignas (32) int b;
extern _Alignas (16) int b;
extern _Alignas (8) int b;
int b = 32; // violates sentence 2
.file "b.c"
.globl b
.data
.align 32
.type b, @object
.size b, 4
b:
.long 32
.globl a
.align 32
.type a, @object
.size a, 4
a:
.long 32
.ident "GCC: (GNU) 8.0.0 20170727 (experimental)"
.section .note.GNU-stack,"",@progbits