Don't dllexport reference temporaries
authorHans Wennborg <hans@chromium.org>
Fri, 4 Feb 2022 10:11:11 +0000 (11:11 +0100)
committerHans Wennborg <hans@chromium.org>
Fri, 4 Feb 2022 15:31:51 +0000 (16:31 +0100)
commit853e0aa424e40b80d0bda1dd8a3471a361048e4b
tree4a90d1ae4e2abafa025418388339fa1dc2c9ea99
parent466c0d0dc7c84139cf747b5513f69b8c6a772e7f
Don't dllexport reference temporaries

Even if the reference itself is dllexport, the temporary should not be.
In fact, we're already giving it internal linkage, so dllexporting it
is not just wasteful, but will fail to link, as in the example below:

  $ cat /tmp/a.cc
  void _DllMainCRTStartup() {}
  const int __declspec(dllexport) &foo = 42;

  $ clang-cl -fuse-ld=lld /tmp/a.cc /Zl /link /dll /out:a.dll
  lld-link: error: <root>: undefined symbol: int const &foo::$RT1

Differential revision: https://reviews.llvm.org/D118980
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/reference-temporary-ms.cpp [new file with mode: 0644]