From 8d3d6c93551cc62c6d550f090991bfba1d32d0a4 Mon Sep 17 00:00:00 2001 From: John McCall Date: Thu, 13 Jan 2011 02:03:06 +0000 Subject: [PATCH] Ensure an insertion point at the end of a statement-expression. Fixes PR8967. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123360 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprAgg.cpp | 1 + lib/CodeGen/CGExprComplex.cpp | 8 ++++---- lib/CodeGen/CGExprScalar.cpp | 6 ++++-- test/CodeGen/exprs.c | 8 ++++++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index f02145ee29..0369077797 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -368,6 +368,7 @@ void AggExprEmitter::VisitBinComma(const BinaryOperator *E) { void AggExprEmitter::VisitStmtExpr(const StmtExpr *E) { CGF.EmitCompoundStmt(*E->getSubStmt(), true, Dest); + CGF.EnsureInsertPoint(); } void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) { diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp index cf1e3f11c4..5c4d0a5608 100644 --- a/lib/CodeGen/CGExprComplex.cpp +++ b/lib/CodeGen/CGExprComplex.cpp @@ -313,8 +313,7 @@ ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) { ComplexPairTy ComplexExprEmitter:: VisitImaginaryLiteral(const ImaginaryLiteral *IL) { llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr()); - return - ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag); + return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag); } @@ -326,7 +325,9 @@ ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) { } ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) { - return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getComplexVal(); + RValue result = CGF.EmitCompoundStmt(*E->getSubStmt(), true); + CGF.EnsureInsertPoint(); + return result.getComplexVal(); } /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType. @@ -635,7 +636,6 @@ ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) { ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) { CGF.EmitIgnoredExpr(E->getLHS()); - CGF.EnsureInsertPoint(); return Visit(E->getRHS()); } diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index f80304d6de..fde9f03ba7 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1204,8 +1204,10 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { } Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) { - return CGF.EmitCompoundStmt(*E->getSubStmt(), - !E->getType()->isVoidType()).getScalarVal(); + RValue value = CGF.EmitCompoundStmt(*E->getSubStmt(), + !E->getType()->isVoidType()); + CGF.EnsureInsertPoint(); + return value.getScalarVal(); } Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) { diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c index b03539333c..cc03be6a92 100644 --- a/test/CodeGen/exprs.c +++ b/test/CodeGen/exprs.c @@ -166,3 +166,11 @@ void f15() { // CHECK-NOT: load // CHECK: ret void } + +// PR8967: this was crashing +// CHECK: define void @f16() +void f16() { + __extension__({ goto lbl; }); + lbl: + ; +}