]> gcc.gnu.org Git - gcc.git/commitdiff
PR tree-optimization/92349 - ICE in -Warray-bounds of a VLA member
authorMartin Sebor <msebor@redhat.com>
Mon, 4 Nov 2019 18:15:43 +0000 (18:15 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 4 Nov 2019 18:15:43 +0000 (11:15 -0700)
gcc/testsuite/ChangeLog:

PR tree-optimization/92349
* gcc.dg/Warray-bounds-50.c: New test.

gcc/ChangeLog:

PR tree-optimization/92349
* tree-vrp.c (vrp_prop::check_array_ref): Avoid assuming struct
memebers have constant sizes.

From-SVN: r277786

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-50.c [new file with mode: 0644]
gcc/tree-vrp.c

index b94a323672875cc1ef4c30abe0dad6c17def6ff7..b8b120d96ffc63fd3dff527311c80d07442a3dce 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-04  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/92349
+       * tree-vrp.c (vrp_prop::check_array_ref): Avoid assuming struct
+       memebers have constant sizes.
+
 2019-11-04  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        * tree-vect-loop.c (vect_analyze_loop): Remove orig_loop_vinfo
index 2059b594e16b6c25cf66b26d7b0cbb1350e6c105..5fa63c3cb8bc2ff9169bee021cbf010ab78eb06b 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-04  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/92349
+       * gcc.dg/Warray-bounds-50.c: New test.
+
 2019-11-04  Joel Hutton  <Joel.Hutton@arm.com>
 
        * gcc.dg/vect/bb-slp-40.c: New test.
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-50.c b/gcc/testsuite/gcc.dg/Warray-bounds-50.c
new file mode 100644 (file)
index 0000000..d6edfac
--- /dev/null
@@ -0,0 +1,114 @@
+/* PR middle-end/92349 - ICE in -Warray-bounds on a VLA member
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+void sink (void*, ...);
+
+void mem_vla_cst_store_idx (void)
+{
+  int n = 3;
+
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  s.a[0] = 0;
+  s.b = 0;
+
+  *++p = 1;
+  *++p = 2;
+
+  sink (&s, p);
+}
+
+void mem_vla_range_store_idx (int n)
+{
+  if (n < 3 || 4 < n)
+    n = 3;
+
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  s.a[0] = 0;
+  s.b = 0;
+
+  *++p = 1;
+  *++p = 2;
+
+  sink (&s, p);
+}
+
+void mem_vla_var_store_idx (size_t n)
+{
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  s.a[0] = 0;
+  s.b = 0;
+
+  *++p = 1;
+  *++p = 2;
+
+  sink (&s, p);
+}
+
+
+void mem_vla_cst_store_ptr (void)
+{
+  int n = 3;
+
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+
+  sink (&s, p);
+}
+
+void mem_vla_range_store_ptr (int n)
+{
+  if (n < 3 || 4 < n)
+    n = 3;
+
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+
+  sink (&s, p);
+}
+
+void mem_vla_var_store_ptr (size_t n)
+{
+  struct {
+    char a[n], b;
+  } s;
+
+  char *p = s.a;
+
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+  *p++ = __LINE__;
+
+  sink (&s, p);
+}
index 31258615247c8ed7a74745bab09095955ecd635a..da6b6151b4a987a75f6e07b31a17172634a0dca9 100644 (file)
@@ -4164,7 +4164,8 @@ vrp_prop::check_array_ref (location_t location, tree ref,
              /* Try to determine the size of the trailing array from
                 its initializer (if it has one).  */
              if (tree refsize = component_ref_size (arg, &interior_zero_len))
-               maxbound = refsize;
+               if (TREE_CODE (refsize) == INTEGER_CST)
+                 maxbound = refsize;
            }
 
          if (maxbound == ptrdiff_max
This page took 0.147421 seconds and 5 git commands to generate.