<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - "Declaration may not be in a Comdat" when using D3DX12 headers and PCH files"
   href="https://bugs.llvm.org/show_bug.cgi?id=44953">44953</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"Declaration may not be in a Comdat" when using D3DX12 headers and PCH files
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>alexandre.ganea@ubisoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, hans@chromium.org, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, rnk@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When including D3DX12 [1] headers in .PCH headers (/Yc), and using them in TUs
(/Yu), clang-cl fails with the following error:

        Declaration may not be in a Comdat!
        %struct.CD3DX12_DEFAULT* @"?D3D12_DEFAULT@@3UCD3DX12_DEFAULT@@B"
        fatal error: error in backend: Broken module found, compilation
aborted!
        Stack dump:
        0.      Program arguments: F:\llvm-project\build\bin\clang-cl.exe
/Yuprecomp.h a.cpp /c
        1.      <eof> parser at end of file
        2.      Per-function optimization
         #0 0x00007ffa8b5ba839 (C:\WINDOWS\System32\KERNELBASE.dll+0x3a839)
         #1 0x00007ff7690e5dda llvm::CrashRecoveryContext::HandleExit(int)
F:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:436:0
         #2 0x00007ff769129484 llvm::sys::Process::Exit(int)
F:\llvm-project\llvm\lib\Support\Process.cpp:95:0
         #3 0x00007ff7688982c9 LLVMErrorHandler
F:\llvm-project\clang\tools\driver\cc1_main.cpp:73:0
         #4 0x00007ff7690e60ea llvm::report_fatal_error(class llvm::Twine const
&, bool) F:\llvm-project\llvm\lib\Support\ErrorHandling.cpp:108:0
         #5 0x00007ff7690e6001 llvm::report_fatal_error(char const *, bool)
F:\llvm-project\llvm\lib\Support\ErrorHandling.cpp:83:0
         #6 0x00007ff769f2ff38 `anonymous
namespace'::VerifierLegacyPass::doFinalization
F:\llvm-project\llvm\lib\IR\Verifier.cpp:5189:0
         #7 0x00007ff768cda3af llvm::FPPassManager::doFinalization(class
llvm::Module &) F:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1536:0
         #8 0x00007ff768cd96e0
llvm::legacy::FunctionPassManagerImpl::doFinalization(class llvm::Module &)
F:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1382:0
         #9 0x00007ff76a3d11e1 clang::EmitBackendOutput(class
clang::DiagnosticsEngine &, class clang::HeaderSearchOptions const &, class
clang::CodeGenOptions const &, class clang::TargetOptions const &, class
clang::LangOptions const &, class llvm::DataLayout const &, class llvm::Module
*, enum clang::BackendAction, class std::unique_ptr<class
llvm::raw_pwrite_stream, struct std::default_delete<class
llvm::raw_pwrite_stream>>)
F:\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1582:0
        #10 0x00007ff76a75a4c6
clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &)
F:\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:339:0
        #11 0x00007ff76c175c43 clang::ParseAST(class clang::Sema &, bool, bool)
F:\llvm-project\clang\lib\Parse\ParseAST.cpp:178:0
        #12 0x00007ff76a6b2edd clang::FrontendAction::Execute(void)
F:\llvm-project\clang\lib\Frontend\FrontendAction.cpp:944:0
        #13 0x00007ff76924e70b clang::CompilerInstance::ExecuteAction(class
clang::FrontendAction &)
F:\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:969:0
        #14 0x00007ff7692b405d clang::ExecuteCompilerInvocation(class
clang::CompilerInstance *)
F:\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:292:0
        #15 0x00007ff768897eda cc1_main(class llvm::ArrayRef<char const *>,
char const *, void *) F:\llvm-project\clang\tools\driver\cc1_main.cpp:240:0
        #16 0x00007ff768894f03 ExecuteCC1Tool
F:\llvm-project\clang\tools\driver\driver.cpp:328:0
        #17 0x00007ff76a4bb536 llvm::function_ref<void ()>::callback_fn<`lambda
at F:\llvm-project\clang\lib\Driver\Job.cpp:417:22'>
F:\llvm-project\llvm\include\llvm\ADT\STLExtras.h:108:0
        #18 0x00007ff7690e5c02 llvm::CrashRecoveryContext::RunSafely(class
llvm::function_ref<(void)>)
F:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:228:0
        #19 0x00007ff76a4bae04 clang::driver::CC1Command::Execute(class
llvm::ArrayRef<class llvm::Optional<class llvm::StringRef>>, class
std::basic_string<char, struct std::char_traits<char>, class
std::allocator<char>> *, bool *) const
F:\llvm-project\clang\lib\Driver\Job.cpp:417:0
        #20 0x00007ff76921411f clang::driver::Compilation::ExecuteCommand(class
clang::driver::Command const &, class clang::driver::Command const *&) const
F:\llvm-project\clang\lib\Driver\Compilation.cpp:182:0
        #21 0x00007ff769214489 clang::driver::Compilation::ExecuteJobs(class
clang::driver::JobList const &, class llvm::SmallVectorImpl<struct
std::pair<int, class clang::driver::Command const *>> &) const
F:\llvm-project\clang\lib\Driver\Compilation.cpp:233:0
        #22 0x00007ff769228ed7 clang::driver::Driver::ExecuteCompilation(class
clang::driver::Compilation &, class llvm::SmallVectorImpl<struct std::pair<int,
class clang::driver::Command const *>> &)
F:\llvm-project\clang\lib\Driver\Driver.cpp:1479:0
        #23 0x00007ff76889447e main
F:\llvm-project\clang\tools\driver\driver.cpp:496:0
        #24 0x00007ff76d477bd0 __scrt_common_main_seh
d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
        #25 0x00007ffa8c407bd4 (C:\WINDOWS\System32\KERNEL32.DLL+0x17bd4)
        #26 0x00007ffa8db2ced1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x6ced1)
        clang-cl: error: clang frontend command failed with exit code 70 (use
-v to see invocation)

Reduced repro:

        // ---- precomp.h
        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;
        };

        // ---- precomp.cpp
        #include "precomp.h"

        // ---- a.cpp
        #include "precomp.h"

        int main() {
          CD3DX12_CPU_DESCRIPTOR_HANDLE desc =
CD3DX12_CPU_DESCRIPTOR_HANDLE(D3D12_DEFAULT);
          return desc.ptr;
        }

Compile with:

        $ clang-cl /Ycprecomp.h precomp.cpp /c
        $ clang-cl /Yuprecomp.h a.cpp /c
        (yields assert above)

I'm synced at 8b60ba73af401ed5a57427eaa235f7d798c72fc9.
Clang was built with -DLLVM_ENABLE_ASSERTIONS=ON.

[1]
<a href="https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Libraries/D3DX12">https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Libraries/D3DX12</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>