[cfe-commits] r137877 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/CodeGenCXX/blocks.cpp
John McCall
rjmccall at apple.com
Wed Aug 17 14:34:14 PDT 2011
Author: rjmccall
Date: Wed Aug 17 16:34:14 2011
New Revision: 137877
URL: http://llvm.org/viewvc/llvm-project?rev=137877&view=rev
Log:
Gather cleanups correctly in block return statements.
Thanks to Ted for finding this with magic tools.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=137877&r1=137876&r2=137877&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Aug 17 16:34:14 2011
@@ -1741,21 +1741,17 @@
// pickier with blocks than for normal functions because we don't have GCC
// compatibility to worry about here.
ReturnStmt *Result = 0;
+ const VarDecl *NRVOCandidate = 0;
if (CurBlock->ReturnType->isVoidType()) {
if (RetValExp && !RetValExp->isTypeDependent() &&
(!getLangOptions().CPlusPlus || !RetValExp->getType()->isVoidType())) {
Diag(ReturnLoc, diag::err_return_block_has_expr);
RetValExp = 0;
}
- Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, 0);
} else if (!RetValExp) {
if (!CurBlock->ReturnType->isDependentType())
return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
-
- Result = new (Context) ReturnStmt(ReturnLoc, 0, 0);
} else {
- const VarDecl *NRVOCandidate = 0;
-
if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
// we have a non-void block with an expression, continue checking
@@ -1775,19 +1771,18 @@
// FIXME: Cleanup temporaries here, anyway?
return StmtError();
}
+ RetValExp = Res.take();
- if (RetValExp) {
- CheckImplicitConversions(RetValExp, ReturnLoc);
- RetValExp = MaybeCreateExprWithCleanups(RetValExp);
- }
-
- RetValExp = Res.takeAs<Expr>();
if (RetValExp)
CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
}
+ }
- Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
+ if (RetValExp) {
+ CheckImplicitConversions(RetValExp, ReturnLoc);
+ RetValExp = MaybeCreateExprWithCleanups(RetValExp);
}
+ Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
// If we need to check for the named return value optimization, save the
// return statement in our scope for later processing.
Modified: cfe/trunk/test/CodeGenCXX/blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/blocks.cpp?rev=137877&r1=137876&r2=137877&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/blocks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/blocks.cpp Wed Aug 17 16:34:14 2011
@@ -104,3 +104,29 @@
consume(^{ (void) b; });
}
}
+
+// rdar://problem/9971485
+namespace test4 {
+ struct A {
+ A();
+ ~A();
+ };
+
+ void foo(A a);
+
+ void test() {
+ extern void consume(void(^)());
+ consume(^{ return foo(A()); });
+ }
+ // CHECK: define void @_ZN5test44testEv()
+ // CHECK: define internal void @__test_block_invoke
+ // CHECK: [[TMP:%.*]] = alloca [[A:%.*]], align 1
+ // CHECK-NEXT: alloca i32
+ // CHECK-NEXT: bitcast i8*
+ // CHECK-NEXT: call void @_ZN5test41AC1Ev([[A]]* [[TMP]])
+ // CHECK-NEXT: call void @_ZN5test43fooENS_1AE([[A]]* [[TMP]])
+ // CHECK-NEXT: store i32 1,
+ // CHECK-NEXT: call void @_ZN5test41AD1Ev([[A]]* [[TMP]])
+ // CHECK-NEXT: ret void
+}
+
More information about the cfe-commits
mailing list