diff options
author | Gabor Marton <martongabesz@gmail.com> | 2018-07-17 12:06:36 +0000 |
---|---|---|
committer | Gabor Marton <martongabesz@gmail.com> | 2018-07-17 12:06:36 +0000 |
commit | f086fa8443bf3676cd31e2bcd6a97691edb01007 (patch) | |
tree | 5646895fa202fde1ed67465cd1b2726f6561cd11 /clang/unittests/AST/ASTImporterTest.cpp | |
parent | da4302ce0d4652f36b966d4dfabb1556c53bf5ce (diff) | |
download | bcm5719-llvm-f086fa8443bf3676cd31e2bcd6a97691edb01007.tar.gz bcm5719-llvm-f086fa8443bf3676cd31e2bcd6a97691edb01007.zip |
[ASTImporter] Fix import of unnamed structs
Summary:
D48773 simplified ASTImporter nicely, but it introduced a new error: Unnamed
structs are not imported correctly, if they appear in a recursive context.
This patch provides a fix for structural equivalency.
Reviewers: a.sidorin, a_sidorin, balazske, gerazo
Subscribers: rnkovacs, dkrupp, cfe-commits
Differential Revision: https://reviews.llvm.org/D49296
llvm-svn: 337267
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index c59c2cd1253..84bfdadae2d 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -273,6 +273,11 @@ public: } }; +template <typename T> RecordDecl *getRecordDecl(T *D) { + auto *ET = cast<ElaboratedType>(D->getType().getTypePtr()); + return cast<RecordType>(ET->getNamedType().getTypePtr())->getDecl(); +}; + // This class provides generic methods to write tests which can check internal // attributes of AST nodes like getPreviousDecl(), isVirtual(), etc. Also, // this fixture makes it possible to import from several "From" contexts. @@ -1755,11 +1760,6 @@ TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) { )", Lang_CXX, "input0.cc"); - auto getRecordDecl = [](VarDecl *VD) { - auto *ET = cast<ElaboratedType>(VD->getType().getTypePtr()); - return cast<RecordType>(ET->getNamedType().getTypePtr())->getDecl(); - }; - auto *Obj0 = FirstDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("object0"))); auto *From0 = getRecordDecl(Obj0); @@ -2580,6 +2580,38 @@ TEST_P(ASTImporterTestBase, ImportOfNonEquivalentMethod) { EXPECT_NE(ToM1, ToM2); } +TEST_P(ASTImporterTestBase, ImportUnnamedStructsWithRecursingField) { + Decl *FromTU = getTuDecl( + R"( + struct A { + struct { + struct A *next; + } entry0; + struct { + struct A *next; + } entry1; + }; + )", + Lang_C, "input0.cc"); + auto *From = + FirstDeclMatcher<RecordDecl>().match(FromTU, recordDecl(hasName("A"))); + + Import(From, Lang_C); + + auto *ToTU = ToAST->getASTContext().getTranslationUnitDecl(); + auto *Entry0 = + FirstDeclMatcher<FieldDecl>().match(ToTU, fieldDecl(hasName("entry0"))); + auto *Entry1 = + FirstDeclMatcher<FieldDecl>().match(ToTU, fieldDecl(hasName("entry1"))); + auto *R0 = getRecordDecl(Entry0); + auto *R1 = getRecordDecl(Entry1); + EXPECT_NE(R0, R1); + EXPECT_TRUE(MatchVerifier<RecordDecl>().match( + R0, recordDecl(has(fieldDecl(hasName("next")))))); + EXPECT_TRUE(MatchVerifier<RecordDecl>().match( + R1, recordDecl(has(fieldDecl(hasName("next")))))); +} + struct DeclContextTest : ASTImporterTestBase {}; TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) { |