Skip to content

Clang crashes when using an explicit object parameter in lambda with specific function body #135005

Open
@misos1

Description

@misos1
# 1 "a.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 468 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "a.cpp" 2
int main()
{
 int a[1] = {0};
 auto f = [&](this const auto &self) -> void
 {
  for(int i = a[0]; i < 1; i++)
  {
   a[0] = i;
  }
 };
 f();
}
# Crash reproducer for Ubuntu clang version 18.1.3 (1ubuntu1)
# Driver args: "--driver-mode=g++" "-std=c++23" "a.cpp"
# Original command:  "/usr/lib/llvm-18/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "a.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home" "-fcoverage-compilation-dir=/home" "-resource-dir" "/usr/lib/llvm-18/lib/clang/18" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward" "-internal-isystem" "/usr/lib/llvm-18/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/a-103ced.o" "-x" "c++" "a.cpp"
 "/usr/lib/llvm-18/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "a.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home" "-fcoverage-compilation-dir=/home" "-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" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "a-25c870.cpp"
Stack dump
Stack dump:
0.	Program arguments: /usr/lib/llvm-18/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name a.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home -fcoverage-compilation-dir=/home -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/a-103ced.o -x c++ a.cpp
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	a.cpp:4:11: Generating code for declaration 'main()::(anonymous class)::operator()'
4.	a.cpp:7:3: LLVM IR generation of compound statement ('{}')
 #0 0x00007ed0fc9a63bf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00007ed0fc9a44f9 llvm::sys::RunSignalHandlers() build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00007ed0fc9a6b00 SignalHandler build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007ed0fb445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x00007ed1053cbcc7 getTypePtr build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Type.h:6833:26
 #5 0x00007ed1053cbcc7 operator-> build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Type.h:797:12
 #6 0x00007ed1053cbcc7 clang::CodeGen::CodeGenModule::getNaturalTypeAlignment(clang::QualType, clang::CodeGen::LValueBaseInfo*, clang::CodeGen::TBAAAccessInfo*, bool) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:7494:17
 #7 0x00007ed1051ffba4 EmitPointerWithAlignment build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExpr.cpp:1387:15
 #8 0x00007ed1052018d7 clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExpr.cpp:4297:10
 #9 0x00007ed10520245a clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExpr.cpp:0:12
#10 0x00007ed1052004d5 getStmtClass build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Stmt.h:1357:44
#11 0x00007ed1052004d5 classof build-llvm/tools/clang/stage2-bins/clang/include/clang/AST/Expr.h:1469:15
#12 0x00007ed1052004d5 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:64:53
#13 0x00007ed1052004d5 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:110:12
#14 0x00007ed1052004d5 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:137:12
#15 0x00007ed1052004d5 doit build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:127:12
#16 0x00007ed1052004d5 isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:255:12
#17 0x00007ed1052004d5 isPossible build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:509:12
#18 0x00007ed1052004d5 isa<clang::DeclRefExpr, const clang::Expr *> build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Casting.h:549:10
#19 0x00007ed1052004d5 clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExpr.cpp:1481:8
#20 0x00007ed105251d23 VisitBinAssign build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExprScalar.cpp:4506:9
#21 0x00007ed105246c01 Visit build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExprScalar.cpp:407:52
#22 0x00007ed105246c01 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExprScalar.cpp:5161:8
#23 0x00007ed1051f52b5 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGExpr.cpp:205:1
#24 0x00007ed10534a151 GetInsertBlock build-llvm/tools/clang/stage2-bins/llvm/include/llvm/IR/IRBuilder.h:174:47
#25 0x00007ed10534a151 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:126:42
#26 0x00007ed10534a9d1 EmitCompoundStmtWithoutScope build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:507:22
#27 0x00007ed10534a9d1 EmitCompoundStmt build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:493:10
#28 0x00007ed10534a9d1 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:449:5
#29 0x00007ed10534a073 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:61:7
#30 0x00007ed10534d0b5 ForceCleanup build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.h:928:28
#31 0x00007ed10534d0b5 ~RunCleanupsScope build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.h:912:9
#32 0x00007ed10534d0b5 clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:1138:3
#33 0x00007ed10534a6e7 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:0:32
#34 0x00007ed10535578c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CGStmt.cpp:507:22
#35 0x00007ed1053ae544 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.cpp:0:5
#36 0x00007ed1053af05c getLangOpts build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.h:2058:51
#37 0x00007ed1053af05c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.cpp:1490:7
#38 0x00007ed1053d0bee clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:5834:3
#39 0x00007ed1053ca0fe clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:0:9
#40 0x00007ed1053bce53 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
#41 0x00007ed1053bce53 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:884:16
#42 0x00007ed1053bce53 empty /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:1089:16
#43 0x00007ed1053bce53 clang::CodeGen::CodeGenModule::EmitDeferred() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:3192:26
#44 0x00007ed1053ba9ed empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:98:61
#45 0x00007ed1053ba9ed begin build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/DenseMap.h:78:9
#46 0x00007ed1053ba9ed clang::CodeGen::CodeGenModule::Release() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenModule.cpp:807:45
#47 0x00007ed105469d0c HandleTranslationUnit build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/ModuleBuilder.cpp:291:11
#48 0x00007ed10539f4e7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenAction.cpp:306:9
#49 0x00007ed103f973d6 __normal_iterator /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_iterator.h:1077:20
#50 0x00007ed103f973d6 begin /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:874:16
#51 0x00007ed103f973d6 finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> >, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> > > > > build-llvm/tools/clang/stage2-bins/clang/include/clang/Sema/TemplateInstCallback.h:54:16
#52 0x00007ed103f973d6 clang::ParseAST(clang::Sema&, bool, bool) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseAST.cpp:183:3
#53 0x00007ed105e0662c clang::FrontendAction::Execute() build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/FrontendAction.cpp:1073:10
#54 0x00007ed105d830b4 getPtr build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:279:12
#55 0x00007ed105d830b4 operator bool build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:239:16
#56 0x00007ed105d830b4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/CompilerInstance.cpp:1057:23
#57 0x00007ed105e8263d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) build-llvm/tools/clang/stage2-bins/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#58 0x00005955d08c742e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) build-llvm/tools/clang/stage2-bins/clang/tools/driver/cc1_main.cpp:294:15
#59 0x00005955d08c4894 ExecuteCC1Tool build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:365:12
#60 0x00005955d08c3a26 clang_main(int, char**, llvm::ToolContext const&) build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:405:12
#61 0x00005955d08d1383 main build-llvm/tools/clang/stage2-bins/build-llvm/tools/clang/stage2-bins/tools/clang/tools/driver/clang-driver.cpp:17:10
#62 0x00007ed0fb42a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#63 0x00007ed0fb42a28b call_init ./csu/../csu/libc-start.c:128:20
#64 0x00007ed0fb42a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#65 0x00005955d08c1255 _start (/usr/lib/llvm-18/bin/clang+0xe255)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions