sberg updated this revision to Diff 137374. sberg added a comment. Turns out DLLAttr-inherited-from-class is only added to members during Sema::CheckCompletedClass -> Sema::checkClassLevelDLLAttribute, when friend re-decls of those members may already have been created.
https://reviews.llvm.org/D16632 Files: clang/lib/Sema/SemaDeclCXX.cpp clang/test/CodeGenCXX/dllexport.cpp Index: clang/test/CodeGenCXX/dllexport.cpp =================================================================== --- clang/test/CodeGenCXX/dllexport.cpp +++ clang/test/CodeGenCXX/dllexport.cpp @@ -290,6 +290,16 @@ __declspec(dllexport) void friend1() {} void friend2() {} +// MSC-DAG: define dso_local dllexport void @"\01?func@Befriended@@SAXXZ"() +// GNU-DAG: define dso_local dllexport void @_ZN10Befriended4funcEv() +struct __declspec(dllexport) Befriended { + static void func(); + struct Befriending { + friend void Befriended::func(); + }; +}; +void Befriended::func() {} + // Implicit declarations can be redeclared with dllexport. // MSC-DAG: define dso_local dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"( // GNU-DAG: define dso_local dllexport noalias i8* @_Znw{{[yj]}}( Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -5688,6 +5688,21 @@ cast<InheritableAttr>(ClassAttr->clone(getASTContext())); NewAttr->setInherited(true); Member->addAttr(NewAttr); + + if (MD) { + // Propagate DLLAttr to friend re-declarations of MD that have already + // been constructed. + for (FunctionDecl *FD = MD->getMostRecentDecl(); FD; + FD = FD->getPreviousDecl()) { + if (FD->getFriendObjectKind() == Decl::FOK_None) + continue; + assert(!getDLLAttr(FD) && + "friend re-decl should not already have a DLLAttr"); + NewAttr = cast<InheritableAttr>(ClassAttr->clone(getASTContext())); + NewAttr->setInherited(true); + FD->addAttr(NewAttr); + } + } } }
Index: clang/test/CodeGenCXX/dllexport.cpp =================================================================== --- clang/test/CodeGenCXX/dllexport.cpp +++ clang/test/CodeGenCXX/dllexport.cpp @@ -290,6 +290,16 @@ __declspec(dllexport) void friend1() {} void friend2() {} +// MSC-DAG: define dso_local dllexport void @"\01?func@Befriended@@SAXXZ"() +// GNU-DAG: define dso_local dllexport void @_ZN10Befriended4funcEv() +struct __declspec(dllexport) Befriended { + static void func(); + struct Befriending { + friend void Befriended::func(); + }; +}; +void Befriended::func() {} + // Implicit declarations can be redeclared with dllexport. // MSC-DAG: define dso_local dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"( // GNU-DAG: define dso_local dllexport noalias i8* @_Znw{{[yj]}}( Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -5688,6 +5688,21 @@ cast<InheritableAttr>(ClassAttr->clone(getASTContext())); NewAttr->setInherited(true); Member->addAttr(NewAttr); + + if (MD) { + // Propagate DLLAttr to friend re-declarations of MD that have already + // been constructed. + for (FunctionDecl *FD = MD->getMostRecentDecl(); FD; + FD = FD->getPreviousDecl()) { + if (FD->getFriendObjectKind() == Decl::FOK_None) + continue; + assert(!getDLLAttr(FD) && + "friend re-decl should not already have a DLLAttr"); + NewAttr = cast<InheritableAttr>(ClassAttr->clone(getASTContext())); + NewAttr->setInherited(true); + FD->addAttr(NewAttr); + } + } } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits