diff options
author | Gabor Marton <martongabesz@gmail.com> | 2018-07-05 09:51:13 +0000 |
---|---|---|
committer | Gabor Marton <martongabesz@gmail.com> | 2018-07-05 09:51:13 +0000 |
commit | 0bebf9594440424ee722b78ca45e97907c4c353b (patch) | |
tree | c387dab735c2e075cd8a116490c55b960560aaa5 /clang/unittests/AST/ASTImporterTest.cpp | |
parent | 6dc45e6ca07781aba05009713731175d7bcaa47d (diff) | |
download | bcm5719-llvm-0bebf9594440424ee722b78ca45e97907c4c353b.tar.gz bcm5719-llvm-0bebf9594440424ee722b78ca45e97907c4c353b.zip |
[ASTImporter] Fix import of objects with anonymous types
Summary:
Currently, anonymous types are merged into the same redecl chain even if they
are structurally inequivalent. This results that global objects are not
imported, if there are at least two global objects with different anonymous
types. This patch provides a fix.
Reviewers: a.sidorin, balazske, r.stahl
Subscribers: rnkovacs, dkrupp, cfe-commits
Differential Revision: https://reviews.llvm.org/D48773
llvm-svn: 336332
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index dfcb6c18939..1f86b91a88d 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1682,6 +1682,35 @@ TEST_P( .match(ToTU, classTemplateSpecializationDecl())); } +TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) { + Decl *FromTU = getTuDecl( + R"( + struct { int a; int b; } object0 = { 2, 3 }; + struct { int x; int y; int z; } object1; + )", + 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); + auto *Obj1 = + FirstDeclMatcher<VarDecl>().match(FromTU, varDecl(hasName("object1"))); + auto *From1 = getRecordDecl(Obj1); + + auto *To0 = Import(From0, Lang_CXX); + auto *To1 = Import(From1, Lang_CXX); + + EXPECT_TRUE(To0); + EXPECT_TRUE(To1); + EXPECT_NE(To0, To1); + EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl()); +} + struct ImportFunctions : ASTImporterTestBase {}; TEST_P(ImportFunctions, |