https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97468
Bug ID: 97468 Summary: gcc crashes when using __may_alias__ attribute Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: tangyixuan at mail dot dlut.edu.cn Target Milestone: --- Hi, the following code uses '__attribute__ ((__may_alias__))' to alias a struct 'S' to 'a'. However, gcc crashes at compilation time while clang successfully compiles. gcc doc: https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Common-Type-Attributes.html#Common-Type-Attributes 'Accesses through pointers to types with this attribute are not subject to type-based alias analysis, but are instead assumed to be able to alias any other type of objects.' $ cat s.cpp template<typename T> struct S{}; auto __attribute__ ((__may_alias__)) a=S<int>{}; $ g++ -c s.cpp s.cpp:2:38: internal compiler error: in layout_type, at stor-layout.c:2618 2 | auto __attribute__ ((__may_alias__)) a=S<int>{}; | ^ 0x62d384 layout_type(tree_node*) ../../gcc-11-20201011/gcc/stor-layout.c:2618 0xebaf34 type_hash_canon(unsigned int, tree_node*) ../../gcc-11-20201011/gcc/tree.c:7140 0x7e6beb build_type_attribute_qual_variant(tree_node*, tree_node*, int) ../../gcc-11-20201011/gcc/attribs.c:1166 0x7e8702 build_type_attribute_variant(tree_node*, tree_node*) ../../gcc-11-20201011/gcc/attribs.c:1377 0x7e8702 decl_attributes(tree_node**, tree_node*, int, tree_node*) ../../gcc-11-20201011/gcc/attribs.c:794 0x6d9e93 cplus_decl_attributes(tree_node**, tree_node*, int) ../../gcc-11-20201011/gcc/cp/decl2.c:1595 0x6cd1bf start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) ../../gcc-11-20201011/gcc/cp/decl.c:5267 0x7590ce cp_parser_init_declarator ../../gcc-11-20201011/gcc/cp/parser.c:20936 0x73a65c cp_parser_simple_declaration ../../gcc-11-20201011/gcc/cp/parser.c:13878 0x7630a6 cp_parser_declaration ../../gcc-11-20201011/gcc/cp/parser.c:13577 0x7636dd cp_parser_translation_unit ../../gcc-11-20201011/gcc/cp/parser.c:4793 0x7636dd c_parse_file() ../../gcc-11-20201011/gcc/cp/parser.c:44172 0x82f13d c_common_parse_file() ../../gcc-11-20201011/gcc/c-family/c-opts.c:1188 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.