aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp b/contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp
index 0f79a2e861d2..b89017de0bcf 100644
--- a/contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp
+++ b/contrib/llvm-project/clang/lib/CodeGen/CGStmt.cpp
@@ -837,7 +837,19 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
if (!ThenCount && !getCurrentProfileCount() &&
CGM.getCodeGenOpts().OptimizationLevel)
LH = Stmt::getLikelihood(S.getThen(), S.getElse());
- EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock, ThenCount, LH);
+
+ // When measuring MC/DC, always fully evaluate the condition up front using
+ // EvaluateExprAsBool() so that the test vector bitmap can be updated prior to
+ // executing the body of the if.then or if.else. This is useful for when
+ // there is a 'return' within the body, but this is particularly beneficial
+ // when one if-stmt is nested within another if-stmt so that all of the MC/DC
+ // updates are kept linear and consistent.
+ if (!CGM.getCodeGenOpts().MCDCCoverage)
+ EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock, ThenCount, LH);
+ else {
+ llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
+ Builder.CreateCondBr(BoolCondVal, ThenBlock, ElseBlock);
+ }
// Emit the 'then' code.
EmitBlock(ThenBlock);