diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2017-10-18 09:25:18 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2017-10-18 09:25:18 +0000 |
commit | 480892b75fc15ee435b4b689a0021bb5f5fd7166 (patch) | |
tree | 4ede1f257c809dcebf58016253e88e35c751d0a0 | |
parent | a4ca931336adb72a10b41d10f82df2e9345c67a7 (diff) | |
download | bcm5719-llvm-480892b75fc15ee435b4b689a0021bb5f5fd7166.tar.gz bcm5719-llvm-480892b75fc15ee435b4b689a0021bb5f5fd7166.zip |
[ASTImporter] Import SubStmt of CaseStmt
Patch by: Rafael Stahl!
Differential Revision: https://reviews.llvm.org/D38943
llvm-svn: 316069
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 10 | ||||
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 13 |
2 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 49e8321953c..c92647770e3 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3983,12 +3983,16 @@ Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { Expr *ToRHS = Importer.Import(S->getRHS()); if (!ToRHS && S->getRHS()) return nullptr; + Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); + if (!ToSubStmt && S->getSubStmt()) + return nullptr; SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); - return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS, - ToCaseLoc, ToEllipsisLoc, - ToColonLoc); + CaseStmt *ToStmt = new (Importer.getToContext()) + CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); + ToStmt->setSubStmt(ToSubStmt); + return ToStmt; } Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 485cf252c15..aea5bfa39e8 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -97,6 +97,10 @@ testImport(const std::string &FromCode, Language FromLang, llvm::raw_svector_ostream ToNothing(ImportChecker); ToCtx.getTranslationUnitDecl()->print(ToNothing); + // This traverses the AST to catch certain bugs like poorly or not + // implemented subtrees. + Imported->dump(ToNothing); + return Verifier.match(Imported, AMatcher); } @@ -267,6 +271,15 @@ TEST(ImportExpr, ImportParenListExpr) { hasUnaryOperand(cxxThisExpr())))))))))))))))))))))))); } +TEST(ImportExpr, ImportSwitch) { + MatchVerifier<Decl> Verifier; + EXPECT_TRUE( + testImport("void declToImport() { int b; switch (b) { case 1: break; } }", + Lang_CXX, "", Lang_CXX, Verifier, + functionDecl(hasBody(compoundStmt( + has(switchStmt(has(compoundStmt(has(caseStmt())))))))))); +} + TEST(ImportExpr, ImportStmtExpr) { MatchVerifier<Decl> Verifier; // NOTE: has() ignores implicit casts, using hasDescendant() to match it |