Skip to content
Snippets Groups Projects
Commit 08e9e453 authored by Anders Carlsson's avatar Anders Carlsson
Browse files

Fix a nasty bug where temporaries weren't marked as being conditional in some cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94341 91177308-0d34-0410-b5e6-96231b3b80d8
parent 1b36a2fc
No related branches found
No related tags found
No related merge requests found
...@@ -431,7 +431,11 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, ...@@ -431,7 +431,11 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond,
EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, FalseBlock); EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, FalseBlock);
EmitBlock(LHSTrue); EmitBlock(LHSTrue);
// Any temporaries created here are conditional.
StartConditionalBranch();
EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock); EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock);
FinishConditionalBranch();
return; return;
} else if (CondBOp->getOpcode() == BinaryOperator::LOr) { } else if (CondBOp->getOpcode() == BinaryOperator::LOr) {
// If we have "0 || X", simplify the code. "1 || X" would have constant // If we have "0 || X", simplify the code. "1 || X" would have constant
...@@ -454,7 +458,11 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, ...@@ -454,7 +458,11 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond,
EmitBranchOnBoolExpr(CondBOp->getLHS(), TrueBlock, LHSFalse); EmitBranchOnBoolExpr(CondBOp->getLHS(), TrueBlock, LHSFalse);
EmitBlock(LHSFalse); EmitBlock(LHSFalse);
// Any temporaries created here are conditional.
StartConditionalBranch();
EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock); EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock);
FinishConditionalBranch();
return; return;
} }
} }
......
...@@ -283,6 +283,9 @@ public: ...@@ -283,6 +283,9 @@ public:
/// FinishConditionalBranch - Should be called after a conditional part of an /// FinishConditionalBranch - Should be called after a conditional part of an
/// expression has been emitted. /// expression has been emitted.
void FinishConditionalBranch() { void FinishConditionalBranch() {
assert(ConditionalBranchLevel != 0 &&
"Conditional branch mismatch!");
--ConditionalBranchLevel; --ConditionalBranchLevel;
} }
......
...@@ -129,10 +129,30 @@ static unsigned f6() { ...@@ -129,10 +129,30 @@ static unsigned f6() {
return tt.Product; return tt.Product;
} }
// 5, 2
static unsigned f7() {
TempTracker tt;
{
(void)((A(tt, 2, false) && A(tt, 3, false)) || A(tt, 5, false));
}
return tt.Product;
}
// 5, 2
static unsigned f8() {
TempTracker tt;
{
(void)((A(tt, 2) || A(tt, 3)) && A(tt, 5));
}
return tt.Product;
}
extern "C" void error(); extern "C" void error();
extern "C" void print(const char *Name, unsigned N); extern "C" void print(const char *Name, unsigned N);
#define ORDER3(a, b, c) (pow(a, 1) * pow(b, 2) * pow(c, 3)) #define ORDER2(a, b) (pow(a, 1) * pow(b, 2))
#define ORDER3(a, b, c) (ORDER2(a, b) * pow(c, 3))
#define ORDER4(a, b, c, d) (ORDER3(a, b, c) * pow(d, 4)) #define ORDER4(a, b, c, d) (ORDER3(a, b, c) * pow(d, 4))
#define ORDER5(a, b, c, d, e) (ORDER4(a, b, c, d) * pow(e, 5)) #define ORDER5(a, b, c, d, e) (ORDER4(a, b, c, d) * pow(e, 5))
#define ORDER6(a, b, c, d, e, f) (ORDER5(a, b, c, d, e) * pow(f, 6)) #define ORDER6(a, b, c, d, e, f) (ORDER5(a, b, c, d, e) * pow(f, 6))
...@@ -171,6 +191,16 @@ void test() { ...@@ -171,6 +191,16 @@ void test() {
print("f6", f6()); print("f6", f6());
if (f6() != ORDER6(3, 7, 11, 5, 13, 2)) if (f6() != ORDER6(3, 7, 11, 5, 13, 2))
error(); error();
// CHECK: call void @print(i8* {{.*}}, i32 20)
print("f7", f7());
if (f7() != ORDER2(5, 2))
error();
// CHECK: call void @print(i8* {{.*}}, i32 20)
print("f8", f8());
if (f8() != ORDER2(5, 2))
error();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment