#include <ptrcheck.h>
void sink(int *__counted_by(n) p, int n);
void f(void){
int n=3;
int *__counted_by(n) p=(int[3]){1,2,3};
sink(p,n);
}
We hit an assertion failure and I think it's because when we replace the initializer of p we drop the ExprWithCleanups that CompoundLiteralExprs now have as a parent due to llvm#219045
Assertion failed: (LifetimeExtendedCleanupStack.empty() && "mismatched push/pop of cleanups in EHStack!"), function FinishFunction, file CodeGenFunction.cpp, line 380.
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: bin/clang -fbounds-safety tmp/compound-literal-crash.c -c -o tmp/compound-literal-crash -O1
1. <eof> parser at end of file
2. tmp/compound-literal-crash.c:3:6: LLVM IR generation of declaration 'f'
3. tmp/compound-literal-crash.c:3:6: Generating code for declaration 'f'
#0 0x0000000106dca5ec llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104ada5ec)
#1 0x0000000106dc830c llvm::sys::RunSignalHandlers() (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104ad830c)
#2 0x0000000106dc9bc4 llvm::sys::CleanupOnSignal(unsigned long) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104ad9bc4)
#3 0x0000000106d123a4 CrashRecoverySignalHandler(int) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104a223a4)
#4 0x0000000193060144 (/usr/lib/system/libsystem_platform.dylib+0x180898144)
#5 0x000000019305597c (/usr/lib/system/libsystem_pthread.dylib+0x18088d97c)
#6 0x0000000192f58458 (/usr/lib/system/libsystem_c.dylib+0x180790458)
#7 0x0000000192f576a0 (/usr/lib/system/libsystem_c.dylib+0x18078f6a0)
#8 0x0000000106e42980 clang::CodeGen::CodeGenFunction::FinishFunction(clang::SourceLocation) (.cold.3) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104b52980)
#9 0x000000010305ac34 clang::CodeGen::CodeGenFunction::FinishFunction(clang::SourceLocation) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d6ac34)
#10 0x00000001030612b0 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d712b0)
#11 0x00000001030867d8 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d967d8)
#12 0x0000000103080418 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d90418)
#13 0x00000001030842b8 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d942b8)
#14 0x000000010307f140 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d8f140)
#15 0x0000000103104e58 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100e14e58)
#16 0x00000001030523fc clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100d623fc)
#17 0x0000000104a3f134 clang::ParseAST(clang::Sema&, bool, bool) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10274f134)
#18 0x000000010484bb98 clang::FrontendAction::Execute() (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10255bb98)
#19 0x00000001047e41c0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x1024f41c0)
#20 0x0000000102cc38e8 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x1009d38e8)
#21 0x00000001022f7f08 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100007f08)
#22 0x00000001022f3d30 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100003d30)
#23 0x00000001022f549c int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10000549c)
#24 0x000000010458cfb4 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10229cfb4)
#25 0x0000000106d120a0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x104a220a0)
#26 0x000000010458c858 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10229c858)
#27 0x000000010455cb54 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10226cb54)
#28 0x000000010455d10c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10226d10c)
#29 0x00000001045766ac clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x1022866ac)
#30 0x00000001022f3034 clang_main(int, char**, llvm::ToolContext const&) (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x100003034)
#31 0x000000010230c94c main (/Volumes/user_data/dev/llvm/upstream_swift/next/builds/RelWithDebInfo/bin/clang-23+0x10001c94c)
#32 0x0000000192c7fe80
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 24.0.0git (git@github.com:swiftlang/llvm-project.git c49162ef25adc71035d9229d2d5d1c200929f28e)
Ever since llvm#219045 merged into
nextclang has started crashing on example like this:We hit an assertion failure and I think it's because when we replace the initializer of
pwe drop theExprWithCleanupsthat CompoundLiteralExprs now have as a parent due to llvm#219045rdar://187817876