DECL_PURE_P only accepts FUNCTION_DECL, and testcase
ICE due to DECL_P (expr) passing by VAR_DECL when
it should be TREE_CODE (expr) == FUNCTION_DECL.
Bootstrapped and regtested on x86_64-pc-linux-gnu.
PR c/128120
gcc/c-family/ChangeLog:
* c-attribs.cc (has_attribute): Fix ICE on
__builtin_has_attribute (var, pure).
gcc/testsuite/ChangeLog:
* gcc.dg/pr128120.c: New test.
Signed-off-by: Kael Andrew Franco <[email protected]>
---
gcc/c-family/c-attribs.cc | 2 +-
gcc/testsuite/gcc.dg/pr128120.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr128120.c
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b41b9d1d72a..aab9f2cb9e3 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -6457,7 +6457,7 @@ has_attribute (location_t atloc, tree t, tree attr, tree
(*convert)(tree))
}
else if (!strcmp ("pure", namestr))
{
- if (expr && DECL_P (expr))
+ if (expr && TREE_CODE (expr) == FUNCTION_DECL)
found_match = DECL_PURE_P (expr);
}
else if (!strcmp ("deprecated", namestr))
diff --git a/gcc/testsuite/gcc.dg/pr128120.c b/gcc/testsuite/gcc.dg/pr128120.c
new file mode 100644
index 00000000000..11f1ff67354
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr128120.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+
+int v;
+int b = __builtin_has_attribute (v, pure);
--
2.56.0