[PATCH] D51340: Add /Zc:DllexportInlines option to clang-cl

Takuto Ikuta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 02:43:26 PDT 2018


takuto.ikuta added inline comments.


================
Comment at: clang/lib/AST/ASTContext.cpp:9552
+    // overwrite linkage of explicit template instantiation
+    // definition/declaration.
+    return GVA_DiscardableODR;
----------------
hans wrote:
> Can you give an example for why this is needed?
Sorry, this change does not need. Removed.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5719
+          TSK != TSK_ExplicitInstantiationDeclaration &&
+          TSK != TSK_ExplicitInstantiationDefinition) {
+        if (ClassExported) {
----------------
takuto.ikuta wrote:
> takuto.ikuta wrote:
> > hans wrote:
> > > takuto.ikuta wrote:
> > > > hans wrote:
> > > > > I still don't understand why we need these checks for template instantiations. Why does it matter whether the functions get inlined or not?
> > > > When function of dllimported class is not inlined, such funtion needs to be dllexported from implementation library.
> > > > 
> > > > c.h
> > > > ```
> > > > template<typename T>
> > > > class EXPORT C {
> > > >  public:
> > > >   void f() {}
> > > > };
> > > > ```
> > > > 
> > > > cuser.cc
> > > > ```
> > > > #include "c.h"
> > > > 
> > > > void cuser() {
> > > >   C<int> c;
> > > >   c.f();  // This function may not be inlined when EXPORT is __declspec(dllimport), so link may fail.
> > > > }
> > > > ```
> > > > 
> > > > When cuser.cc and c.h are built to different library, cuser.cc needs to be able to see dllexported C::f() when C::f() is not inlined.
> > > > This is my understanding.
> > > Your example doesn't use explicit instantiation definition or declaration, so doesn't apply here I think.
> > > 
> > > As long as the dllexport and dllimport attributes matches it's fine. It doesn't matter whether the function gets inlined or not, the only thing that matters is that if it's marked dllimport on the "consumer side", it must be dllexport when building the dll.
> > Hmm, I changed the linkage for functions having DLLExport/ImportStaticLocal Attr.
> > 
> I changed linkage in ASTContext so that inline function is emitted when it is necessary when we use fno-dllexport-inlines.
I revived explicit template instantiation check. 
Found that this is necessary.

For explicit template instantiation, inheriting dll attribute from function for local static var is run before inheriting dll attribute from class for member functions. So I cannot detect local static var of inline function after class level dll attribute processing for explicit template instantiation.



https://reviews.llvm.org/D51340





More information about the cfe-commits mailing list