]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/testsuite/c-c++-common/Warray-bounds-4.c
Correct handling of variable offset minus constant in -Warray-bounds [PR100137]
[thirdparty/gcc.git] / gcc / testsuite / c-c++-common / Warray-bounds-4.c
index 22a23a126512f5e4f9236affee9210179fe7dfa9..1f73f11943fe633a344f1f91728ea81813dd1f23 100644 (file)
@@ -43,7 +43,17 @@ void test_memcpy_bounds_memarray_range (void)
 
   TM (ma.a5, ma.a5 + j, ma.a5, 1);
   TM (ma.a5, ma.a5 + j, ma.a5, 3);
-  TM (ma.a5, ma.a5 + j, ma.a5, 5);
+
+  /* The copy below is invalid for two reasons: 1) it overlaps and 2) it
+     writes past the end of ma.a5.  The warning is a little cryptic here
+     because the GIMPLE is:
+       _4 = &ma.a5 + prephitmp_14;
+       MEM <unsigned char[5]> [(char * {ref-all})_4]
+         = MEM <unsigned char[5]> [(char * {ref-all})&ma];
+     and could be improved.  Just verify that one is issued but not its
+     full text.  */
+  TM (ma.a5, ma.a5 + j, ma.a5, 5);        /* { dg-warning "\\\[-Warray-bounds" } */
+
   TM (ma.a5, ma.a5 + j, ma.a5, 7);        /* { dg-warning "offset \\\[5, 7] from the object at .ma. is out of the bounds of referenced subobject .\(MA::\)?a5. with type .char ?\\\[5]. at offset 0" } */
   TM (ma.a5, ma.a5 + j, ma.a5, 9);        /* { dg-warning "offset \\\[5, 9] from the object at .ma. is out of the bounds of referenced subobject .\(MA::\)?a5. with type .char ?\\\[5]. at offset 0" } */
 }