[clang] [clang] fix transformation of subst constant template parameter nodes (PR #161029)

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 7 00:02:00 PDT 2025


alexfh wrote:

@mizvekov now a better test case, which compiles before this commit: https://gcc.godbolt.org/z/qhaTEEr3P

```
template <class... _Args> constexpr void __invoke(_Args... __args) {
  __builtin_invoke(__args...);
}
template <template <class> class _BaseType, class _Tp, _Tp _SequenceSize>
using __make_integer_sequence_impl =
    __make_integer_seq<_BaseType, _Tp, _SequenceSize>;
template <class _Tp, _Tp...> struct integer_sequence {};
template <decltype(sizeof(int))... _Ip>
using index_sequence = integer_sequence<decltype(sizeof(int)), _Ip...>;
template <class _Tp, _Tp _Ep>
using make_integer_sequence =
    __make_integer_sequence_impl<integer_sequence, _Tp, _Ep>;
template <decltype(sizeof(int)) _Np>
using make_index_sequence = make_integer_sequence<decltype(sizeof(int)), _Np>;
enum { _TriviallyAvailable };
template <typename> struct __traits;
auto __make_farray(...) {}
struct __dispatcher {
  template <class _Fp, class... _Vs> static auto __dispatch(_Vs... __vs) {
    _Fp __f;
    __invoke(__f, __vs...);
  }
};
template <class _Fp, class... _Vs> auto __make_dispatch() {
  return __dispatcher::__dispatch<_Fp, _Vs...>;
}
struct Trans_NS___visitation___base {
  template <class _Visitor, class... _Vs>
  static void __visit_alt(_Visitor, _Vs... __vs) {
    __make_fmatrix<_Visitor, decltype(__vs)...>();
  }
  template <class _Fp, class... _Vs, decltype(sizeof(int))... _Is>
  static auto __make_fmatrix_impl(index_sequence<_Is...>) {
    return __make_dispatch<_Fp, _Vs...>;
  }
  template <class _Fp, class, decltype(sizeof(int))... _Js>
  static void __make_fmatrix_impl(index_sequence<>, index_sequence<_Js...>) {
    __make_farray(__make_fmatrix_impl<_Fp, int>(index_sequence<_Js>{})...);
  }
  template <class _Fp, class... _Vs> static void __make_fmatrix() {
    __make_fmatrix_impl<_Fp, _Vs...>({},
                                     make_index_sequence<_Vs::__size()>{}...);
  }
};
template <class _Visitor, class... _Vs>
void __visit_alt(_Visitor __visitor, _Vs... __vs) {
  Trans_NS___visitation___base::__visit_alt(__visitor, __vs.__impl_...);
}
struct __variant {
  template <class _Visitor, class... _Vs>
  static void __visit_value(_Visitor __visitor, _Vs... __vs) {
    __visit_alt(__visitor, __vs...);
  }
};
struct __ctor {
  static constexpr decltype(sizeof(int)) __size() { return sizeof(int); }
};
template <class _Visitor, class... _Vs>
void visit(_Visitor __visitor, _Vs... __vs) {
  __variant::__visit_value(__visitor, __vs...);
}
struct variant {
  __ctor __impl_;
};
template <int, typename T, T...> struct ElementAt;
template <typename T, T First, T... Items>
struct ElementAt<0, T, First, Items...> {
  static int value;
};
template <typename T, T... Items> struct TagSet {
  template <int Index> using Tag = ElementAt<Index, T, Items...>;
};
template <typename TagSet> struct S {
  void U() {
    (void)TagSet::template Tag<0>::value;
  }
};
enum E { k };
S<TagSet<E, k>> s;
void h() {
  variant v;
  visit(
      [](auto) -> int {
        s.U();
        return 0;
      },
      v);
}
```

```
<source>:75:11: error: cannot compile this l-value expression yet
   75 |     (void)TagSet::template Tag<0>::value;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected placeholder builtin type!
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CodeGenTypes.cpp:594!
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 -std=c++20 <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	<source>:74:8: Generating code for declaration 'S<TagSet<E, k>>::U'
 #0 0x00000000041d20a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41d20a8)
 #1 0x00000000041cf4d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41cf4d4)
 #2 0x0000000004113668 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007b0b26842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007b0b268969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007b0b26842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007b0b268287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000000000411ed3a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x411ed3a)
 #8 0x00000000047fcf90 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47fcf90)
 #9 0x000000000450fb60 clang::CodeGen::CodeGenFunction::EmitUnsupportedLValue(clang::Expr const*, char const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450fb60)
#10 0x0000000004546485 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4546485)
#11 0x0000000004547007 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#12 0x000000000818b181 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x818b181)
#13 0x000000000450fea3 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450fea3)
#14 0x000000000453f54b clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453f54b)
#15 0x00000000045aec5f (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#16 0x00000000045a61a8 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#17 0x00000000045aa96c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45aa96c)
#18 0x000000000450eb2e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450eb2e)
#19 0x000000000453f5bd clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453f5bd)
#20 0x00000000046beef7 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46beef7)
#21 0x00000000046c718c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46c718c)
#22 0x000000000472f7de clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x472f7de)
#23 0x0000000004741784 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4741784)
#24 0x00000000047ae3e0 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47ae3e0)
#25 0x00000000047a9294 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47a9294)
#26 0x00000000047b615c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b615c)
#27 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#28 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#29 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#30 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#31 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#32 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#33 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#34 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#35 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#36 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#37 0x00000000047b6078 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b6078)
#38 0x00000000047b8803 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b8803)
#39 0x0000000004b17f3e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#40 0x0000000004b13f45 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b13f45)
#41 0x00000000068a504c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68a504c)
#42 0x0000000004b14728 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b14728)
#43 0x0000000004e00195 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e00195)
#44 0x0000000004d81dee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d81dee)
#45 0x0000000004ef748d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ef748d)
#46 0x0000000000dbc110 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbc110)
#47 0x0000000000db2c7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#48 0x0000000000db2dfd int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#49 0x0000000004b7d8d9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#50 0x0000000004113b04 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4113b04)
#51 0x0000000004b7deef clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#52 0x0000000004b3f1f2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b3f1f2)
#53 0x0000000004b4019e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b4019e)
#54 0x0000000004b478d5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b478d5)
#55 0x0000000000db8639 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb8639)
#56 0x0000000000c6a194 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc6a194)
#57 0x00007b0b26829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#58 0x00007b0b26829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#59 0x0000000000db2715 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb2715)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

https://github.com/llvm/llvm-project/pull/161029


More information about the cfe-commits mailing list