]> granicus.if.org Git - clang/commitdiff
[ASTImporter] Import SubStmt of CaseStmt
authorGabor Horvath <xazax.hun@gmail.com>
Wed, 18 Oct 2017 09:25:18 +0000 (09:25 +0000)
committerGabor Horvath <xazax.hun@gmail.com>
Wed, 18 Oct 2017 09:25:18 +0000 (09:25 +0000)
Patch by: Rafael Stahl!

Differential Revision: https://reviews.llvm.org/D38943

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316069 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTImporter.cpp
unittests/AST/ASTImporterTest.cpp

index 49e8321953cd6b3aac1a7d71d465f2fdeb7778a4..c92647770e379049c688545b9ebef7a0a2024a36 100644 (file)
@@ -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) {
index 485cf252c15c61b826dd378761a49b67b7d83509..aea5bfa39e89faf1d0d020cb33e81f8d53466a0a 100644 (file)
@@ -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