[PATCH] D74846: fix -fcodegen-modules code when used with PCH (PR44958)

Luboš Luňák via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 19 09:21:32 PST 2020


llunak created this revision.
llunak added reviewers: hans, dblaikie.
llunak added a project: clang.
Herald added a subscriber: cfe-commits.

In D69778 <https://reviews.llvm.org/D69778> I incorrectly handled two cases (checking for -building-pch-with-obj without also checking -fmodules-codegen).


Repository:
  rC Clang

https://reviews.llvm.org/D74846

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/PCH/Inputs/declspec-selectany-pch.cpp
  clang/test/PCH/Inputs/declspec-selectany-pch.h
  clang/test/PCH/declspec-selectany.cpp


Index: clang/test/PCH/declspec-selectany.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/declspec-selectany.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cl /Yc%S/Inputs/declspec-selectany-pch.h %S/Inputs/declspec-selectany-pch.cpp /c /Fo%t.obj /Fp%t.pch
+// RUN: %clang_cl /Yu%S/Inputs/declspec-selectany-pch.h %s /I%S/Inputs /c /Fo%t.obj /Fp%t.pch
+
+#include "declspec-selectany-pch.h"
+
+int main() {
+  CD3DX12_CPU_DESCRIPTOR_HANDLE desc = CD3DX12_CPU_DESCRIPTOR_HANDLE(D3D12_DEFAULT);
+  return desc.ptr;
+}
Index: clang/test/PCH/Inputs/declspec-selectany-pch.h
===================================================================
--- /dev/null
+++ clang/test/PCH/Inputs/declspec-selectany-pch.h
@@ -0,0 +1,7 @@
+struct CD3DX12_DEFAULT {};
+extern const __declspec(selectany) CD3DX12_DEFAULT D3D12_DEFAULT;
+
+struct CD3DX12_CPU_DESCRIPTOR_HANDLE {
+  CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
+  size_t ptr;
+};
Index: clang/test/PCH/Inputs/declspec-selectany-pch.cpp
===================================================================
--- /dev/null
+++ clang/test/PCH/Inputs/declspec-selectany-pch.cpp
@@ -0,0 +1 @@
+#include "declspec-selectany-pch.h"
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===================================================================
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1017,10 +1017,12 @@
       // definition in the module interface is provided by the compilation of
       // that module interface unit, not by its users. (Inline variables are
       // still emitted in module users.)
+      // Similarly if a PCH is built with codegen and its own object file.
       ModulesCodegen =
           (((Writer.WritingModule &&
              Writer.WritingModule->Kind == Module::ModuleInterfaceUnit) ||
-            Writer.Context->getLangOpts().BuildingPCHWithObjectFile) &&
+            (Writer.Context->getLangOpts().BuildingPCHWithObjectFile &&
+             Writer.Context->getLangOpts().ModulesCodegen)) &&
            Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
     }
     Record.push_back(ModulesCodegen);
@@ -2451,9 +2453,8 @@
   bool ModulesCodegen = false;
   if (!FD->isDependentContext()) {
     Optional<GVALinkage> Linkage;
-    if ((Writer->WritingModule &&
-         Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) ||
-        Writer->Context->getLangOpts().BuildingPCHWithObjectFile) {
+    if (Writer->WritingModule &&
+        Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
       // When building a C++ Modules TS module interface unit, a strong
       // definition in the module interface is provided by the compilation of
       // that module interface unit, not by its users. (Inline functions are


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74846.245437.patch
Type: text/x-patch
Size: 2844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200219/dfa50037/attachment-0001.bin>


More information about the cfe-commits mailing list