https://gcc.gnu.org/g:ec0d4feb49927b575a7485fe9c90b10100aaff6b
commit r15-11138-gec0d4feb49927b575a7485fe9c90b10100aaff6b Author: Martin Uecker <[email protected]> Date: Thu Feb 19 18:20:01 2026 +0100 c: Fix ICE related to tags and hardbool attribute [PR123856] 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. The patch was adapted for the backport. 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. (cherry picked from commit 4edd2957ad32c4dabb05dbd175ff2067d0bfe072) Diff: --- gcc/c-family/c-attribs.cc | 6 +++++- gcc/testsuite/gcc.dg/pr123856.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 5a0e3d328ba7..957b201be42a 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -1191,7 +1191,11 @@ handle_hardbool_attribute (tree *node, tree name, tree args, gcc_checking_assert (!TYPE_CACHED_VALUES_P (*node)); TYPE_VALUES (*node) = values; - TYPE_NAME (*node) = 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 index 000000000000..2967243220af --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr123856.c @@ -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" } */ +
