Author: rsmith Date: Mon Aug 3 21:05:09 2015 New Revision: 243940 URL: http://llvm.org/viewvc/llvm-project?rev=243940&view=rev Log: [modules] Make IndirectFieldDecl mergeable to avoid lookup ambiguity when the same anonymous union is defined across multiple modules.
Modified: cfe/trunk/include/clang/AST/Decl.h cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h cfe/trunk/test/Modules/submodules-merge-defs.cpp Modified: cfe/trunk/include/clang/AST/Decl.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=243940&r1=243939&r2=243940&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Decl.h (original) +++ cfe/trunk/include/clang/AST/Decl.h Mon Aug 3 21:05:09 2015 @@ -2499,7 +2499,8 @@ public: /// IndirectFieldDecl - An instance of this class is created to represent a /// field injected from an anonymous union/struct into the parent scope. /// IndirectFieldDecl are always implicit. -class IndirectFieldDecl : public ValueDecl { +class IndirectFieldDecl : public ValueDecl, + public Mergeable<IndirectFieldDecl> { void anchor() override; NamedDecl **Chaining; unsigned ChainingSize; @@ -2537,6 +2538,9 @@ public: return dyn_cast<VarDecl>(*chain_begin()); } + IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); } + const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); } + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == IndirectField; } Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=243940&r1=243939&r2=243940&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Aug 3 21:05:09 2015 @@ -1178,6 +1178,8 @@ void ASTDeclReader::VisitIndirectFieldDe for (unsigned I = 0; I != FD->ChainingSize; ++I) FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx); + + mergeMergeable(FD); } ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { @@ -2638,6 +2640,13 @@ static bool isSameEntity(NamedDecl *X, N return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); } + // Indirect fields with the same target field match. + if (auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { + auto *IFDY = cast<IndirectFieldDecl>(Y); + return IFDX->getAnonField()->getCanonicalDecl() == + IFDY->getAnonField()->getCanonicalDecl(); + } + // Enumerators with the same name match. if (isa<EnumConstantDecl>(X)) // FIXME: Also check the value is odr-equivalent. Modified: cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h?rev=243940&r1=243939&r2=243940&view=diff ============================================================================== --- cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h (original) +++ cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h Mon Aug 3 21:05:09 2015 @@ -103,3 +103,11 @@ namespace RedeclDifferentDeclKind { typedef X X; using RedeclDifferentDeclKind::X; } + +namespace Anon { + struct X { + union { + int n; + }; + }; +} Modified: cfe/trunk/test/Modules/submodules-merge-defs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-merge-defs.cpp?rev=243940&r1=243939&r2=243940&view=diff ============================================================================== --- cfe/trunk/test/Modules/submodules-merge-defs.cpp (original) +++ cfe/trunk/test/Modules/submodules-merge-defs.cpp Mon Aug 3 21:05:09 2015 @@ -104,6 +104,7 @@ template<typename T, int N, template<typ J<> post_j2; FriendDefArg::Y<int> friend_def_arg; FriendDefArg::D<> friend_def_arg_d; +int post_anon_x_n = Anon::X().n; MergeFunctionTemplateSpecializations::X<int>::Q<char> xiqc; _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits