abstract the SwitchStack for blocks just like we do the goto labels.
This fixes a crash on invalid (test10). rdar://6805469
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69465 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 48e465e..7818ae1 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -103,6 +103,10 @@
/// labels have a LabelStmt created for them with a null location & SubStmt.
llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
+ /// SwitchStack - This is the current set of active switch statements in the
+ /// block.
+ llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
+
/// PrevBlockInfo - If this is nested inside another block, this points
/// to the outer block.
BlockSemaInfo *PrevBlockInfo;
@@ -144,7 +148,10 @@
/// to handle blocks properly.
llvm::DenseMap<IdentifierInfo*, LabelStmt*> FunctionLabelMap;
- llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
+ /// FunctionSwitchStack - This is the current set of active switch statements
+ /// in the top level function. Clients should always use getSwitchStack() to
+ /// handle the case when they are in a block.
+ llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack;
/// ExtVectorDecls - This is a list all the extended vector types. This allows
/// us to associate a raw vector type with one of the ext_vector type names.
@@ -336,6 +343,12 @@
return CurBlock ? CurBlock->LabelMap : FunctionLabelMap;
}
+ /// getSwitchStack - This is returns the switch stack for the current block or
+ /// function.
+ llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() {
+ return CurBlock ? CurBlock->SwitchStack : FunctionSwitchStack;
+ }
+
//===--------------------------------------------------------------------===//
// Type Analysis / Processing: SemaType.cpp.
//