https://gcc.gnu.org/g:1759734f1584a3db75c5a931bc1b144b7695b80a

commit r16-626-g1759734f1584a3db75c5a931bc1b144b7695b80a
Author: Andrew Pinski <quic_apin...@quicinc.com>
Date:   Tue May 13 09:56:13 2025 -0700

    gimple: allow fold_stmt without setting cfun in case of GIMPLE_COND folding
    
    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_apin...@quicinc.com>

Diff:
---
 gcc/gimple-fold.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index b8c1588365e2..009c5737ef96 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -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))

Reply via email to