diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-25 23:27:26 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-25 23:27:26 +0000 |
commit | e946fc833d8592aa2890bfd9839f1ad839b3d284 (patch) | |
tree | 1f9125aa9546447672670d24704ea7091be2576c /lib | |
parent | b31c289678a3fe0f062656015dbcd57272f60742 (diff) |
Patch for mis-compile of statement expressions with
non-trivial copy constructors. // rdar: //8540501.
A test will be added to llvm nightly tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e329ada932..0510bd2ed8 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7067,21 +7067,43 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, // If there are sub stmts in the compound stmt, take the type of the last one // as the type of the stmtexpr. QualType Ty = Context.VoidTy; - + bool StmtExprMayBindToTemp = false; if (!Compound->body_empty()) { Stmt *LastStmt = Compound->body_back(); + LabelStmt *LastLabelStmt = 0; // If LastStmt is a label, skip down through into the body. - while (LabelStmt *Label = dyn_cast<LabelStmt>(LastStmt)) + while (LabelStmt *Label = dyn_cast<LabelStmt>(LastStmt)) { + LastLabelStmt = Label; LastStmt = Label->getSubStmt(); - - if (Expr *LastExpr = dyn_cast<Expr>(LastStmt)) + } + if (Expr *LastExpr = dyn_cast<Expr>(LastStmt)) { Ty = LastExpr->getType(); + if (!Ty->isDependentType() && !LastExpr->isTypeDependent()) { + ExprResult Res = PerformCopyInitialization( + InitializedEntity::InitializeResult(LPLoc, + Ty, + false), + SourceLocation(), + Owned(LastExpr)); + if (Res.isInvalid()) + return ExprError(); + if ((LastExpr = Res.takeAs<Expr>())) { + if (!LastLabelStmt) + Compound->setLastStmt(LastExpr); + else + LastLabelStmt->setSubStmt(LastExpr); + StmtExprMayBindToTemp = true; + } + } + } } // FIXME: Check that expression type is complete/non-abstract; statement // expressions are not lvalues. - - return Owned(new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc)); + Expr *ResStmtExpr = new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc); + if (StmtExprMayBindToTemp) + return MaybeBindToTemporary(ResStmtExpr); + return Owned(ResStmtExpr); } ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |