[llvm-bugs] [Bug 38934] New: Failing to dllexport class template member w/ explicit instantiation and PCH

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 13 07:35:59 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38934

            Bug ID: 38934
           Summary: Failing to dllexport class template member w/ explicit
                    instantiation and PCH
           Product: new-bugs
           Version: 7.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: hans at chromium.org
                CC: llvm-bugs at lists.llvm.org

For example:

#ifndef IN_HEADER
#define IN_HEADER

template <typename T> struct S { };
extern template struct S<int>;

inline void use(S<int> *s, S<int> *t) {
  *s = *t;
}

#else

template struct __declspec(dllexport) S<int>;

#endif



$ clang -cc1 -triple i686-pc-win32 -fms-extensions -emit-pch
-building-pch-with-obj -o x.pch /tmp/x.cc
$ clang -cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm
-DUSE_PCH -include-pch x.pch -o - /tmp/x.cc

In the second invocation, S<int>::operator=(S<int>&) is supposed to get
emitted, but it's not because it appears as if its definition comes from the
PCH file and so would be emitted in the .obj file corresponding to the PCH.

However, it's just the declaration that's in the PCH, not the definition.


The code in ASTContext::DeclMustBeEmitted() is supposed to catch exactly this:

    bool IsExpInstDef =
        isa<FunctionDecl>(D) &&
        cast<FunctionDecl>(D)->getTemplateSpecializationKind() ==
            TSK_ExplicitInstantiationDefinition;

    if (getExternalSource()->DeclIsFromPCHWithObjectFile(D) && !IsExpInstDef)
      return false;


However it doesn't work here because getTemplateSpecializationKind() returns 0,
as the function itself is not a template. At least that's what I think is
happening. It's seems I'm not understanding the AST right.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180913/1eecf9b3/attachment.html>


More information about the llvm-bugs mailing list