Two patches that clarify the logic to emit for/for-range statements a bit. There shouldn't be any meaningful functionality change.
Okay to commit these?
>From 4617099335b3fdc502d02af96b9dfd06c325ac16 Mon Sep 17 00:00:00 2001 From: Justin Bogner <[email protected]> Date: Thu, 24 Oct 2013 14:09:48 -0700 Subject: [PATCH 1/2] CodeGen: Move an initialization away from an unrelated comment An initialization somehow found its way in between a comment and the block of code the comment is about. Moving the initialization makes this less confusing. --- lib/CodeGen/CGStmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 2408224..497a490 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -643,11 +643,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { if (S.getCond()) { // If the for statement has a condition scope, emit the local variable // declaration. - llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); if (S.getConditionVariable()) { EmitAutoVarDecl(*S.getConditionVariable()); } + llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); // If there are any cleanups between here and the loop-exit scope, // create a block to stage a loop exit along. if (ForScope.requiresCleanups()) -- 1.8.3.4 (Apple Git-47)
>From 92286c079284a4bdc64282b932df5b2a542086fa Mon Sep 17 00:00:00 2001 From: Justin Bogner <[email protected]> Date: Mon, 28 Oct 2013 14:00:17 -0700 Subject: [PATCH 2/2] CodeGen: Use EmitBranchOnBool when generating For and CXXForRange A while ago EmitForStmt was changed to explicitly evaluate the condition expression and create a branch instead of using EmitBranchOnBool, so that the condition expression could be used for some cleanup logic. The cleanup stuff has since been reorganized, and this is no longer necessary. In EmitCXXForRange, the evaluated condition was never used for anything else. The logic was presumably modeled on EmitForStmt. --- lib/CodeGen/CGStmt.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 497a490..0bc51dd 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -639,7 +639,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { // Create a cleanup scope for the condition variable cleanups. RunCleanupsScope ConditionScope(*this); - llvm::Value *BoolCondVal = 0; if (S.getCond()) { // If the for statement has a condition scope, emit the local variable // declaration. @@ -658,8 +657,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { // C99 6.8.5p2/p4: The first substatement is executed if the expression // compares unequal to 0. The condition must be a scalar type. - BoolCondVal = EvaluateExprAsBool(S.getCond()); - Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock); + EmitBranchOnBoolExpr(S.getCond(), ForBody, ExitBlock); if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); @@ -739,8 +737,7 @@ void CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S) { // The body is executed if the expression, contextually converted // to bool, is true. - llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond()); - Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock); + EmitBranchOnBoolExpr(S.getCond(), ForBody, ExitBlock); if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); -- 1.8.3.4 (Apple Git-47)
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
