aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-06-27 16:39:29 -0400
committerMarek Polacek <polacek@redhat.com>2024-07-10 14:37:54 -0400
commit4c7009735f73f59c9a635d79c048c8981310e331 (patch)
tree39b2d1e10439f48566f4b221e1dd7ac68f392d5a /gcc
parent4865a92b35054fdfaa1318a4c1f56d95d44012a2 (diff)
downloadgcc-4c7009735f73f59c9a635d79c048c8981310e331.zip
gcc-4c7009735f73f59c9a635d79c048c8981310e331.tar.gz
gcc-4c7009735f73f59c9a635d79c048c8981310e331.tar.bz2
c: ICE on invalid with attribute optimize [PR115549]
I had this PR in my open tabs so why not go ahead and fix it. decl_attributes gets last_decl, the last already pushed declaration, to be used in common_handle_aligned_attribute. In C++, we look up the decl via find_last_decl, which returns NULL_TREE if it finds a decl that had not been declared. In C, we look up the decl via lookup_last_decl which returns error_mark_node rather than NULL_TREE in that case. The error_mark_node causes a crash in common_handle_aligned_attribute. We can fix this on the C FE side like in the patch below. PR c/115549 gcc/c/ChangeLog: * c-decl.cc (c_decl_attributes): If lookup_last_decl returns error_mark_node, use NULL_TREE as last_decl. gcc/testsuite/ChangeLog: * c-c++-common/attr-aligned-2.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-decl.cc5
-rw-r--r--gcc/testsuite/c-c++-common/attr-aligned-2.c8
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 0eac266..97f1d346 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5496,8 +5496,11 @@ c_decl_attributes (tree *node, tree attributes, int flags)
/* Look up the current declaration with all the attributes merged
so far so that attributes on the current declaration that's
about to be pushed that conflict with the former can be detected,
- diagnosed, and rejected as appropriate. */
+ diagnosed, and rejected as appropriate. To match the C++ FE, do
+ not pass an error_mark_node when we found an undeclared variable. */
tree last_decl = lookup_last_decl (*node);
+ if (last_decl == error_mark_node)
+ last_decl = NULL_TREE;
return decl_attributes (node, attributes, flags, last_decl);
}
diff --git a/gcc/testsuite/c-c++-common/attr-aligned-2.c b/gcc/testsuite/c-c++-common/attr-aligned-2.c
new file mode 100644
index 0000000..991b390
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-aligned-2.c
@@ -0,0 +1,8 @@
+/* PR c/115549 */
+/* { dg-do compile } */
+
+__attribute__((aligned,optimize(s))) /* { dg-error "not declared|undeclared" } */
+int s()
+{
+ return 0;
+}