https://gcc.gnu.org/g:c9889f295676378d4c341674d94f9c8056ba3202

commit r17-5600-gc9889f295676378d4c341674d94f9c8056ba3202
Author: Kael Andrew Alonzo Franco <[email protected]>
Date:   Mon Oct 26 18:45:20 2026 -0400

    c: Fix ICE on __builtin_has_attribute (var, pure). [PR128120]
    
    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]>

Diff:
---
 gcc/c-family/c-attribs.cc       | 2 +-
 gcc/testsuite/gcc.dg/pr128120.c | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b41b9d1d72a1..aab9f2cb9e3b 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 000000000000..11f1ff673542
--- /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);

Reply via email to