================ @@ -908,6 +908,73 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { incrementProfileCounter(&S); } +bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, + bool IsTrivialCXXLoop) { + if (CGM.getCodeGenOpts().getFiniteLoops() == + CodeGenOptions::FiniteLoopsKind::Always) + return true; + if (CGM.getCodeGenOpts().getFiniteLoops() == + CodeGenOptions::FiniteLoopsKind::Never) + return false; + + // Now apply rules for plain C (see 6.8.5.6 in C11). + // Loops with constant conditions do not have to make progress in any C + // version. + // As an extension, we consisider loops whose constant expression + // can be constant-folded. + Expr::EvalResult Result; + bool CondIsConstInt = + !ControllingExpression || + (ControllingExpression->EvaluateAsInt(Result, getContext()) && + Result.Val.isInt()); + bool IsTrue = CondIsConstInt && + (!ControllingExpression || Result.Val.getInt().getBoolValue()); + + if (getLangOpts().C99 && CondIsConstInt) + return false; + + // Loops with non-constant conditions must make progress in C11 and later. + if (getLangOpts().C11) + return true; + + // [C++26][intro.progress] (DR) + // The implementation may assume that any thread will eventually do one of the + // following: + // [...] + // - continue execution of a trivial infinite loop ([stmt.iter.general]). + if (getLangOpts().CPlusPlus11) { + if (IsTrivialCXXLoop && IsTrue) { + CurFn->removeFnAttr(llvm::Attribute::MustProgress); ---------------- cor3ntin wrote:
We do mark the loops `mustprogress` in C++ too. I'm not sure how either of these attributes work, so I've try to preserve existing behavior. IE, a function will be marked `mustprogress` in C++11+ _unless_ at least one loop is not `mustprogress`. If you telling me that the `mustprogress` attribute has no effect in the absence of loops in the body, or when all the loops are mustprogress, maybe we should never use it in C++11+ modes? https://github.com/llvm/llvm-project/pull/90066 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits