[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 30 06:26:47 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff e50a857fb16bcfe7cfc99bf87db620bc82d1cff5 043132f8c5bbc00d647dedb873e47c5dda905f9b -- clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/test/CodeGenCXX/attr-mustprogress.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index a3c66e433b..3a86ae0a1f 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -914,8 +914,9 @@ bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression,
CodeGenOptions::FiniteLoopsKind::Never)
return false;
- if(CGM.getCodeGenOpts().getFiniteLoops() == CodeGenOptions::FiniteLoopsKind::Always
- && !getLangOpts().CPlusPlus11)
+ if (CGM.getCodeGenOpts().getFiniteLoops() ==
+ CodeGenOptions::FiniteLoopsKind::Always &&
+ !getLangOpts().CPlusPlus11)
return true;
// 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
@@ -928,8 +929,8 @@ bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression,
(ControllingExpression->EvaluateAsInt(Result, getContext()) &&
Result.Val.isInt());
- bool CondIsTrue = CondIsConstInt &&
- (!ControllingExpression || Result.Val.getInt().getBoolValue());
+ bool CondIsTrue = CondIsConstInt && (!ControllingExpression ||
+ Result.Val.getInt().getBoolValue());
if (getLangOpts().C99 && CondIsConstInt)
return false;
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 3196d05906..546beae4af 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1471,7 +1471,8 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
// Ensure that the function adheres to the forward progress guarantee, which
// is required by certain optimizations.
- // In C++11 and up, the attribute will be removed if the body contains a trivial empty loop.
+ // In C++11 and up, the attribute will be removed if the body contains a
+ // trivial empty loop.
if (checkIfFunctionMustProgress())
CurFn->addFnAttr(llvm::Attribute::MustProgress);
``````````
</details>
https://github.com/llvm/llvm-project/pull/90066
More information about the cfe-commits
mailing list