llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] CGDebugInfo.cpp crash when enabling -gtemplate-alias option ("Dependent types cannot show up in debug information")

Open MaggieYingYi opened this issue 7 months ago • 4 comments

The -gtemplate-alias option instructs Clang to emit DW_TAG_template_alias instead of DW_TAG_typedef for template aliases.

However, the following code causes Clang to crash when -gtemplate-alias is enabled.

This issue has been present since Clang 21.0.0 for x86-64 (from commit: https://github.com/llvm/llvm-project/commit/366f48890d64) and remains reproducible on the current trunk.

$ cat test.cpp
struct a {};
template <typename> using b = a;
template <typename c> struct d : b<c> {};
d<int> e;

Compile the code using:

$ clang.exe -c -O2 -gtemplate-alias test.cpp -o test.o

Stack Dump:

Dependent types cannot show up in debug information
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp:4241!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -gtemplate-alias <source>
1.	<eof> parser at end of file
2.	<source>:4:8: LLVM IR generation of declaration 'e'
3.	<source>:4:8: Generating code for declaration 'e'
 #0 0x0000000004524768 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4524768)
 #1 0x0000000004521594 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521594)
 #2 0x0000000004521bb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521bb4)
 #3 0x000000000445f338 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 :

Clang crash started since Clang 21.0.0. Clang 20.0.0 works fine. Compiler Explorer: https://godbolt.org/z/3hYMhh7rM

MaggieYingYi avatar Apr 24 '26 10:04 MaggieYingYi

@llvm/issue-subscribers-clang-frontend

Author: Ying Yi (MaggieYingYi)

The -gtemplate-alias option instructs Clang to emit DW_TAG_template_alias instead of DW_TAG_typedef for template aliases.

However, the following code causes Clang to crash when -gtemplate-alias is enabled.

This issue has been present since Clang 21.0.0 for x86-64 (from commit: https://github.com/llvm/llvm-project/commit/366f48890d64) and remains reproducible on the current trunk.

$ cat test.cpp
struct a {};
template &lt;typename&gt; using b = a;
template &lt;typename c&gt; struct d : b&lt;c&gt; {};
d&lt;int&gt; e;

Compile the code using:

$ clang.exe -c -O2 -gtemplate-alias test.cpp -o test.o

Stack Dump:

Dependent types cannot show up in debug information
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp:4241!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -gtemplate-alias &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
2.	&lt;source&gt;:4:8: LLVM IR generation of declaration 'e'
3.	&lt;source&gt;:4:8: Generating code for declaration 'e'
 #<!-- -->0 0x0000000004524768 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4524768)
 #<!-- -->1 0x0000000004521594 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521594)
 #<!-- -->2 0x0000000004521bb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521bb4)
 #<!-- -->3 0x000000000445f338 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 :

Clang crash started since Clang 21.0.0. Clang 20.0.0 works fine. Compiler Explorer: https://godbolt.org/z/3hYMhh7rM

llvmbot avatar Apr 24 '26 10:04 llvmbot

@llvm/issue-subscribers-debuginfo

Author: Ying Yi (MaggieYingYi)

The -gtemplate-alias option instructs Clang to emit DW_TAG_template_alias instead of DW_TAG_typedef for template aliases.

However, the following code causes Clang to crash when -gtemplate-alias is enabled.

This issue has been present since Clang 21.0.0 for x86-64 (from commit: https://github.com/llvm/llvm-project/commit/366f48890d64) and remains reproducible on the current trunk.

$ cat test.cpp
struct a {};
template &lt;typename&gt; using b = a;
template &lt;typename c&gt; struct d : b&lt;c&gt; {};
d&lt;int&gt; e;

Compile the code using:

$ clang.exe -c -O2 -gtemplate-alias test.cpp -o test.o

Stack Dump:

Dependent types cannot show up in debug information
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp:4241!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -gtemplate-alias &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
2.	&lt;source&gt;:4:8: LLVM IR generation of declaration 'e'
3.	&lt;source&gt;:4:8: Generating code for declaration 'e'
 #<!-- -->0 0x0000000004524768 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4524768)
 #<!-- -->1 0x0000000004521594 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521594)
 #<!-- -->2 0x0000000004521bb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521bb4)
 #<!-- -->3 0x000000000445f338 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 :

Clang crash started since Clang 21.0.0. Clang 20.0.0 works fine. Compiler Explorer: https://godbolt.org/z/3hYMhh7rM

llvmbot avatar Apr 24 '26 10:04 llvmbot

@llvm/issue-subscribers-clang-codegen

Author: Ying Yi (MaggieYingYi)

The -gtemplate-alias option instructs Clang to emit DW_TAG_template_alias instead of DW_TAG_typedef for template aliases.

However, the following code causes Clang to crash when -gtemplate-alias is enabled.

This issue has been present since Clang 21.0.0 for x86-64 (from commit: https://github.com/llvm/llvm-project/commit/366f48890d64) and remains reproducible on the current trunk.

$ cat test.cpp
struct a {};
template &lt;typename&gt; using b = a;
template &lt;typename c&gt; struct d : b&lt;c&gt; {};
d&lt;int&gt; e;

Compile the code using:

$ clang.exe -c -O2 -gtemplate-alias test.cpp -o test.o

Stack Dump:

Dependent types cannot show up in debug information
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp:4241!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -gtemplate-alias &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
2.	&lt;source&gt;:4:8: LLVM IR generation of declaration 'e'
3.	&lt;source&gt;:4:8: Generating code for declaration 'e'
 #<!-- -->0 0x0000000004524768 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4524768)
 #<!-- -->1 0x0000000004521594 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521594)
 #<!-- -->2 0x0000000004521bb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4521bb4)
 #<!-- -->3 0x000000000445f338 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 :

Clang crash started since Clang 21.0.0. Clang 20.0.0 works fine. Compiler Explorer: https://godbolt.org/z/3hYMhh7rM

llvmbot avatar Apr 24 '26 10:04 llvmbot

CC @mizvekov We used to skip CreateType for isInstantiationDependentType types until https://github.com/llvm/llvm-project/commit/366f48890d64

Michael137 avatar Apr 24 '26 11:04 Michael137