re PR tree-optimization/89566 (ICE on compilable C++ code: in gimple_call_arg, at...
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Mar 2019 08:43:16 +0000 (09:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Mar 2019 08:43:16 +0000 (09:43 +0100)
PR tree-optimization/89566
* gimple-ssa-sprintf.c (sprintf_dom_walker::handle_gimple_call):
Set info.fncode to BUILT_IN_NONE if gimple_call_builtin_p failed.
Punt if get_user_idx_format succeeds, but idx_format argument is
not provided or doesn't have pointer type, or if idx_args is above
number of provided arguments.

* c-c++-common/pr89566.c: New test.

From-SVN: r269384

gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr89566.c [new file with mode: 0644]

index 38858fa..22ce364 100644 (file)
@@ -1,3 +1,12 @@
+2019-03-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/89566
+       * gimple-ssa-sprintf.c (sprintf_dom_walker::handle_gimple_call):
+       Set info.fncode to BUILT_IN_NONE if gimple_call_builtin_p failed.
+       Punt if get_user_idx_format succeeds, but idx_format argument is
+       not provided or doesn't have pointer type, or if idx_args is above
+       number of provided arguments.
+
 2019-03-04  Wilco Dijkstra  <wdijkstr@arm.com>
 
        PR tree-optimization/89437
index 4fe206a..ced1c4c 100644 (file)
@@ -3858,16 +3858,21 @@ sprintf_dom_walker::handle_gimple_call (gimple_stmt_iterator *gsi)
   if (!info.func)
     return false;
 
-  info.fncode = DECL_FUNCTION_CODE (info.func);
-
   /* Format string argument number (valid for all functions).  */
   unsigned idx_format = UINT_MAX;
-  if (!gimple_call_builtin_p (info.callstmt, BUILT_IN_NORMAL))
+  if (gimple_call_builtin_p (info.callstmt, BUILT_IN_NORMAL))
+    info.fncode = DECL_FUNCTION_CODE (info.func);
+  else
     {
       unsigned idx_args;
       idx_format = get_user_idx_format (info.func, &idx_args);
-      if (idx_format == UINT_MAX)
+      if (idx_format == UINT_MAX
+         || idx_format >= gimple_call_num_args (info.callstmt)
+         || idx_args > gimple_call_num_args (info.callstmt)
+         || !POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (info.callstmt,
+                                                         idx_format))))
        return false;
+      info.fncode = BUILT_IN_NONE;
       info.argidx = idx_args;
     }
 
index c06d63a..a5e25c3 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/89566
+       * c-c++-common/pr89566.c: New test.
+
 2019-03-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84605
diff --git a/gcc/testsuite/c-c++-common/pr89566.c b/gcc/testsuite/c-c++-common/pr89566.c
new file mode 100644 (file)
index 0000000..d967656
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR tree-optimization/89566 */
+/* { dg-do compile } */
+
+typedef struct FILE { int i; } FILE;
+#ifdef __cplusplus
+extern "C"
+#endif
+int fprintf (FILE *, const char *, ...);
+
+int
+main ()
+{
+  ((void (*)()) fprintf) ();   // { dg-warning "function called through a non-compatible type" "" { target c } }
+  return 0;
+}