This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR86988


Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2018-08-22  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/86988
	* tree-vrp.c (vrp_prop::check_mem_ref): Bail out on VLAs.

	* g++.dg/pr86988.C: New testcase.

diff --git a/gcc/testsuite/g++.dg/pr86988.C b/gcc/testsuite/g++.dg/pr86988.C
new file mode 100644
index 00000000000..62fb0f3220d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr86988.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O2 -Warray-bounds" }
+
+struct R { int r; };
+void baz (char *, char *, char *, char *);
+
+void
+foo ()
+{
+  const R a = { 12 };
+  char b[1][a.r] = { { "12345678901" } };
+  char c[a.r] = { "12345678901" };
+  char d[1][a.r] = { { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '\0' } };
+  char e[a.r] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '\0' };
+  baz (b[0], c, d[0], e);
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 24e089b019b..ead19f15996 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4581,6 +4581,7 @@ vrp_prop::check_mem_ref (location_t location, tree ref,
   tree reftype = TREE_TYPE (arg);
   if (POINTER_TYPE_P (reftype)
       || !COMPLETE_TYPE_P (reftype)
+      || TREE_CODE (TYPE_SIZE_UNIT (reftype)) != INTEGER_CST
       || RECORD_OR_UNION_TYPE_P (reftype))
     return;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]