Issue 242211
Summary [Clang] Crash on passing to reference parameter where the referenced type is `(unsigned) _BitInt` of width larger than 128
Labels clang:codegen, crash-on-valid, regression:19
Assignees
Reporter frederick-vs-ja
    Clang is now crashing for the following example, which is somehow related to `std::complex` and an extension allowing using integer types as it's real type.

[Godbolt link](https://godbolt.org/z/j8hcYEYrf). Widths less than or equal to 128 are fine. It seems that Clang 18 used to accept it well.

```C++
template <class T>
struct ComplexLike {
 ComplexLike(const T& = T(), const T& = T()) {}
};

void test() {
 ComplexLike<_BitInt(129)>{};
  ComplexLike<_BitInt(256)>{};
 ComplexLike<_BitInt(257)>{};
  ComplexLike<_BitInt(512)>{};
 ComplexLike<_BitInt(513)>{};
  ComplexLike<_BitInt(1024)>{};
 ComplexLike<_BitInt(1025)>{};
  ComplexLike<unsigned _BitInt(129)>{};
 ComplexLike<unsigned _BitInt(256)>{};
  ComplexLike<unsigned _BitInt(257)>{};
  ComplexLike<unsigned _BitInt(512)>{};
 ComplexLike<unsigned _BitInt(513)>{};
  ComplexLike<unsigned _BitInt(1024)>{};
  ComplexLike<unsigned _BitInt(1025)>{};
}
```

```
clang++: /root/llvm-project/llvm/lib/IR/Constants.cpp:2427: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
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.	<source>:6:6: LLVM IR generation of declaration 'test'
3.	<source>:6:6: Generating code for declaration 'test'
 #0 0x0000000004f4f778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4f778)
 #1 0x0000000004f4c9d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4c9d4)
 #2 0x0000000004f4d00c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f4d00c)
 #3 0x0000000004e86d28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x00007b7302a45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x00007b7302a9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
 #6 0x00007b7302a4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x00007b7302a288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x00007b7302a2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #9 0x00007b7302a3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000046e16b3 llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46e16b3)
#11 0x0000000003d10dfc llvm::ConstantFoldCastOperand(unsigned int, llvm::Constant*, llvm::Type*, llvm::DataLayout const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d10dfc)
#12 0x000000000540eb64 clang::CodeGen::CodeGenFunction::EmitFromMemory(llvm::Value*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x540eb64)
#13 0x00000000054ad4f9 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#14 0x00000000054b2a4c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54b2a4c)
#15 0x0000000005427395 clang::CodeGen::CodeGenFunction::EmitAnyExprToMem(clang::Expr const*, clang::CodeGen::Address, clang::Qualifiers, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5427395)
#16 0x0000000005445491 clang::CodeGen::CodeGenFunction::EmitMaterializeTemporaryExpr(clang::MaterializeTemporaryExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5445491)
#17 0x0000000005449c44 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5449c44)
#18 0x000000000544a5c7 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#19 0x000000000ab955b1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xab955b1)
#20 0x000000000540d9dc clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x540d9dc)
#21 0x0000000005449ce1 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5449ce1)
#22 0x000000000544a5c7 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#23 0x000000000ab955b1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xab955b1)
#24 0x000000000540d9dc clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x540d9dc)
#25 0x0000000005437395 clang::CodeGen::CodeGenFunction::EmitReferenceBindingToExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5437395)
#26 0x000000000594715a clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, clang::Expr const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x594715a)
#27 0x0000000005961328 clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, clang::CodeGen::CodeGenFunction::PrototypeWrapper, llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>>, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGenUtils::EvaluationOrder) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5961328)
#28 0x000000000597eef7 clang::CodeGen::CodeGenFunction::EmitCXXConstructorCall(clang::CXXConstructorDecl const*, clang::CXXCtorType, bool, bool, clang::CodeGen::AggValueSlot, clang::CXXConstructExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x597eef7)
#29 0x0000000005469252 clang::CodeGen::CodeGenFunction::EmitCXXConstructExpr(clang::CXXConstructExpr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5469252)
#30 0x000000000544c008 (anonymous namespace)::AggExprEmitter::VisitCXXConstructExpr(clang::CXXConstructExpr const*) CGExprAgg.cpp:0:0
#31 0x0000000005458e71 (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#32 0x0000000005458fe8 (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#33 0x000000000545a08c clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x545a08c)
#34 0x000000000541f71a clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x541f71a)
#35 0x00000000054433dd clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54433dd)
#36 0x00000000055df11d clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x55df11d)
#37 0x00000000055e76ab clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x55e76ab)
#38 0x0000000005653696 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5653696)
#39 0x0000000005664e8c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5664e8c)
#40 0x00000000056d4f4a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x56d4f4a)
#41 0x00000000056ce5c5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x56ce5c5)
#42 0x00000000056cef43 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x56cef43)
#43 0x00000000056dc4f1 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#44 0x0000000005a53349 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#45 0x0000000005a47214 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5a47214)
#46 0x0000000009008a94 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x9008a94)
#47 0x0000000005a4fd58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5a4fd58)
#48 0x0000000005d7a7c8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d7a7c8)
#49 0x0000000005d0737d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d0737d)
#50 0x0000000005e51043 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e51043)
#51 0x0000000001717968 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1717968)
#52 0x000000000170e86a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#53 0x000000000170e9f3 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
#54 0x0000000005ac9539 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
#55 0x0000000004e87124 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e87124)
#56 0x0000000005aca0a5 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
#57 0x0000000005a86ec2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5a86ec2)
#58 0x0000000005a8a17c 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+++0x5a8a17c)
#59 0x0000000005a96675 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5a96675)
#60 0x0000000001713fba clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1713fba)
#61 0x000000000169a073 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x169a073)
#62 0x00007b7302a2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#63 0x00007b7302a2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#64 0x000000000170e215 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x170e215)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to