]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix ICE related to tags and hardbool attribute [PR123856]
authorMartin Uecker <uecker@tugraz.at>
Thu, 19 Feb 2026 17:20:01 +0000 (18:20 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Sat, 7 Mar 2026 09:44:39 +0000 (10:44 +0100)
The hardbool attribute creates special enumeration types,
but the tag is not set correctly, which causes broken diagnostics
and an ICE with the new helper function to get the tag.

PR c/123856

gcc/c-family/ChangeLog:
* c-attribs.cc (handle_hardbool_attribute): Fix TYPE_NAME.

gcc/testsuite/ChangeLog:
* gcc.dg/pr123856.c: New test.

gcc/c-family/c-attribs.cc
gcc/testsuite/gcc.dg/pr123856.c [new file with mode: 0644]

index 10d9a51418ef69c1f139e4cff42cba9c5a9b18f2..d437c55285e374b3a99f42057afa64db16780800 100644 (file)
@@ -1229,13 +1229,14 @@ handle_hardbool_attribute (tree *node, tree name, tree args,
 
   gcc_checking_assert (!TYPE_CACHED_VALUES_P (*node));
   TYPE_VALUES (*node) = values;
-  TYPE_NAME (*node) = unqual;
 
   if (TYPE_QUALS (orig) != TYPE_QUALS (*node))
-    {
-      *node = build_qualified_type (*node, TYPE_QUALS (orig));
-      TYPE_NAME (*node) = orig;
-    }
+    *node = build_qualified_type (*node, TYPE_QUALS (orig));
+
+  if (TREE_CODE (orig) == TYPE_DECL)
+    TYPE_NAME (*node) = TYPE_NAME (orig);
+  else
+    TYPE_NAME (*node) = NULL_TREE;
 
   return NULL_TREE;
 }
diff --git a/gcc/testsuite/gcc.dg/pr123856.c b/gcc/testsuite/gcc.dg/pr123856.c
new file mode 100644 (file)
index 0000000..2967243
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-Wenum-conversion" } */
+
+typedef __attribute__((__hardbool__)) int A, B;
+
+B b;
+void bar(A) { }
+void foo() { bar(b); }         /* { dg-warning "implicit conversion" } */
+
+void bar2(__attribute__((__hardbool__)) int)  { }
+void foo2() { bar2(b); }       /* { dg-warning "implicit conversion" } */
+
+__attribute__((__hardbool__)) int c;
+void bar3(__attribute__((__hardbool__)) int)  { }
+void foo3() { bar2(c); }       /* { dg-warning "implicit conversion" } */
+
+void bar4(int)  { }
+void foo4() { bar2(c); }       /* { dg-warning "implicit conversion" } */
+