c: Fix ICE on __builtin_has_attribute (var, pure). [PR128120]
Fixes an Internal Compiler Error when using __builtin_has_attribute with variables and the 'pure' attribute.
This commit resolves an Internal Compiler Error (ICE) occurring in the C front-end when __builtin_has_attribute is used with a variable and the pure attribute. The issue arises because DECL_PURE_P incorrectly accepts FUNCTION_DECL when a VAR_DECL is passed. The fix ensures that the function correctly checks for FUNCTION_DECL when TREE_CODE is evaluated.
In Details
The __builtin_has_attribute intrinsic, when checking for the pure attribute on a variable, triggers an ICE. The c-attribs.cc file's has_attribute function incorrectly passes a VAR_DECL to DECL_PURE_P, which expects a FUNCTION_DECL. This commit corrects the check to ensure TREE_CODE (expr) == FUNCTION_DECL is evaluated for pure attribute checks, preventing the ICE.
- Internal Compiler Error (ICE)
- An unexpected condition encountered by the compiler that prevents it from continuing compilation. It typically indicates a bug in the compiler itself.
- __builtin_has_attribute
- A GCC-specific built-in function that checks if a type or declaration has a specified attribute.
- TREE_CODE
- A GCC internal representation that identifies the type of a node in the compiler's abstract syntax tree or intermediate representation.
- VAR_DECL
- A GCC internal representation node for a variable declaration.
- FUNCTION_DECL
- A GCC internal representation node for a function declaration.
- DECL_PURE_P
- A GCC internal macro that checks if a declaration is pure (i.e., does not modify global state or have side effects).