llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.13k stars 12.01k forks source link

clang frontend hangs when compiling for unknown-windows with the Itanium ABI #110380

Open amyspark opened 1 month ago

amyspark commented 1 month ago

Hi all,

The following MWE causes the Clang frontend to hang when compiling to x86_64-unknown-windows (e.g. for UEFI) but setting -fc++-abi=itanium.

namespace foo {
    struct bar{
        int a;
        int b;

        bar() {
            a = 1;
            b = 2;
        }
    };
}

int main() noexcept {
    foo::bar baz{};

    return 0;
}

Stacktrace looks like this:

[Inline Frame] clang.exe!llvm::Value::addUse(llvm::Use &) Line 505 (f:\Projects\llvm-project\llvm\include\llvm\IR\Value.h:505)
[Inline Frame] clang.exe!llvm::Use::set(llvm::Value *) Line 885 (f:\Projects\llvm-project\llvm\include\llvm\IR\Value.h:885)
clang.exe!llvm::Value::doRAUW(llvm::Value * New, llvm::Value::ReplaceMetadataUses ReplaceMetaUses) Line 527 (f:\Projects\llvm-project\llvm\lib\IR\Value.cpp:527)
clang.exe!clang::CodeGen::CodeGenModule::applyReplacements() Line 538 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenModule.cpp:538)
clang.exe!clang::CodeGen::CodeGenModule::Release() Line 860 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenModule.cpp:860)
clang.exe!`anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext & Ctx) Line 287 (f:\Projects\llvm-project\clang\lib\CodeGen\ModuleBuilder.cpp:287)
clang.exe!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 278 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:278)
clang.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 191 (f:\Projects\llvm-project\clang\lib\Parse\ParseAST.cpp:191)
clang.exe!clang::ASTFrontendAction::ExecuteAction() Line 1192 (f:\Projects\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1192)
clang.exe!clang::CodeGenAction::ExecuteAction() Line 1143 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:1143)
clang.exe!clang::FrontendAction::Execute() Line 1082 (f:\Projects\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1082)
clang.exe!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 1060 (f:\Projects\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:1060)
clang.exe!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 280 (f:\Projects\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:280)
clang.exe!cc1_main(llvm::ArrayRef<char const *> Argv, const char * Argv0, void * MainAddr) Line 285 (f:\Projects\llvm-project\clang\tools\driver\cc1_main.cpp:285)
clang.exe!ExecuteCC1Tool(llvm::SmallVectorImpl<char const *> & ArgV, const llvm::ToolContext & ToolContext) Line 217 (f:\Projects\llvm-project\clang\tools\driver\driver.cpp:217)
clang.exe!clang_main(int Argc, char * * Argv, const llvm::ToolContext & ToolContext) Line 258 (f:\Projects\llvm-project\clang\tools\driver\driver.cpp:258)
clang.exe!main(int argc, char * * argv) Line 17 (f:\Projects\llvm-project\build\tools\clang\tools\driver\clang-driver.cpp:17)
[Inline Frame] clang.exe!invoke_main() Line 78 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78)
clang.exe!__scrt_common_main_seh() Line 288 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
kernel32.dll!00007ffb129e7374() (Origen desconocido:0)

Clang version:

clang version 20.0.0git (https://github.com/llvm/llvm-project.git bbe79a803c84f4193c39566c9b0189ecadf5d8b4)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: F:\Projects\llvm-project\build\bin

Command line (CLI): clang --target=x86_64-unknown-windows -Xclang=-fc++-abi=itanium -x c++ foo.cpp -o foo.o

Command line (frontend) ``` clang.exe -cc1 -triple x86_64-unknown-windows-msvc19.42.34321 -emit-obj -mincremental-linker-compatible -dumpdir foo.o- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -fdebug-compilation-dir=F:\Projects\llvm-project\build\bin -fcoverage-compilation-dir=F:\Projects\llvm-project\build\bin -resource-dir lib\clang\20 -internal-isystem lib\clang\20\include -internal-isystem "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\include" -internal-isystem "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\atlmfc\include" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt" -O2 -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.42.34321 -std=c++14 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -fc++-abi=itanium -faddrsig -o C:\Users\Amalia\AppData\Local\Temp\test-07744d.o -x c++ test.cpp ```

cc @lethalbit

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-codegen

Author: Amyspark (amyspark)

Hi all, The following MWE causes the Clang frontend to hang when compiling to `x86_64-unknown-windows` (e.g. for UEFI) but setting `-fc++-abi=itanium`. ```c++ namespace foo { struct bar{ int a; int b; bar() { a = 1; b = 2; } }; } int main() noexcept { foo::bar baz{}; return 0; } ``` Stacktrace looks like this: ``` [Inline Frame] clang.exe!llvm::Value::addUse(llvm::Use &) Line 505 (f:\Projects\llvm-project\llvm\include\llvm\IR\Value.h:505) [Inline Frame] clang.exe!llvm::Use::set(llvm::Value *) Line 885 (f:\Projects\llvm-project\llvm\include\llvm\IR\Value.h:885) clang.exe!llvm::Value::doRAUW(llvm::Value * New, llvm::Value::ReplaceMetadataUses ReplaceMetaUses) Line 527 (f:\Projects\llvm-project\llvm\lib\IR\Value.cpp:527) clang.exe!clang::CodeGen::CodeGenModule::applyReplacements() Line 538 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenModule.cpp:538) clang.exe!clang::CodeGen::CodeGenModule::Release() Line 860 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenModule.cpp:860) clang.exe!`anonymous namespace'::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext & Ctx) Line 287 (f:\Projects\llvm-project\clang\lib\CodeGen\ModuleBuilder.cpp:287) clang.exe!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 278 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:278) clang.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 191 (f:\Projects\llvm-project\clang\lib\Parse\ParseAST.cpp:191) clang.exe!clang::ASTFrontendAction::ExecuteAction() Line 1192 (f:\Projects\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1192) clang.exe!clang::CodeGenAction::ExecuteAction() Line 1143 (f:\Projects\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:1143) clang.exe!clang::FrontendAction::Execute() Line 1082 (f:\Projects\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1082) clang.exe!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 1060 (f:\Projects\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:1060) clang.exe!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 280 (f:\Projects\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:280) clang.exe!cc1_main(llvm::ArrayRef<char const *> Argv, const char * Argv0, void * MainAddr) Line 285 (f:\Projects\llvm-project\clang\tools\driver\cc1_main.cpp:285) clang.exe!ExecuteCC1Tool(llvm::SmallVectorImpl<char const *> & ArgV, const llvm::ToolContext & ToolContext) Line 217 (f:\Projects\llvm-project\clang\tools\driver\driver.cpp:217) clang.exe!clang_main(int Argc, char * * Argv, const llvm::ToolContext & ToolContext) Line 258 (f:\Projects\llvm-project\clang\tools\driver\driver.cpp:258) clang.exe!main(int argc, char * * argv) Line 17 (f:\Projects\llvm-project\build\tools\clang\tools\driver\clang-driver.cpp:17) [Inline Frame] clang.exe!invoke_main() Line 78 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78) clang.exe!__scrt_common_main_seh() Line 288 (d:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) kernel32.dll!00007ffb129e7374() (Origen desconocido:0) ``` Clang version: ``` clang version 20.0.0git (https://github.com/llvm/llvm-project.git bbe79a803c84f4193c39566c9b0189ecadf5d8b4) Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: F:\Projects\llvm-project\build\bin ``` Command line (CLI): `clang --target=x86_64-unknown-windows -Xclang=-fc++-abi=itanium -x c++ foo.cpp -o foo.o` <details><summary>Command line (frontend)</summary> ``` clang.exe -cc1 -triple x86_64-unknown-windows-msvc19.42.34321 -emit-obj -mincremental-linker-compatible -dumpdir foo.o- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -fdebug-compilation-dir=F:\Projects\llvm-project\build\bin -fcoverage-compilation-dir=F:\Projects\llvm-project\build\bin -resource-dir lib\clang\20 -internal-isystem lib\clang\20\include -internal-isystem "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\include" -internal-isystem "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34321\atlmfc\include" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\winrt" -internal-isystem "C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\cppwinrt" -O2 -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.42.34321 -std=c++14 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -fc++-abi=itanium -faddrsig -o C:\Users\Amalia\AppData\Local\Temp\test-07744d.o -x c++ test.cpp ``` </details> cc @lethalbit