Hi,
in this regression we issue a diagnostic about an incomplete type (only
a warning by default) and then we crash when we try to query
has_attribute on a member of the type because in such cases the member
remains an IDENTIFIER_NODE which of course doesn't have a TREE_TYPE
neither a DECL_ATTRIBUTES... Simply recognizing IDENTIFIER_NODEs and
returning false works fine, not sure if we want to do something more
sophisticated. Tested x86_64-linux.
Thanks, Paolo.
////////////////////////
Fix "PR c++/90915 ICE in has_attribute, at c-family/c-attribs.c:4221"
A rather simple ICE where we didn't properly recover upon diagnosing
an incomplete type.
Tested x86_64-linux.
/c-family
PR c++/90915
* c-attribs.c (has_attribute): Handle correctly IDENTIFIER_NODEs.
/testsuite
PR c++/90915
* g++.dg/ext/builtin-has-attribute-1.C: New.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index dc9579c5c60..97590a19c0f 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -4759,6 +4759,10 @@ has_attribute (location_t atloc, tree t, tree attr, tree
(*convert)(tree))
expr = NULL_TREE;
done = true;
}
+ else if (TREE_CODE (expr) == IDENTIFIER_NODE)
+ /* Can happen during error-recovery when querying a member of
+ an incomplete type (c++/90915). */
+ return false;
else if (DECL_P (expr))
{
/* Set TYPE to the DECL's type to process it on the next
diff --git a/gcc/testsuite/g++.dg/ext/builtin-has-attribute-1.C
b/gcc/testsuite/g++.dg/ext/builtin-has-attribute-1.C
new file mode 100644
index 00000000000..3d81a078159
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/builtin-has-attribute-1.C
@@ -0,0 +1,7 @@
+// { dg-do compile { target c++11 } }
+
+struct S;
+template<int> struct T
+{
+ static_assert (!__builtin_has_attribute (((S *) 0) -> a, packed), ""); // {
dg-error "invalid use of incomplete type" }
+};