From a626d645d5f6ddd1f8c5ed3b6664af17e559ee5f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 10 Sep 2011 00:02:34 +0000 Subject: Extend the Stmt AST to make it easier to look through label, default, and case statements. Use this to make the logic in the CFG builder more robust at finding the actual statements within a compound statement, even when there are many layers of labels obscuring it. Also extend the test cases for a large chunk of PR10063. Still more work to do here though. llvm-svn: 139437 --- clang/lib/AST/Stmt.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'clang/lib/AST/Stmt.cpp') diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index 9e4be940110..e7b87e4db67 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -97,6 +97,22 @@ Stmt *Stmt::IgnoreImplicit() { return s; } +/// \brief Strip off all label-like statements. +/// +/// This will strip off label statements, case statements, and default +/// statements recursively. +const Stmt *Stmt::stripLabelLikeStatements() const { + const Stmt *S = this; + while (true) { + if (const LabelStmt *LS = dyn_cast(S)) + S = LS->getSubStmt(); + else if (const SwitchCase *SC = dyn_cast(S)) + S = SC->getSubStmt(); + else + return S; + } +} + namespace { struct good {}; struct bad {}; -- cgit v1.2.3