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

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 29 07:32:25 PDT 2018


hans added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5719
+          TSK != TSK_ExplicitInstantiationDeclaration &&
+          TSK != TSK_ExplicitInstantiationDefinition) {
+        if (ClassExported) {
----------------
takuto.ikuta wrote:
> 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.
> 
Oh I see, it's a static local problem..
Can you provide a concrete example that does not work without your check?
Maybe this is the right thing to do, but I would like to understand exactly what the problem is.


https://reviews.llvm.org/D51340





More information about the cfe-commits mailing list