diff gcc/testsuite/gcc.dg/Wstringop-overflow-8.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-8.c	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,62 @@
+/* PR tree-optimization/79220 - missing -Wstringop-overflow= on a memcpy
+   overflow with a small power-of-2 size
+   { dg-do compile }
+   { dg-options "-O2 -Wno-array-bounds -Wstringop-overflow" } */
+
+extern void* memcpy (void*, const void*, __SIZE_TYPE__);
+extern void* memmove (void*, const void*, __SIZE_TYPE__);
+extern void* memset (void*, int, __SIZE_TYPE__);
+
+char d[1];
+
+void test_memcpy_lit_2 (void)
+{
+  memcpy (d, "01", 2);          /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memcpy_lit_4 (void)
+{
+  memcpy (d, "0123", 4);        /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memmove_lit_8 (void)
+{
+  memmove (d, "01234567", 8);   /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+
+void test_memcpy_ptr_2 (const void *s)
+{
+  memcpy (d, s, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memcpy_ptr_4 (const void *s)
+{
+  memcpy (d, s, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memcpy_ptr_8 (const void *s)
+{
+  memcpy (d, s, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+
+void test_memmove_ptr (const void *s)
+{
+  memmove (d, s, 8);            /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memset_2 (void)
+{
+  memset (d, 0, 2);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memset_4 (void)
+{
+  memset (d, 0, 4);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}
+
+void test_memset_8 (void)
+{
+  memset (d, 0, 8);             /* { dg-warning "\\\[-Wstringop-overflow" } */
+}