[cfe-commits] r56254 - in /cfe/trunk: lib/Sema/SemaChecking.cpp lib/Sema/SemaStmt.cpp test/Sema/block-return.c
Steve Naroff
snaroff at apple.com
Tue Sep 16 15:25:10 PDT 2008
Author: snaroff
Date: Tue Sep 16 17:25:10 2008
New Revision: 56254
URL: http://llvm.org/viewvc/llvm-project?rev=56254&view=rev
Log:
Sema::ActOnBlockReturnStmt(): Need to perform the UsualUnaryConversions on the return type.
Sema::CheckReturnStackAddr(): Make sure we skip over implicit casts.
Added some more test cases...
Added:
cfe/trunk/test/Sema/block-return.c
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=56254&r1=56253&r2=56254&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 16 17:25:10 2008
@@ -716,7 +716,12 @@
Diag(DR->getLocStart(), diag::warn_ret_stack_addr,
DR->getDecl()->getIdentifier()->getName(),
RetValExp->getSourceRange());
-
+
+ // Skip over implicit cast expressions when checking for block expressions.
+ if (ImplicitCastExpr *IcExpr =
+ dyn_cast_or_null<ImplicitCastExpr>(RetValExp))
+ RetValExp = IcExpr->getSubExpr();
+
if (BlockExpr *C = dyn_cast_or_null<BlockExpr>(RetValExp))
Diag(C->getLocStart(), diag::err_ret_local_block,
C->getSourceRange());
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=56254&r1=56253&r2=56254&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Sep 16 17:25:10 2008
@@ -678,9 +678,10 @@
// If this is the first return we've seen in the block, infer the type of
// the block from it.
if (CurBlock->ReturnType == 0) {
- if (RetValExp)
+ if (RetValExp) {
+ UsualUnaryConversions(RetValExp);
CurBlock->ReturnType = RetValExp->getType().getTypePtr();
- else
+ } else
CurBlock->ReturnType = Context.VoidTy.getTypePtr();
return new ReturnStmt(ReturnLoc, RetValExp);
}
Added: cfe/trunk/test/Sema/block-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-return.c?rev=56254&view=auto
==============================================================================
--- cfe/trunk/test/Sema/block-return.c (added)
+++ cfe/trunk/test/Sema/block-return.c Tue Sep 16 17:25:10 2008
@@ -0,0 +1,52 @@
+// RUN: clang -fsyntax-only %s -verify
+
+typedef void (^CL)(void);
+
+CL foo() {
+
+ short y;
+
+ short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}}
+
+ CL X = ^{
+ if (2)
+ return;
+ return 1; // expected-error {{void block should not return a value}}
+ };
+ int (^Y) (void) = ^{
+ if (3)
+ return 1;
+ else
+ return; // expected-error {{non-void block should return a value}}
+ };
+
+ char *(^Z)(void) = ^{
+ if (3)
+ return "";
+ else
+ return (char*)0;
+ };
+
+ double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}}
+ if (1)
+ return (float)1.0;
+ else
+ if (2)
+ return (double)2.0; // expected-error {{incompatible type returning 'double', expected 'float'}}
+ return 1; // expected-error {{incompatible type returning 'int', expected 'float'}}
+ };
+
+ char *(^B)(void) = ^{
+ if (3)
+ return "";
+ else
+ return 2; // expected-error {{incompatible type returning 'int', expected 'char *'}}
+ };
+ return ^{ return 1; }; // expected-error {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}} expected-error {{returning block that lives on the local stack}}
+}
+
+typedef int (^CL2)(void);
+
+CL2 foo2() {
+ return ^{ return 1; }; // expected-error {{returning block that lives on the local stack}}
+}
More information about the cfe-commits
mailing list