Issue 242767
Summary [Clang][CodeGen] Crash on defaulted copy assignment operator with explicit object parameter
Labels clang
Assignees
Reporter SekaiArendelle
    Clang crashes on valid code when generating the body of a defaulted copy assignment operator declared with an explicit object parameter (`this W&`). The same code without the explicit object parameter compiles fine.

Reproducer:

```cpp
struct W {
    int a{};
    int b{};
 constexpr auto operator=(this W& self, W const& o) noexcept -> W& = default;
};

int main() {
    W x{};
    W y{};
    x = y;
}
```

Compiler Explorer link: https://godbolt.org/z/qhzEM6n5j

Command:

```
clang++ -std=c++23 repro.cpp
```

Result: the frontend crashes during code generation:

```
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: /cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/lib/clang/24 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/backward -internal-isystem /cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/lib/clang/24/include -internal-isystem /cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/../include/x86_64-unknown-linux-gnu -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -fdwarf2-cfi-asm -o /tmp/example-0d09f7.o -x c++ <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	<source>:4:20: Generating code for declaration 'W::operator='
 #0 0x0000000004852cf8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4852cf8)
 #1 0x000000000485013d SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000000004850238 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x000076c6bfe45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x000000000386de3c llvm::TargetFolder::FoldGEP(llvm::DataLayout const&, llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::GEPNoWrapFlags) const (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x386de3c)
 #5 0x000000000412d601 llvm::IRBuilderBase::CreateGEP(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::GEPNoWrapFlags) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x412d601)
 #6 0x0000000004c699fb emitAddrOfFieldStorage(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::FieldDecl const*, bool) CGExpr.cpp:0:0
 #7 0x0000000004c6abde clang::CodeGen::CodeGenFunction::EmitLValueForField(clang::CodeGen::LValue, clang::FieldDecl const*, bool) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4c6abde)
 #8 0x0000000004c6ccb8 clang::CodeGen::CodeGenFunction::EmitLValueForFieldInitialization(clang::CodeGen::LValue, clang::FieldDecl const*) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4c6ccb8)
 #9 0x000000000515817a (anonymous namespace)::FieldMemcpyizer::emitMemcpy() CGClass.cpp:0:0
#10 0x000000000515a09f clang::CodeGen::CodeGenFunction::emitImplicitAssignmentOperatorBody(clang::CodeGen::FunctionArgList&) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x515a09f)
#11 0x0000000004e83291 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4e83291)
#12 0x0000000004edf9ea clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4edf9ea)
#13 0x0000000004ed93e3 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4ed93e3)
#14 0x0000000004ee754a clang::CodeGen::CodeGenModule::EmitDeferred() (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4ee754a)
#15 0x0000000004eea8d3 clang::CodeGen::CodeGenModule::Release() (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x4eea8d3)
#16 0x00000000052230de (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#17 0x000000000521fc2d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x521fc2d)
#18 0x0000000008352e1c clang::ParseAST(clang::Sema&, bool, bool) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x8352e1c)
#19 0x0000000005220ce5 clang::CodeGenAction::ExecuteAction() (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x5220ce5)
#20 0x0000000005553361 clang::FrontendAction::Execute() (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x5553361)
#21 0x00000000054e4dd5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x54e4dd5)
#22 0x0000000005628bbb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x5628bbb)
#23 0x000000000178a898 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x178a898)
#24 0x000000000178282b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#25 0x000000000178582c clang_main(int, char**, llvm::ToolContext const&) (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x178582c)
#26 0x0000000001715773 main (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x1715773)
#27 0x000076c6bfe2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#28 0x000076c6bfe2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#29 0x00000000017822d5 _start (/cefs/11/117707d19b8a1f0b137a7b22_clang-trunk-20261114/bin/clang-24+0x17822d5)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed with exit code -2 (use -v to see invocation)
Program terminated with signal SIGABRT (6)
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to