[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 30 14:56:43 PDT 2024
================
@@ -908,6 +908,74 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
incrementProfileCounter(&S);
}
+bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression,
+ bool IsTrivialCXXLoop) {
+ if (CGM.getCodeGenOpts().getFiniteLoops() ==
+ CodeGenOptions::FiniteLoopsKind::Never)
+ return false;
+
+ if (CGM.getCodeGenOpts().getFiniteLoops() ==
+ CodeGenOptions::FiniteLoopsKind::Always &&
+ !getLangOpts().CPlusPlus11)
----------------
efriedma-quic wrote:
There are basically four modes we have logic for here:
- No mustprogress optimizations
- C11 mustprogress
- C++23 mustprogress
- always mustprogress
I don't think there's really much reason to keep "always mustprogress" mode; like you note, it's not really useful. Let's just make -ffinite-loops mean the new C++ rules.
Of course, -fno-finite-loops means no mustprogress.
This does mean we don't provide a way to explicitly access C11 mustprogress mode, I guess; it's not equivalent to either of -ffinite-loops or -fno-finite-loops. But not sure how much we care. We could add a flag -fc11-finite-loops if someone does care.
https://github.com/llvm/llvm-project/pull/90066
More information about the cfe-commits
mailing list