llvm / llvm/llvm-project

Assertion failure in getInlineDesc with incomplete constexpr array decl

Open
#212,719 5 comments 0 reactions 0 assignees View on GitHub
clang:bytecode crash-on-invalid generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

@tbaederr I'm working on a non-llm fuzzer so this is a kind of weird failure - I ha vent done any diagnosis yet:

```cpp
constexpr int foo[][1] = ;
static_assert(foo[0][0])
```

CE link: https://compiler-explorer.com/z/T48KrxGdd

crash trace:

```
:1:26: error: expected expression
1 | constexpr int foo[][1] = ;
| ^
:2:25: error: expected ';' after 'static_assert'
2 | static_assert(foo[0][0])
| ^
| ;
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ByteCode/Pointer.h:1045: clang::interp::InlineDescriptor* clang::interp::Pointer::getInlineDesc() const: Assertion `BS.Base != sizeof(GlobalInlineDescriptor)' failed.
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 -fexperimental-new-constant-interpreter
1. parser at end of file
#0 0x0000000004420a78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4420a78)
#1 0x000000000441d924 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441d924)
#2 0x000000000441df5c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441df5c)
#3 0x000000000435cf38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007bee44645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007bee4469eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007bee4464527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007bee446288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007bee4462881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007bee4463b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000834179a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x834179a)
#11 0x00000000083fe5f8 clang::interp::Pointer::isInitialized() const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x83fe5f8)
#12 0x00000000083cab2a clang::interp::CheckLoad(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Pointer const&, clang::AccessKinds) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x83cab2a)
#13 0x000000000825ec3e clang::interp::EvalEmitter::emitLoadPop(clang::interp::PrimType, clang::interp::SourceInfo) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x825ec3e)
#14 0x000000000869216d clang::interp::Compiler::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x869216d)
#15 0x0000000008690050 clang::interp::Compiler::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8690050)
#16 0x00000000086924b4 clang::interp::Compiler::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x86924b4)
#17 0x0000000008690050 clang::interp::Compiler::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8690050)
#18 0x0000000008684d1a clang::interp::Compiler::visitExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8684d1a)
#19 0x00000000081bf347 clang::interp::EvalEmitter::interpretExpr(clang::Expr const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x81bf347)
#20 0x00000000081b709a clang::interp::Context::evaluateAsRValue(clang::interp::State&, clang::Expr const*, clang::APValue&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x81b709a)
#21 0x0000000008117b22 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#22 0x000000000811de8e clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x811de8e)
#23 0x00000000072c7296 clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*, clang::Sema::VerifyICEDiagnoser&, clang::AllowFoldKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72c7296)
#24 0x00000000072c7ca2 clang::Sema::VerifyIntegerConstantExpression(clang::Expr*, llvm::APSInt*, unsigned int, clang::AllowFoldKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72c7ca2)
#25 0x00000000071d60c6 clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71d60c6)
#26 0x0000000006da5edb clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da5edb)
#27 0x0000000006d9d6f6 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9d6f6)
#28 0x0000000006d542d0 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d542d0)
#29 0x0000000006d55205 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d55205)
#30 0x0000000006d3216a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d3216a)
#31 0x0000000004f2e918 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f2e918)
#32 0x000000000525ba98 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525ba98)
#33 0x00000000051e865d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51e865d)
#34 0x00000000053301dd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53301dd)
#35 0x0000000000dacf5c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdacf5c)
#36 0x0000000000da3b6a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#37 0x0000000000da3ced int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#38 0x0000000004fa5e19 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#39 0x000000000435d374 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435d374)
#40 0x0000000004fa6985 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#41 0x0000000004f5f162 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5f162)
#42 0x0000000004f63997 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f63997)
#43 0x0000000004f6def5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f6def5)
#44 0x0000000000da944a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda944a)
#45 0x0000000000cc525a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc525a)
#46 0x00007bee4462a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#47 0x00007bee4462a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#48 0x0000000000da3515 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda3515)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the provided incomplete constexpr array with Clang's -fexperimental-new-constant-interpreter option. Inspect clang/lib/AST/ByteCode/Pointer.h at Pointer::getInlineDesc() and follow the isInitialized and CheckLoad stack frames. Done means the input produces a normal diagnostic or otherwise no frontend assertion, with a regression test covering the reproducer.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.