PR middle-end/89934 - ICE on a call with fewer arguments to strncpy declared without...
authorMartin Sebor <msebor@redhat.com>
Thu, 4 Apr 2019 21:59:49 +0000 (21:59 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Thu, 4 Apr 2019 21:59:49 +0000 (15:59 -0600)
gcc/ChangeLog:

PR middle-end/89934
* gimple-ssa-warn-restrict.c (builtin_access::builtin_access): Bail
out if the number of arguments is less than expected.

gcc/testsuite/ChangeLog:

PR middle-end/89934
* gcc.dg/Wrestrict-19.c: New test.
* gcc.dg/Wrestrict-5.c: Add comment.  Remove unused code.

From-SVN: r270152

gcc/ChangeLog
gcc/gimple-ssa-warn-restrict.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wrestrict-19.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wrestrict-5.c

index f57c2f9c193fd361f7b3c7e8611c9de3f79bb70b..bc97e1992995502a6ba8019c257e0be9ab5a2b69 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-04  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/89934
+       * gimple-ssa-warn-restrict.c (builtin_access::builtin_access): Bail
+       out if the number of arguments is less than expected.
+
 2019-04-04  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/89399
index 4ebe99fe7a225f66bea2baf865c893603364c973..0c571efb666590e6f3352ad6d7a8dc826414f733 100644 (file)
@@ -730,6 +730,10 @@ builtin_access::builtin_access (gimple *call, builtin_memref &dst,
   offset_int bounds[2] = { maxobjsize, maxobjsize };
   if (dstref->strbounded_p)
     {
+      unsigned nargs = gimple_call_num_args (call);
+      if (nargs <= sizeargno)
+       return;
+
       tree size = gimple_call_arg (call, sizeargno);
       tree range[2];
       if (get_size_range (size, range, true))
index 389ca037429e77e941139bfef12cba43dceca7b3..cc60f539a239eed9a0e12b3d17e4065e100762be 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-04  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/89934
+       * gcc.dg/Wrestrict-19.c: New test.
+       * gcc.dg/Wrestrict-5.c: Add comment.  Remove unused code.
+
 2019-04-04  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/89399
diff --git a/gcc/testsuite/gcc.dg/Wrestrict-19.c b/gcc/testsuite/gcc.dg/Wrestrict-19.c
new file mode 100644 (file)
index 0000000..d475053
--- /dev/null
@@ -0,0 +1,32 @@
+/* PR middle-end/89934 - ICE on a call with fewer arguments to strncpy
+   declared without prototype
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+char *strncpy ();
+
+char* f0 (char *s)
+{
+  return strncpy ();
+}
+
+char* f1 (char *s)
+{
+  return strncpy (s);
+}
+
+char* f2 (char *s)
+{
+  return strncpy (s, s + 1);   /* ICE here.  */
+}
+
+void f3 (char *s, size_t n, const char *t)
+{
+  strncpy (s, n, t);
+  strncpy (n, s, t);
+}
+
+/* { dg-prune-output "\\\[-Wbuiltin-declaration-mismatch]" }
+   { dg-prune-output "\\\[-Wint-conversion]" } */
index 90babfd8205d3f11b9af6942765e5edaa14dc678..513b4267fa4a94c8f61ad5183666cb7f0f15168e 100644 (file)
@@ -1,20 +1,11 @@
-/* Test to verify that valid calls to common restrict-qualified built-in
+/* PR tree-optimization/83655 - ICE on an invalid call to memcpy declared
+   with no prototype
+   Test to verify that valid calls to common restrict-qualified built-in
    functions declared with no prototype are checked for overlap, and that
    invalid calls are ignored.
   { dg-do compile }
-  { dg-prune-output "conflicting types for built-in" }
   { dg-options "-O2 -Wrestrict" }  */
 
-typedef __SIZE_TYPE__ size_t;
-
-#if __cplusplus
-extern "C" {
-
-#define NO_PROTO ...
-#else
-#define NO_PROTO /* empty */
-#endif
-
 void* memcpy ();
 char* strncpy ();