summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorWolfgang Pieb <Wolfgang.Pieb@sony.com>2016-07-11 22:22:23 +0000
committerWolfgang Pieb <Wolfgang.Pieb@sony.com>2016-07-11 22:22:23 +0000
commit5675c9698775b9c29254aa46de216705576cc3c4 (patch)
treedf36f02edcd5a23f2a8c7fa48d0815c958b946cb /clang/lib/CodeGen
parent118cb4180f30a5e501a055dc859b326049a24be2 (diff)
downloadbcm5719-llvm-5675c9698775b9c29254aa46de216705576cc3c4.tar.gz
bcm5719-llvm-5675c9698775b9c29254aa46de216705576cc3c4.zip
Prevent the creation of empty (forwarding) blocks resulting from nested ifs.
Summary: Nested if statements can generate empty BBs whose terminator branches unconditionally to its successor. These branches are not eliminated to help generate better line number information in some cases, but there is no reason to keep the empty blocks that result from nested ifs. Reviewers: mehdi_amini, dblaikie, echristo Subscribers: mehdi_amini, cfe-commits Differential review: http://reviews.llvm.org/D11360 llvm-svn: 275115
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGStmt.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 29889dd6b50..ee6e3ebb356 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -613,7 +613,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
RunCleanupsScope ThenScope(*this);
EmitStmt(S.getThen());
}
- EmitBranch(ContBlock);
+ {
+ auto CurBlock = Builder.GetInsertBlock();
+ EmitBranch(ContBlock);
+ // Eliminate any empty blocks that may have been created by nested
+ // control flow statements in the 'then' clause.
+ if (CurBlock)
+ SimplifyForwardingBlocks(CurBlock);
+ }
// Emit the 'else' code if present.
if (const Stmt *Else = S.getElse()) {
@@ -629,7 +636,12 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
{
// There is no need to emit line number for an unconditional branch.
auto NL = ApplyDebugLocation::CreateEmpty(*this);
+ auto CurBlock = Builder.GetInsertBlock();
EmitBranch(ContBlock);
+ // Eliminate any empty blocks that may have been created by nested
+ // control flow statements emitted in the 'else' clause.
+ if (CurBlock)
+ SimplifyForwardingBlocks(CurBlock);
}
}
OpenPOWER on IntegriCloud