Skip to content

[clang][bytecode] crash on large multi-dimensional array in new expression #152951

@k-arrows

Description

@k-arrows

Reproducer:
https://godbolt.org/z/G639zMYbv

typedef __typeof__ (sizeof 0) size_t;

void* operator new (size_t, void*);
void* operator new[] (size_t, void*);

void *p;

void foo ()
{
    enum { N = 256 };
    p = new char [N][N][N][N][N];
}

Backtrace:

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-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 -fexperimental-new-constant-interpreter <source>
1.	<source>:12:1: current parser token '}'
2.	<source>:9:1: parsing function body 'foo'
3.	<source>:9:1: in compound statement ('{}')
 #0 0x0000000003cdc778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cdc778)
 #1 0x0000000003cda14c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cda14c)
 #2 0x0000000003c2a4e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000774668242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00000000075e2889 clang::interp::EvalEmitter::emitAllocCN(clang::interp::PrimType, clang::interp::Descriptor const*, bool, clang::interp::SourceInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x75e2889)
 #5 0x000000000790655c clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCXXNewExpr(clang::CXXNewExpr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x790655c)
 #6 0x000000000790c8e9 clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x790c8e9)
 #7 0x000000000790a968 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x790a968)
 #8 0x00000000078ed03f clang::interp::Compiler<clang::interp::EvalEmitter>::visitAssignment(clang::Expr const*, clang::Expr const*, clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x78ed03f)
 #9 0x000000000790d20a clang::interp::Compiler<clang::interp::EvalEmitter>::VisitBinaryOperator(clang::BinaryOperator const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x790d20a)
#10 0x000000000790a968 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x790a968)
#11 0x00000000079008ca clang::interp::Compiler<clang::interp::EvalEmitter>::visitExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x79008ca)
#12 0x00000000075319a3 clang::interp::EvalEmitter::interpretExpr(clang::Expr const*, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x75319a3)
#13 0x000000000751787e clang::interp::Context::evaluateAsRValue(clang::interp::State&, clang::Expr const*, clang::APValue&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x751787e)
#14 0x00000000074984ea EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) (.part.0) ExprConstant.cpp:0:0
#15 0x000000000749abaf clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x749abaf)
#16 0x000000000650ced6 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x650ced6)
#17 0x000000000653e5b3 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x653e5b3)
#18 0x00000000068b8409 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68b8409)
#19 0x0000000006bd323e clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6bd323e)
#20 0x00000000063c902c clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c902c)
#21 0x00000000063bfaf6 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63bfaf6)
#22 0x00000000063c04d3 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c04d3)
#23 0x00000000063c9e7d clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63c9e7d)
#24 0x00000000063ca8ba clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63ca8ba)
#25 0x00000000062a1458 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62a1458)
#26 0x00000000062edc8f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62edc8f)
#27 0x000000000629a20f clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x629a20f)
#28 0x000000000629b007 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x629b007)
#29 0x00000000062a3c1f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62a3c1f)
#30 0x00000000062a5470 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x62a5470)
#31 0x0000000006293aba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6293aba)
#32 0x00000000046238cd clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x46238cd)
#33 0x000000000492f13a clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x492f13a)
#34 0x00000000048a86bb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48a86bb)
#35 0x0000000004a1fd63 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a1fd63)
#36 0x0000000000dc00c5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdc00c5)
#37 0x0000000000db806d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#38 0x0000000004695bc9 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
#39 0x0000000003c2a903 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c2a903)
#40 0x0000000004695de9 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
#41 0x000000000465917d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x465917d)
#42 0x000000000465a131 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x465a131)
#43 0x0000000004663f7c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4663f7c)
#44 0x0000000000dbc8d1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdbc8d1)
#45 0x0000000000c6b864 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc6b864)
#46 0x0000774668229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x0000774668229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x0000000000db7b05 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdb7b05)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:bytecodeIssues for the clang bytecode constexpr interpreterclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]regression:18Regression in 18 release

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions