r316069 - [ASTImporter] Import SubStmt of CaseStmt
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 02:25:18 PDT 2017
Author: xazax
Date: Wed Oct 18 02:25:18 2017
New Revision: 316069
URL: http://llvm.org/viewvc/llvm-project?rev=316069&view=rev
Log:
[ASTImporter] Import SubStmt of CaseStmt
Patch by: Rafael Stahl!
Differential Revision: https://reviews.llvm.org/D38943
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=316069&r1=316068&r2=316069&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Oct 18 02:25:18 2017
@@ -3983,12 +3983,16 @@ Stmt *ASTNodeImporter::VisitCaseStmt(Cas
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) {
Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=316069&r1=316068&r2=316069&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Wed Oct 18 02:25:18 2017
@@ -97,6 +97,10 @@ testImport(const std::string &FromCode,
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
More information about the cfe-commits
mailing list