[cfe-commits] r69510 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/scope-check.c
Chris Lattner
sabre at nondot.org
Sat Apr 18 22:28:13 PDT 2009
Author: lattner
Date: Sun Apr 19 00:28:12 2009
New Revision: 69510
URL: http://llvm.org/viewvc/llvm-project?rev=69510&view=rev
Log:
run the jump checker on blocks, even though they don't have gotos,
they do allow switches.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/scope-check.c
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=69510&r1=69509&r2=69510&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Apr 19 00:28:12 2009
@@ -107,6 +107,10 @@
/// block.
llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
+ /// SavedFunctionNeedsScopeChecking - This is the value of
+ /// CurFunctionNeedsScopeChecking at the point when the block started.
+ bool SavedFunctionNeedsScopeChecking;
+
/// PrevBlockInfo - If this is nested inside another block, this points
/// to the outer block.
BlockSemaInfo *PrevBlockInfo;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=69510&r1=69509&r2=69510&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Apr 19 00:28:12 2009
@@ -4661,6 +4661,8 @@
BSI->ReturnType = 0;
BSI->TheScope = BlockScope;
BSI->hasBlockDeclRefExprs = false;
+ BSI->SavedFunctionNeedsScopeChecking = CurFunctionNeedsScopeChecking;
+ CurFunctionNeedsScopeChecking = false;
BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc);
PushDeclContext(BlockScope, BSI->TheDecl);
@@ -4746,11 +4748,12 @@
// Ensure that CurBlock is deleted.
llvm::OwningPtr<BlockSemaInfo> CC(CurBlock);
+ CurFunctionNeedsScopeChecking = CurBlock->SavedFunctionNeedsScopeChecking;
+
// Pop off CurBlock, handle nested blocks.
CurBlock = CurBlock->PrevBlockInfo;
// FIXME: Delete the ParmVarDecl objects as well???
-
}
/// ActOnBlockStmtExpr - This is called when the body of a block statement
@@ -4793,6 +4796,11 @@
BlockTy = Context.getBlockPointerType(BlockTy);
+ // If needed, diagnose invalid gotos and switches in the block.
+ if (CurFunctionNeedsScopeChecking)
+ DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get()));
+ CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking;
+
BSI->TheDecl->setBody(static_cast<CompoundStmt*>(body.release()));
return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy,
BSI->hasBlockDeclRefExprs));
Modified: cfe/trunk/test/Sema/scope-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/scope-check.c?rev=69510&r1=69509&r2=69510&view=diff
==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Sun Apr 19 00:28:12 2009
@@ -164,9 +164,22 @@
return;
}
+void test11(int n) {
+ void *P = ^{
+ switch (n) {
+ case 1:;
+ case 2:
+ case 3:;
+ int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
+ case 4: // expected-error {{illegal switch case into protected scope}}
+ return;
+ }
+ };
+}
+
// TODO: When and if gotos are allowed in blocks, this should work.
-void test13(int n) {
+void test12(int n) {
void *P = ^{
goto L1; // expected-error {{goto not allowed in block literal}}
L1:
More information about the cfe-commits
mailing list