aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-10-13 11:42:27 +0200
committerRichard Biener <rguenth@gcc.gnu.org>2024-10-13 11:51:36 +0200
commit1506027347776a2f6ec5b92d56ef192e85944e2e (patch)
treec15092adf9cbd460511582b70e30bf0281c45ffe
parent3269a722b7a03613e9c4e2862bc5088c4a17cc11 (diff)
downloadgcc-1506027347776a2f6ec5b92d56ef192e85944e2e.zip
gcc-1506027347776a2f6ec5b92d56ef192e85944e2e.tar.gz
gcc-1506027347776a2f6ec5b92d56ef192e85944e2e.tar.bz2
tree-optimization/116481 - avoid building function_type[]
The following avoids building an array type with function or method element type during diagnosing an array bound violation as this will result in an error, rejecting a program with a not too useful error message. Instead build such array type manually. PR tree-optimization/116481 * pointer-query.cc (build_printable_array_type): Build an array types with function or method element type manually to avoid bogus diagnostic. * gcc.dg/pr116481.c: New testcase.
-rw-r--r--gcc/pointer-query.cc11
-rw-r--r--gcc/testsuite/gcc.dg/pr116481.c13
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/pointer-query.cc b/gcc/pointer-query.cc
index c8ab057..a85c041 100644
--- a/gcc/pointer-query.cc
+++ b/gcc/pointer-query.cc
@@ -2587,6 +2587,17 @@ array_elt_at_offset (tree artype, HOST_WIDE_INT off,
tree
build_printable_array_type (tree eltype, unsigned HOST_WIDE_INT nelts)
{
+ /* Cannot build an array type of functions or methods without
+ an error diagnostic. */
+ if (FUNC_OR_METHOD_TYPE_P (eltype))
+ {
+ tree arrtype = make_node (ARRAY_TYPE);
+ TREE_TYPE (arrtype) = eltype;
+ TYPE_SIZE (arrtype) = bitsize_zero_node;
+ TYPE_SIZE_UNIT (arrtype) = size_zero_node;
+ return arrtype;
+ }
+
if (TYPE_SIZE_UNIT (eltype)
&& TREE_CODE (TYPE_SIZE_UNIT (eltype)) == INTEGER_CST
&& !integer_zerop (TYPE_SIZE_UNIT (eltype))
diff --git a/gcc/testsuite/gcc.dg/pr116481.c b/gcc/testsuite/gcc.dg/pr116481.c
new file mode 100644
index 0000000..3ee6d74
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116481.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Warray-bounds" } */
+
+extern void tramp ();
+
+int is_trampoline (void* function) /* { dg-bogus "arrays of functions are not meaningful" } */
+{
+ void* tramp_address = tramp;
+ if (!(((unsigned long)function & 3) == 2))
+ return 0;
+ return (((long *) ((char*)function - 2))[0]
+ == ((long *) ((char*)tramp_address-2))[0]); /* { dg-warning "outside array bounds" } */
+}