]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimple: allow fold_stmt without setting cfun in case of GIMPLE_COND folding
authorAndrew Pinski <quic_apinski@quicinc.com>
Tue, 13 May 2025 16:56:13 +0000 (09:56 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 14 May 2025 14:52:32 +0000 (07:52 -0700)
This is the followup mentioned in https://gcc.gnu.org/pipermail/gcc-patches/2025-May/683444.html .
It adds the check for cfun before accessing function specific flags.
We handle the case where !cfun as conservative in that it the function might throw.

gcc/ChangeLog:

* gimple-fold.cc (replace_stmt_with_simplification): Check cfun before
accessing cfun.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/gimple-fold.cc

index b8c1588365e275e684b5122fc283568536299839..009c5737ef96aaf72c5b3e6b539fb683fc14fcae 100644 (file)
@@ -6239,8 +6239,9 @@ replace_stmt_with_simplification (gimple_stmt_iterator *gsi,
       auto code = tree_code (res_op->code);
       if (TREE_CODE_CLASS (code) == tcc_comparison
          /* GIMPLE_CONDs condition may not throw.  */
-         && (!flag_exceptions
-             || !cfun->can_throw_non_call_exceptions
+         && ((cfun
+              && (!flag_exceptions
+                  || !cfun->can_throw_non_call_exceptions))
              || !operation_could_trap_p (code,
                                          FLOAT_TYPE_P (TREE_TYPE (ops[0])),
                                          false, NULL_TREE)))
@@ -6282,8 +6283,9 @@ replace_stmt_with_simplification (gimple_stmt_iterator *gsi,
             `(ne (cmp @0 @1) integer_zerop)` which creates a new expression
             for the comparison.  */
          if (TREE_CODE_CLASS (code) == tcc_comparison
-             && flag_exceptions
-             && cfun->can_throw_non_call_exceptions
+             && (!cfun
+                 || (flag_exceptions
+                     && cfun->can_throw_non_call_exceptions))
              && operation_could_trap_p (code,
                                         FLOAT_TYPE_P (TREE_TYPE (ops[0])),
                                         false, NULL_TREE))