llvm / llvm/llvm-project

crash when const attribute is applied to variadic snprintf

Open
#214,409 2 comments 0 reactions 0 assignees View on GitHub
confirmed crash-on-valid regression:23
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/jKeoqrE46
```cpp
int __attribute__((const)) snprintf(char *, __SIZE_TYPE__, const char *, ...);

long foo(char c, long d) { return snprintf(&c, d, ""); }
```

Backtrace:
```console
Attributes 'readnone and writeonly' are incompatible!
ptr @snprintf
Attributes 'readnone and readonly' are incompatible!
ptr @snprintf
fatal error: error in backend: Broken module found, compilation aborted!
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -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 -O1
1. parser at end of file
2. Code generation
#0 0x0000000004423f28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4423f28)
#1 0x0000000004420dd4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4420dd4)
#2 0x000000000442140c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442140c)
#3 0x00000000043608c6 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43608c6)
#4 0x000000000441897e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441897e)
#5 0x0000000000da8c10 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
#6 0x000000000436a343 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436a343)
#7 0x000000000436a4a1 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436a4a1)
#8 0x0000000003dbb17d (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3dbb17d)
#9 0x0000000003cf6aed llvm::FPPassManager::doFinalization(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cf6aed)
#10 0x0000000003d03a61 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d03a61)
#11 0x0000000004841f58 (anonymous namespace)::EmitAssemblyHelper::TimeCodegenPasses(llvm::function_ref) (.isra.0) BackendUtil.cpp:0:0
#12 0x0000000004850fab (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#13 0x0000000004851493 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4851493)
#14 0x0000000004f24abc clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f24abc)
#15 0x0000000006d316bd clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d316bd)
#16 0x0000000004f24ee8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f24ee8)
#17 0x0000000005252b28 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5252b28)
#18 0x00000000051df6ad clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51df6ad)
#19 0x0000000005327dbd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5327dbd)
#20 0x0000000000dab3bc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdab3bc)
#21 0x0000000000da1fda ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#22 0x0000000000da215d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#23 0x0000000004f9ce59 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#24 0x0000000004360804 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4360804)
#25 0x0000000004f9d9c5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#26 0x0000000004f558a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f558a2)
#27 0x0000000004f5a207 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5a207)
#28 0x0000000004f64775 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f64775)
#29 0x0000000000da78ba clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda78ba)
#30 0x0000000000cc35ba main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc35ba)
#31 0x000071807122a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#32 0x000071807122a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#33 0x0000000000da1985 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda1985)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```

Contributor guide

Open the contributing guide

Research direction

Start by running the linked Godbolt reproducer with Clang at -O1 and inspect the generated IR or backend diagnostics around the conflicting attributes. Trace the code-generation path that handles the const variadic snprintf declaration; done means the reproducer compiles without the broken-module crash and the regression is covered by an appropriate compiler test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.