Issue 140023
Summary ICE / LLVM oom after allocd[32] = '\2'; in C and C++ related to CodeGen
Labels new issue
Assignees
Reporter mariete1223
    In C++ it happens since clang 15 until trunk and in C since 3.0.0

## Assertion

No assertion given

## Stack dump

```
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -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 -x c++ -std=c++23 <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	<source>:2:13: Generating code for declaration 'allocd'
 #0 0x0000000003f98e38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f98e38)
 #1 0x0000000003f96ac4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f96ac4)
 #2 0x0000000003edb6f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007b2b24642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007b2b246969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007b2b24642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007b2b246287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003ee6efb (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ee6efb)
 #8 0x0000000003f15ead llvm::SmallVectorBase<unsigned long>::grow_pod(void*, unsigned long, unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f15ead)
 #9 0x000000000450bf3b clang::CodeGen::CodeGenModule::GetConstantArrayFromStringLiteral(clang::StringLiteral const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450bf3b)
#10 0x000000000434e03c clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ConstExprEmitter, llvm::Constant*, clang::QualType>::Visit(clang::Stmt const*, clang::QualType) CGExprConstant.cpp:0:0
#11 0x0000000004350313 clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4350313)
#12 0x0000000004350591 clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4350591)
#13 0x000000000453a4ce clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453a4ce)
#14 0x000000000455ef31 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455ef31)
#15 0x000000000456b797 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456b797)
#16 0x000000000456dd23 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456dd23)
#17 0x000000000494640e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#18 0x0000000004942825 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4942825)
#19 0x000000000662637c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x662637c)
#20 0x0000000004942fd8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4942fd8)
#21 0x0000000004c39725 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c39725)
#22 0x0000000004bb834e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bb834e)
#23 0x0000000004d2d289 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d2d289)
#24 0x0000000000daba2f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaba2f)
#25 0x0000000000da1bfa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x00000000049aa2c9 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
#27 0x0000000003edbb94 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3edbb94)
#28 0x00000000049aa8df 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
#29 0x000000000496c6ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x496c6ad)
#30 0x000000000496d73e 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+++0x496d73e)
#31 0x0000000004975a25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4975a25)
#32 0x0000000000da7998 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda7998)
#33 0x0000000000c2d064 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc2d064)
#34 0x00007b2b24629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007b2b24629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000da16a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda16a5)
```


## Program

```
#include <stdlib.h>
char static allocd[((size_t)-1) / 256] = "\1";
int main(void)
{
    free(malloc(0));
    allocd[32] = '\2';
}
```

To quickly reproduce:

https://godbolt.org/z/KbjTcdzKM
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to