[llvm-bugs] [Bug 37801] New: [clang-cl] Don't emit dllexport inline function definitions from pch files

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 14 05:27:44 PDT 2018


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

            Bug ID: 37801
           Summary: [clang-cl] Don't emit dllexport inline function
                    definitions from pch files
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hans at chromium.org
                CC: llvm-bugs at lists.llvm.org

The definitions will already be present in the .obj file generated when
building the PCH. Not emitting them again saves a lot of compile time.

For example,


header.h

  #ifndef HEADER_H
  #define HEADER_H

  inline int __declspec(dllexport) foo() {
    return 42;
  }

  #endif


precompiled_header.h

  #include "header.h"


precompiled_header.cc

  // No include needed; the include is forced with /FI.


a.cc

  #include "header.h"

  int __declspec(dllexport) bar() {
    return 1;
  }


To build the PCH file:

  cl /c precompiled_header.cc /FIprecompiled_header.h /Ycprecompiled_header.h
/Fppch.pch


Note how the definition of foo() is emitted into precompiled_header.obj:

  dumpbin /directives precompiled_header.obj | grep EXPORT
     /EXPORT:?foo@@YAHXZ


To use the PCH when compiling a.cc:

  cl /c a.cc /FIprecompiled_header.h /Yuprecompiled_header.h /Fppch.pch


Note how the definition of foo() is *not* emitted into a.obj:

  dumpbin /directives a.obj | grep EXPORT
     /EXPORT:?bar@@YAHXZ


If we had not used the PCH, foo() would have been emitted:

  cl /c a.cc && dumpbin /directives a.obj | grep EXPORT
     /EXPORT:?foo@@YAHXZ
     /EXPORT:?bar@@YAHXZ


clang-cl does not do this optimization, and always emits foo() even if it came
from the PCH.

-- 
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/20180614/a427d610/attachment.html>


More information about the llvm-bugs mailing list