Fix a Sema invariant bug that I recently introduced involving

the template instantiation of statement-expressions.

I think it was jyasskin who had a crashing testcase in this area;
hopefully this fixes it and he can find his testcase and check it in.

llvm-svn: 154189
This commit is contained in:
John McCall 2012-04-06 18:20:53 +00:00
parent 0e09facb85
commit ed7b27830d
3 changed files with 22 additions and 2 deletions

View File

@ -8567,6 +8567,9 @@ void Sema::ActOnStartStmtExpr() {
}
void Sema::ActOnStmtExprError() {
// Note that function is also called by TreeTransform when leaving a
// StmtExpr scope without rebuilding anything.
DiscardCleanupsInEvaluationContext();
PopExpressionEvaluationContext();
}

View File

@ -6736,14 +6736,20 @@ TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
template<typename Derived>
ExprResult
TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
SemaRef.ActOnStartStmtExpr();
StmtResult SubStmt
= getDerived().TransformCompoundStmt(E->getSubStmt(), true);
if (SubStmt.isInvalid())
if (SubStmt.isInvalid()) {
SemaRef.ActOnStmtExprError();
return ExprError();
}
if (!getDerived().AlwaysRebuild() &&
SubStmt.get() == E->getSubStmt())
SubStmt.get() == E->getSubStmt()) {
// Calling this an 'error' is unintuitive, but it does the right thing.
SemaRef.ActOnStmtExprError();
return SemaRef.MaybeBindToTemporary(E);
}
return getDerived().RebuildStmtExpr(E->getLParenLoc(),
SubStmt.get(),

View File

@ -241,3 +241,14 @@ Test37 *instantiate_init() {
// CHECK: call i8* @objc_autoreleaseReturnValue
template Test37* instantiate_init<int>();
// Just make sure that the AST invariants hold properly here,
// i.e. that we don't crash.
// The block should get bound in the full-expression outside
// the statement-expression.
template <class T> class Test38 {
void test(T x) {
^{ (void) x; }, ({ x; });
}
};
// CHECK: define weak_odr void @_ZN6Test38IiE4testEi(
template class Test38<int>;