Skip to content

"Declaration may not be in a Comdat" when using D3DX12 headers and PCH files #44298

@llvmbot

Description

@llvmbot
Bugzilla Link 44953
Resolution FIXED
Resolved on Feb 27, 2020 05:44
Version trunk
OS Windows NT
Blocks #43900
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zmodem,@llunak,@zygoloid,@rnk

Extended Description

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
 #&#8203;0 0x00007ffa8b5ba839 (C:\WINDOWS\System32\KERNELBASE.dll+0x3a839)
 #&#8203;1 0x00007ff7690e5dda llvm::CrashRecoveryContext::HandleExit(int) F:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:436:0
 #&#8203;2 0x00007ff769129484 llvm::sys::Process::Exit(int) F:\llvm-project\llvm\lib\Support\Process.cpp:95:0
 #&#8203;3 0x00007ff7688982c9 LLVMErrorHandler F:\llvm-project\clang\tools\driver\cc1_main.cpp:73:0
 #&#8203;4 0x00007ff7690e60ea llvm::report_fatal_error(class llvm::Twine const &, bool) F:\llvm-project\llvm\lib\Support\ErrorHandling.cpp:108:0
 #&#8203;5 0x00007ff7690e6001 llvm::report_fatal_error(char const *, bool) F:\llvm-project\llvm\lib\Support\ErrorHandling.cpp:83:0
 #&#8203;6 0x00007ff769f2ff38 `anonymous namespace'::VerifierLegacyPass::doFinalization F:\llvm-project\llvm\lib\IR\Verifier.cpp:5189:0
 #&#8203;7 0x00007ff768cda3af llvm::FPPassManager::doFinalization(class llvm::Module &) F:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1536:0
 #&#8203;8 0x00007ff768cd96e0 llvm::legacy::FunctionPassManagerImpl::doFinalization(class llvm::Module &) F:\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1382:0
 #&#8203;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
llvm/llvm-project#382 0x00007ff76a75a4c6 clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) F:\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:339:0
llvm/llvm-project#383 0x00007ff76c175c43 clang::ParseAST(class clang::Sema &, bool, bool) F:\llvm-project\clang\lib\Parse\ParseAST.cpp:178:0
llvm/llvm-project#384 0x00007ff76a6b2edd clang::FrontendAction::Execute(void) F:\llvm-project\clang\lib\Frontend\FrontendAction.cpp:944:0
llvm/llvm-project#385 0x00007ff76924e70b clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) F:\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:969:0
llvm/llvm-project#386 0x00007ff7692b405d clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) F:\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:292:0
llvm/llvm-project#387 0x00007ff768897eda cc1_main(class llvm::ArrayRef<char const *>, char const *, void *) F:\llvm-project\clang\tools\driver\cc1_main.cpp:240:0
llvm/llvm-project#388 0x00007ff768894f03 ExecuteCC1Tool F:\llvm-project\clang\tools\driver\driver.cpp:328:0
llvm/llvm-project#389 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
llvm/llvm-project#390 0x00007ff7690e5c02 llvm::CrashRecoveryContext::RunSafely(class llvm::function_ref<(void)>) F:\llvm-project\llvm\lib\Support\CrashRecoveryContext.cpp:228:0
llvm/llvm-project#391 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
llvm/llvm-project#392 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
llvm/llvm-project#393 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
llvm/llvm-project#394 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
llvm/llvm-project#395 0x00007ff76889447e main F:\llvm-project\clang\tools\driver\driver.cpp:496:0
llvm/llvm-project#396 0x00007ff76d477bd0 __scrt_common_main_seh d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
llvm/llvm-project#397 0x00007ffa8c407bd4 (C:\WINDOWS\System32\KERNEL32.DLL+0x17bd4)
llvm/llvm-project#398 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 8b60ba7.
Clang was built with -DLLVM_ENABLE_ASSERTIONS=ON.

[1] https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Libraries/D3DX12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++11

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions