Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang codegen ICE: Emitted constant has unexpected size with large static array size and small initializer #61666

Open
langston-barrett opened this issue Mar 23, 2023 · 2 comments
Labels
clang:codegen confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@langston-barrett
Copy link
Contributor

langston-barrett commented Mar 23, 2023

This bug was found with a fuzzer; please feel free to close if it's not helpful.

// https://godbolt.org/z/cqxxvhhYq
char buffer[1196209283887] = "%";
clang++: /root/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4936: void clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(const clang::VarDecl*, bool): Assertion `VarSize == CstSize && "Emitted constant has unexpected size"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -c -O0 -emit-llvm -Xclang -disable-llvm-passes <source>
1.	<eof> parser at end of file
2.	<source>:1:6: LLVM IR generation of declaration 'buffer'
3.	<source>:1:6: Generating code for declaration 'buffer'
 #0 0x0000557c6b9e307f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401107f)
 #1 0x0000557c6b9e0dbc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x400edbc)
 #2 0x0000557c6b92e428 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f088f1b5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f088ec8200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f088ec61859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f088ec61729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f088ec72fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000557c6bdb6eb6 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43e4eb6)
 #9 0x0000557c6bdd98a1 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44078a1)
#10 0x0000557c6bdda508 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4408508)
#11 0x0000557c6bde3354 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#12 0x0000557c6cc0de49 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#13 0x0000557c6cbffc70 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x522dc70)
#14 0x0000557c6e0c7fa4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f5fa4)
#15 0x0000557c6cc0ac48 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5238c48)
#16 0x0000557c6c46fcb9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a9dcb9)
#17 0x0000557c6c3f41e6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a221e6)
#18 0x0000557c6c553e77 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b81e77)
#19 0x0000557c68f6a4c6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15984c6)
#20 0x0000557c68f662ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000557c6c254cdd 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
#22 0x0000557c6b92e910 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f5c910)
#23 0x0000557c6c25559f 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
#24 0x0000557c6c21cddc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x484addc)
#25 0x0000557c6c21d87d 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+++0x484b87d)
#26 0x0000557c6c22552d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x485352d)
#27 0x0000557c68f68970 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1596970)
#28 0x0000557c68e744d5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x14a24d5)
#29 0x00007f088ec63083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#30 0x0000557c68f60ffe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x158effe)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

This is possibly a duplicate of #39290, though this program doesn't use an initializer list. Here's how I searched for duplicates: https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+label%3Aclang%3Acodegen+constant+has+unexpected+size

@EugeneZelenko EugeneZelenko added llvm:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Mar 23, 2023
@shafik
Copy link
Collaborator

shafik commented Mar 24, 2023

We have a bunch of bugs related to this: #61187

@shafik shafik added the confirmed Verified by a second party label Mar 24, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2023

@llvm/issue-subscribers-clang-codegen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants