diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -5066,6 +5066,11 @@ auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); for (auto *FoundDecl : FoundDecls) { if (auto *FoundProp = dyn_cast(FoundDecl)) { + // Instance and class properties can share the same name but are different + // declarations. + if (FoundProp->isInstanceProperty() != D->isInstanceProperty()) + continue; + // Check property types. if (!Importer.IsStructurallyEquivalent(D->getType(), FoundProp->getType())) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -5639,6 +5639,35 @@ EXPECT_TRUE(ToMethod->getSelfDecl() != nullptr); } +TEST_P(ASTImporterOptionSpecificTestBase, ObjPropertyNameConflict) { + // Tests that properties that share the same name are correctly imported. + // This is only possible with one instance and one class property. + Decl *FromTU = getTuDecl(R"( + @interface DupProp{} + @property (class) int prop; + @property int prop; + @end + )", + Lang_OBJCXX, "input.mm"); + auto *FromClass = FirstDeclMatcher().match( + FromTU, namedDecl(hasName("DupProp"))); + auto ToClass = Import(FromClass, Lang_OBJCXX); + ASSERT_TRUE(ToClass); + // We should have one class and one instance property. + ASSERT_EQ( + 1, std::distance(ToClass->classprop_begin(), ToClass->classprop_end())); + ASSERT_EQ(1, + std::distance(ToClass->instprop_begin(), ToClass->instprop_end())); + for (clang::ObjCPropertyDecl *prop : ToClass->properties()) { + // All properties should have a getter and a setter. + ASSERT_TRUE(prop->getGetterMethodDecl()); + ASSERT_TRUE(prop->getSetterMethodDecl()); + // The getters/setters should be able to find the right associated property. + ASSERT_EQ(prop->getGetterMethodDecl()->findPropertyDecl(), prop); + ASSERT_EQ(prop->getSetterMethodDecl()->findPropertyDecl(), prop); + } +} + struct ImportAutoFunctions : ASTImporterOptionSpecificTestBase {}; TEST_P(ImportAutoFunctions, ReturnWithTypedefDeclaredInside) {