https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99975
Bug ID: 99975
Summary: wrong variable alignment on a locally redeclared
overaligned extern variable
Product: gcc
Version: 11.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: ---
Perhaps due to the same underlying bug as pr99974, the C++ front end determines
the wrong alignment from an overaligned extern variable redeclared locally
without the alignment attribute.
Both the C front end as well as other compilers (Clang and ICC) behave
correctly and determine the same alignment in both functions.
$ cat z.C && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O -S -Wall
-fdump-tree-optimized=/dev/stdout z.C
extern __attribute__ ((aligned (32))) int i;
int fa32 ()
{
return __alignof__ (i); // folded to 32 (good)
}
int ga32 ()
{
extern int i;
return __alignof__ (i); // folded to 4 (bug)
}
;; Function fa32 (_Z4fa32v, funcdef_no=0, decl_uid=2347, cgraph_uid=1,
symbol_order=0)
int fa32 ()
{
<bb 2> [local count: 1073741824]:
return 32;
}
;; Function ga32 (_Z4ga32v, funcdef_no=1, decl_uid=2349, cgraph_uid=2,
symbol_order=1)
int ga32 ()
{
<bb 2> [local count: 1073741824]:
return 4;
}