[cfe-commits] r154189 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/TreeTransform.h test/CodeGenObjCXX/arc.mm

John McCall rjmccall at apple.com
Fri Apr 6 11:20:53 PDT 2012


Author: rjmccall
Date: Fri Apr  6 13:20:53 2012
New Revision: 154189

URL: http://llvm.org/viewvc/llvm-project?rev=154189&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CodeGenObjCXX/arc.mm

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154189&r1=154188&r2=154189&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr  6 13:20:53 2012
@@ -8567,6 +8567,9 @@
 }
 
 void Sema::ActOnStmtExprError() {
+  // Note that function is also called by TreeTransform when leaving a
+  // StmtExpr scope without rebuilding anything.
+
   DiscardCleanupsInEvaluationContext();
   PopExpressionEvaluationContext();
 }

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=154189&r1=154188&r2=154189&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Apr  6 13:20:53 2012
@@ -6736,14 +6736,20 @@
 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(),

Modified: cfe/trunk/test/CodeGenObjCXX/arc.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc.mm?rev=154189&r1=154188&r2=154189&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/arc.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc.mm Fri Apr  6 13:20:53 2012
@@ -241,3 +241,14 @@
 // 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>;





More information about the cfe-commits mailing list