re PR middle-end/78901 (ICE: verify_gimple failed (error: statement marked for throw...
authorJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Jan 2017 07:20:04 +0000 (08:20 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Jan 2017 07:20:04 +0000 (08:20 +0100)
PR middle-end/78901
* gimple-ssa-sprintf.c (try_substitute_return_value): Don't change
possibly throwing calls.

* g++.dg/opt/pr78901.C: New test.

From-SVN: r244013

gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr78901.C [new file with mode: 0644]

index b38e59a546201b8ffdcd5317cd80cccc668e76da..7e1b2df89183b7ffd30c8a5a407b2d7184251aaf 100644 (file)
@@ -1,5 +1,9 @@
 2017-01-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/78901
+       * gimple-ssa-sprintf.c (try_substitute_return_value): Don't change
+       possibly throwing calls.
+
        * genmatch.c (dt_node::gen_kids_1): If generic_exprs include SSA_NAME
        and exprs_len || fns_len, emit the code for SSA_NAME next to the exprs
        and fns handling, rather than in a separate case SSA_NAME.
index 907a06479eef13280e9c7b5218b55946df51d997..ecd2267ae93fbe1ad92847eabf81584301d3b955 100644 (file)
@@ -2696,9 +2696,15 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
      the output overflows the destination object (but leave it enabled
      when the function is bounded because then the behavior is well-
      defined).  */
-  if (lhs && res.bounded && res.under4k
+  if (lhs
+      && res.bounded
+      && res.under4k
       && (info.bounded || res.number_chars <= info.objsize)
-      && res.number_chars - 1 <= target_int_max ())
+      && res.number_chars - 1 <= target_int_max ()
+      /* Not prepared to handle possibly throwing calls here; they shouldn't
+        appear in non-artificial testcases, except when the __*_chk routines
+        are badly declared.  */
+      && !stmt_ends_bb_p (info.callstmt))
     {
       tree cst = build_int_cst (integer_type_node, res.number_chars - 1);
 
index 560976989b8310c3389d17420ba155143582114a..bdaa2fe5d6874fcfa4f3d631644911973b069773 100644 (file)
@@ -1,20 +1,24 @@
+2017-01-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/78901
+       * g++.dg/opt/pr78901.C: New test.
+
 2017-01-03  Janne Blomqvist  <jb@gcc.gnu.org>
 
-        PR fortran/78534
-        PR fortran/66310
-        * gfortran.dg/dependency_49.f90: Change scan-tree-dump-times
-          due to gfc_trans_string_copy change to avoid
-          -Wstringop-overflow.
-        * gfortran.dg/repeat_4.f90: Use integers of kind C_SIZE_T.
-        * gfortran.dg/repeat_7.f90: New test for PR 66310.
-        * gfortran.dg/scan_2.f90: Handle potential cast in assignment.
-        * gfortran.dg/string_1.f90: Limit to ilp32 targets.
-        * gfortran.dg/string_1_lp64.f90: New test.
-        * gfortran.dg/string_3.f90: Limit to ilp32 targets.
-        * gfortran.dg/string_3_lp64.f90: New test.
-        * gfortran.dg/transfer_intrinsic_1.f90: Change
-          scan-tree-dump-times due to gfc_trans_string_copy change to
-          avoid -Wstringop-overflow.
+       PR fortran/78534
+       PR fortran/66310
+       * gfortran.dg/dependency_49.f90: Change scan-tree-dump-times
+       due to gfc_trans_string_copy change to avoid -Wstringop-overflow.
+       * gfortran.dg/repeat_4.f90: Use integers of kind C_SIZE_T.
+       * gfortran.dg/repeat_7.f90: New test for PR 66310.
+       * gfortran.dg/scan_2.f90: Handle potential cast in assignment.
+       * gfortran.dg/string_1.f90: Limit to ilp32 targets.
+       * gfortran.dg/string_1_lp64.f90: New test.
+       * gfortran.dg/string_3.f90: Limit to ilp32 targets.
+       * gfortran.dg/string_3_lp64.f90: New test.
+       * gfortran.dg/transfer_intrinsic_1.f90: Change
+       scan-tree-dump-times due to gfc_trans_string_copy change to
+       avoid -Wstringop-overflow.
 
 2017-01-02  Uros Bizjak  <ubizjak@gmail.com>
 
diff --git a/gcc/testsuite/g++.dg/opt/pr78901.C b/gcc/testsuite/g++.dg/opt/pr78901.C
new file mode 100644 (file)
index 0000000..932462f
--- /dev/null
@@ -0,0 +1,18 @@
+// PR middle-end/78901
+// { dg-do compile }
+// { dg-options "-O2 -Wno-stringop-overflow" }
+
+extern "C" int __snprintf_chk (char *, __SIZE_TYPE__, int, __SIZE_TYPE__, const char *, ...);
+
+int
+foo (char *c)
+{
+  try
+    {
+      return __snprintf_chk (c, 64, 0, 32, "%s", "abcdefghijklmnopq");
+    }
+  catch (...)
+    {
+      return -1;
+    }
+}