https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88585

--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
OK, I think this is frontend issue because at least in my understanding there
should be only one canonical type for the structure, while here we have two.

One canonical type is result of:
#0  0x00007ffff765f728 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00000000015925d3 in copy_node (node=0x7ffff7211690) at
../../gcc/tree.c:1183
#2  0x00000000015a8059 in build_distinct_type_copy (type=0x7ffff7211690) at
../../gcc/tree.c:6514
#3  0x00000000015a81d2 in build_variant_type_copy (type=0x7ffff7211690) at
../../gcc/tree.c:6548
#4  0x00000000015a7bc0 in build_qualified_type (type=0x7ffff7211690,
type_quals=8) at ../../gcc/tree.c:6449
#5  0x00000000009107f4 in c_build_qualified_type (type=0x7ffff7211690,
type_quals=8, orig_qual_type=0x0, orig_qual_indirect=0) at
../../gcc/c/c-typeck.c:14941
#6  0x00000000008b2c70 in grokdeclarator (declarator=0x3188250,
declspecs=0x31880c0, decl_context=PARM, initialized=false, width=0x0,
decl_attrs=0x7fffffffe348, expr=0x7fffffffe368, 
    expr_const_operands=0x7fffffffe17f, deprecated_state=DEPRECATED_NORMAL) at
../../gcc/c/c-decl.c:6663
#7  0x00000000008af3fd in push_parm_decl (parm=0x3188280, expr=0x7fffffffe368)
at ../../gcc/c/c-decl.c:5439
#8  0x0000000000922343 in c_parser_parms_list_declarator
(parser=0x7ffff70f4b40, attrs=0x0, expr=0x0) at ../../gcc/c/c-parser.c:4011
#9  0x00000000009221e6 in c_parser_parms_declarator (parser=0x7ffff70f4b40,
id_list_ok=true, attrs=0x0) at ../../gcc/c/c-parser.c:3942
#10 0x0000000000921f55 in c_parser_direct_declarator_inner
(parser=0x7ffff70f4b40, id_present=true, inner=0x3188090) at
../../gcc/c/c-parser.c:3870
#11 0x0000000000921962 in c_parser_direct_declarator (parser=0x7ffff70f4b40,
type_seen_p=true, kind=C_DTR_NORMAL, seen_id=0x7fffffffe67f) at
../../gcc/c/c-parser.c:3711
#12 0x000000000092187a in c_parser_declarator (parser=0x7ffff70f4b40,
type_seen_p=true, kind=C_DTR_NORMAL, seen_id=0x7fffffffe67f) at
../../gcc/c/c-parser.c:3655
#13 0x000000000091dc43 in c_parser_declaration_or_fndef (parser=0x7ffff70f4b40,
fndef_ok=true, static_assert_ok=true, empty_ok=true, nested=false,
start_attr_ok=true, 
    objc_foreach_object_declaration=0x0, omp_declare_simd_clauses=...,
oacc_routine_data=0x0, fallthru_attr_p=0x0) at ../../gcc/c/c-parser.c:2001
#14 0x000000000091d2bc in c_parser_external_declaration (parser=0x7ffff70f4b40)
at ../../gcc/c/c-parser.c:1654
#15 0x000000000091ce15 in c_parser_translation_unit (parser=0x7ffff70f4b40) at
../../gcc/c/c-parser.c:1534
#16 0x0000000000954eae in c_parse_file () at ../../gcc/c/c-parser.c:19842
#17 0x00000000009d4288 in c_common_parse_file () at
../../gcc/c-family/c-opts.c:1155
#18 0x0000000001197690 in compile_file () at ../../gcc/toplev.c:456
#19 0x000000000119a1c2 in do_compile () at ../../gcc/toplev.c:2176
#20 0x000000000119a4ae in toplev::main (this=0x7fffffffe9fe, argc=5,
argv=0x7fffffffeaf8) at ../../gcc/toplev.c:2311
#21 0x00000000020690ad in main (argc=5, argv=0x7fffffffeaf8) at
../../gcc/main.c:39

While the second is
#0  0x00007ffff765f79c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00000000015925d3 in copy_node (node=0x7ffff7211690) at
../../gcc/tree.c:1183
#2  0x00000000015a8059 in build_distinct_type_copy (type=0x7ffff7211690) at
../../gcc/tree.c:6514
#3  0x00000000015a81d2 in build_variant_type_copy (type=0x7ffff7211690) at
../../gcc/tree.c:6548
#4  0x00000000015a7bc0 in build_qualified_type (type=0x7ffff7211690,
type_quals=8) at ../../gcc/tree.c:6449
#5  0x00000000009107f4 in c_build_qualified_type (type=0x7ffff7211690,
type_quals=8, orig_qual_type=0x0, orig_qual_indirect=0) at
../../gcc/c/c-typeck.c:14941
#6  0x00000000008b2c70 in grokdeclarator (declarator=0x3188250,
declspecs=0x31880c0, decl_context=PARM, initialized=false, width=0x0,
decl_attrs=0x7fffffffe348, expr=0x7fffffffe368, 
    expr_const_operands=0x7fffffffe17f, deprecated_state=DEPRECATED_NORMAL) at
../../gcc/c/c-decl.c:6663
#7  0x00000000008af3fd in push_parm_decl (parm=0x3188280, expr=0x7fffffffe368)
at ../../gcc/c/c-decl.c:5439
#8  0x0000000000922343 in c_parser_parms_list_declarator
(parser=0x7ffff70f4b40, attrs=0x0, expr=0x0) at ../../gcc/c/c-parser.c:4011
#9  0x00000000009221e6 in c_parser_parms_declarator (parser=0x7ffff70f4b40,
id_list_ok=true, attrs=0x0) at ../../gcc/c/c-parser.c:3942
#10 0x0000000000921f55 in c_parser_direct_declarator_inner
(parser=0x7ffff70f4b40, id_present=true, inner=0x3188090) at
../../gcc/c/c-parser.c:3870
#11 0x0000000000921962 in c_parser_direct_declarator (parser=0x7ffff70f4b40,
type_seen_p=true, kind=C_DTR_NORMAL, seen_id=0x7fffffffe67f) at
../../gcc/c/c-parser.c:3711
#12 0x000000000092187a in c_parser_declarator (parser=0x7ffff70f4b40,
type_seen_p=true, kind=C_DTR_NORMAL, seen_id=0x7fffffffe67f) at
../../gcc/c/c-parser.c:3655
#13 0x000000000091dc43 in c_parser_declaration_or_fndef (parser=0x7ffff70f4b40,
fndef_ok=true, static_assert_ok=true, empty_ok=true, nested=false,
start_attr_ok=true, 
    objc_foreach_object_declaration=0x0, omp_declare_simd_clauses=...,
oacc_routine_data=0x0, fallthru_attr_p=0x0) at ../../gcc/c/c-parser.c:2001
#14 0x000000000091d2bc in c_parser_external_declaration (parser=0x7ffff70f4b40)
at ../../gcc/c/c-parser.c:1654
#15 0x000000000091ce15 in c_parser_translation_unit (parser=0x7ffff70f4b40) at
../../gcc/c/c-parser.c:1534
#16 0x0000000000954eae in c_parse_file () at ../../gcc/c/c-parser.c:19842
#17 0x00000000009d4288 in c_common_parse_file () at
../../gcc/c-family/c-opts.c:1155
#18 0x0000000001197690 in compile_file () at ../../gcc/toplev.c:456
#19 0x000000000119a1c2 in do_compile () at ../../gcc/toplev.c:2176
#20 0x000000000119a4ae in toplev::main (this=0x7fffffffe9fe, argc=5,
argv=0x7fffffffeaf8) at ../../gcc/toplev.c:2311
#21 0x00000000020690ad in main (argc=5, argv=0x7fffffffeaf8) at
../../gcc/main.c:39

The reason is that build_variant_type_copy adjust alignment of atomic types and
thus
the variant lookup never succeeds.

I am testing
Index: tree.c
===================================================================
--- tree.c      (revision 268742)
+++ tree.c      (working copy)
@@ -6329,18 +6329,33 @@ check_lang_type (const_tree cand, const_
   return lang_hooks.types.type_hash_eq (cand, base);
 }

+static tree find_atomic_core_type (const_tree type);
+
 /* Returns true iff unqualified CAND and BASE are equivalent.  */

 bool
 check_base_type (const_tree cand, const_tree base)
 {
-  return (TYPE_NAME (cand) == TYPE_NAME (base)
-         /* Apparently this is needed for Objective-C.  */
-         && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
-         /* Check alignment.  */
-         && TYPE_ALIGN (cand) == TYPE_ALIGN (base)
-         && attribute_list_equal (TYPE_ATTRIBUTES (cand),
-                                  TYPE_ATTRIBUTES (base)));
+  if (TYPE_NAME (cand) != TYPE_NAME (base)
+      /* Apparently this is needed for Objective-C.  */
+      || TYPE_CONTEXT (cand) != TYPE_CONTEXT (base)
+      || !attribute_list_equal (TYPE_ATTRIBUTES (cand),
+                               TYPE_ATTRIBUTES (base)))
+    return false;
+  /* Check alignment.  */
+  if (TYPE_ALIGN (cand) == TYPE_ALIGN (base))
+    return true;
+  /* Atomic types increase minimal alignment.  We must to do so as well
+     or we get duplicated canonical types. See PR88686.  */
+  if ((TYPE_QUALS (cand) & TYPE_QUAL_ATOMIC))
+    {
+      /* See if this object can map to a basic atomic type.  */
+      tree atomic_type = find_atomic_core_type (cand);
+      if (TYPE_ALIGN (atomic_type) == TYPE_ALIGN (cand)
+         && TYPE_ALIGN (base) < TYPE_ALIGN (cand))
+       return true;
+    }
+  return false;
 }

 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS.  */
@@ -6373,7 +6388,7 @@ check_aligned_type (const_tree cand, con
    atomic types, and returns that core atomic type.  */

 static tree
-find_atomic_core_type (tree type)
+find_atomic_core_type (const_tree type)
 { 
   tree base_atomic_type;

Reply via email to