aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-05-19 11:56:21 +0200
committerJakub Jelinek <jakub@redhat.com>2022-05-19 11:57:36 +0200
commit3b4daa0b3c3d8eb2ac3b40ad6898f314ed4d7919 (patch)
tree3d72c764de583ed88c3657cd434af19096a0146e /gcc
parentb8944f0438a183a0245ffe17aeaeaf3a1a00069c (diff)
downloadgcc-3b4daa0b3c3d8eb2ac3b40ad6898f314ed4d7919.zip
gcc-3b4daa0b3c3d8eb2ac3b40ad6898f314ed4d7919.tar.gz
gcc-3b4daa0b3c3d8eb2ac3b40ad6898f314ed4d7919.tar.bz2
pointer-query: Fix ICE with non-pointer param [PR105635]
The gimple_parm_array_size function comment talks about pointe parameters but doesn't actually verify it, it checks whether an attribute is present on the function and then just uses TREE_TYPE (TREE_TYPE (var)) which assumes a pointer type (or in theory could work for ARRAY_TYPE but c-family languages which only have that attribute will never have ARRAY_TYPE parameters; and for VECTOR_TYPE/COMPLEX_TYPE it would mean something quite different). So, this patch punts early if var doesn't have pointer/reference type. 2022-05-19 Jakub Jelinek <jakub@redhat.com> PR c/105635 * pointer-query.cc (gimple_parm_array_size): Return NULL if var doesn't have pointer or reference type. * gcc.dg/pr105635.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/pointer-query.cc2
-rw-r--r--gcc/testsuite/gcc.dg/pr105635.c11
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
index 646606e..67c2550 100644
--- a/gcc/pointer-query.cc
+++ b/gcc/pointer-query.cc
@@ -555,7 +555,7 @@ gimple_parm_array_size (tree ptr, wide_int rng[2],
from the current function declaratation (e.g., attribute access or
related). */
tree var = SSA_NAME_VAR (ptr);
- if (TREE_CODE (var) != PARM_DECL)
+ if (TREE_CODE (var) != PARM_DECL || !POINTER_TYPE_P (TREE_TYPE (var)))
return NULL_TREE;
const unsigned prec = TYPE_PRECISION (sizetype);
diff --git a/gcc/testsuite/gcc.dg/pr105635.c b/gcc/testsuite/gcc.dg/pr105635.c
new file mode 100644
index 0000000..aa02f59
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105635.c
@@ -0,0 +1,11 @@
+/* PR c/105635 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+void foo (int, int[*]); /* { dg-message "previous declaration of 'foo' with type" } */
+
+foo (int x, int y) /* { dg-warning "return type defaults to 'int'" } */
+{ /* { dg-warning "conflicting types for 'foo'" "" { target *-*-* } .-1 } */
+ /* { dg-message "declared here" "" { target *-*-* } .-2 } */
+ return (x >= 0) != (y < 0); /* { dg-warning "'return' with a value, in function returning void" } */
+}