diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-20 18:43:47 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-06-20 18:43:47 +0000 |
| commit | d282252b652c8ef8a45ffb6a06c29da83be53d16 (patch) | |
| tree | 040ca9242d12c8d6583e078b5fbbe5e012eb92d7 /lib/CodeGen/CGExpr.cpp | |
| parent | 426974cf6ddb91596b810e73a479e324ecf5c5f0 (diff) | |
| download | clang-d282252b652c8ef8a45ffb6a06c29da83be53d16.tar.gz clang-d282252b652c8ef8a45ffb6a06c29da83be53d16.tar.bz2 clang-d282252b652c8ef8a45ffb6a06c29da83be53d16.tar.xz | |
Don't crash when emitting a glvalue conditional where one arm is a
throw-expression. Based on a patch by Marius Wachtler!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211388 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index fda04104b6..62ecc7394a 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2684,6 +2684,19 @@ LValue CodeGenFunction::EmitInitListLValue(const InitListExpr *E) { return EmitLValue(E->getInit(0)); } +/// Emit the operand of a glvalue conditional operator. This is either a glvalue +/// or a (possibly-parenthesized) throw-expression. If this is a throw, no +/// LValue is returned and the current block has been terminated. +static Optional<LValue> EmitLValueOrThrowExpression(CodeGenFunction &CGF, + const Expr *Operand) { + if (auto *ThrowExpr = dyn_cast<CXXThrowExpr>(Operand->IgnoreParens())) { + CGF.EmitCXXThrowExpr(ThrowExpr, /*KeepInsertionPoint*/false); + return None; + } + + return CGF.EmitLValue(Operand); +} + LValue CodeGenFunction:: EmitConditionalOperatorLValue(const AbstractConditionalOperator *expr) { if (!expr->isGLValue()) { @@ -2721,31 +2734,40 @@ EmitConditionalOperatorLValue(const AbstractConditionalOperator *expr) { EmitBlock(lhsBlock); Cnt.beginRegion(Builder); eval.begin(*this); - LValue lhs = EmitLValue(expr->getTrueExpr()); + Optional<LValue> lhs = + EmitLValueOrThrowExpression(*this, expr->getTrueExpr()); eval.end(*this); - if (!lhs.isSimple()) + if (lhs && !lhs->isSimple()) return EmitUnsupportedLValue(expr, "conditional operator"); lhsBlock = Builder.GetInsertBlock(); - Builder.CreateBr(contBlock); + if (lhs) + Builder.CreateBr(contBlock); // Any temporaries created here are conditional. EmitBlock(rhsBlock); eval.begin(*this); - LValue rhs = EmitLValue(expr->getFalseExpr()); + Optional<LValue> rhs = + EmitLValueOrThrowExpression(*this, expr->getFalseExpr()); eval.end(*this); - if (!rhs.isSimple()) + if (rhs && !rhs->isSimple()) return EmitUnsupportedLValue(expr, "conditional operator"); rhsBlock = Builder.GetInsertBlock(); EmitBlock(contBlock); - llvm::PHINode *phi = Builder.CreatePHI(lhs.getAddress()->getType(), 2, - "cond-lvalue"); - phi->addIncoming(lhs.getAddress(), lhsBlock); - phi->addIncoming(rhs.getAddress(), rhsBlock); - return MakeAddrLValue(phi, expr->getType()); + if (lhs && rhs) { + llvm::PHINode *phi = Builder.CreatePHI(lhs->getAddress()->getType(), + 2, "cond-lvalue"); + phi->addIncoming(lhs->getAddress(), lhsBlock); + phi->addIncoming(rhs->getAddress(), rhsBlock); + return MakeAddrLValue(phi, expr->getType()); + } else { + assert((lhs || rhs) && + "both operands of glvalue conditional are throw-expressions?"); + return lhs ? *lhs : *rhs; + } } /// EmitCastLValue - Casts are never lvalues unless that cast is to a reference |
