From: Andrew Pinski Date: Tue, 13 May 2025 16:56:13 +0000 (-0700) Subject: gimple: allow fold_stmt without setting cfun in case of GIMPLE_COND folding X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1759734f1584a3db75c5a931bc1b144b7695b80a;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index b8c1588365e..009c5737ef9 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))