-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Labels
clang:bytecodeIssues for the clang bytecode constexpr interpreterIssues for the clang bytecode constexpr interpretercrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]
Description
Reproducer:
https://godbolt.org/z/bqbc83EPz
char *strchr(const char *, int);
struct A {
char n, a[2];
};
struct B {
int n;
struct A a[];
};
const struct B b = {0, {{1, {2, 3}}, {4, {5, 6}}}};
void foo(void) { int sch = 0 != strchr(b.a[1].a, '\0'); }
Backtrace:
clang: /root/llvm-project/llvm/tools/clang/lib/AST/ByteCode/Pointer.h:688: T& clang::interp::Pointer::deref() const [with T = clang::interp::Integral<8, true>]: Assertion `isDereferencable()' 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 -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -fexperimental-new-constant-interpreter <source>
1. <source>:13:55: current parser token ';'
2. <source>:13:16: parsing function body 'foo'
3. <source>:13:16: in compound statement ('{}')
#0 0x0000000004026d28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4026d28)
#1 0x0000000004024154 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4024154)
#2 0x0000000003f68988 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000071fe35c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000071fe35c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000071fe35c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000071fe35c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000071fe35c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000071fe35c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000079d167e clang::interp::Integral<8u, true>& clang::interp::Pointer::deref<clang::interp::Integral<8u, true>>() const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x79d167e)
#10 0x0000000007a01e7e clang::interp::EvalEmitter::emitInitField(clang::interp::PrimType, unsigned int, clang::interp::SourceInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7a01e7e)
#11 0x0000000007e0329f clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitList(llvm::ArrayRef<clang::Expr const*>, clang::Expr const*, clang::Expr const*)::'lambda'(clang::interp::Record::Field const*, clang::Expr const*, clang::interp::PrimType, bool)::operator()(clang::interp::Record::Field const*, clang::Expr const*, clang::interp::PrimType, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e0329f)
#12 0x0000000007e4277f clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitList(llvm::ArrayRef<clang::Expr const*>, clang::Expr const*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e4277f)
#13 0x0000000007e2ee7d clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitializer(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e2ee7d)
#14 0x0000000007e33c2f clang::interp::Compiler<clang::interp::EvalEmitter>::visitArrayElemInit(unsigned int, clang::Expr const*, clang::interp::OptPrimType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e33c2f)
#15 0x0000000007e4265d clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitList(llvm::ArrayRef<clang::Expr const*>, clang::Expr const*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e4265d)
#16 0x0000000007e2ee7d clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitializer(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e2ee7d)
#17 0x0000000007e33a19 clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitList(llvm::ArrayRef<clang::Expr const*>, clang::Expr const*, clang::Expr const*)::'lambda0'(clang::interp::Record::Field const*, clang::Expr const*, bool)::operator()(clang::interp::Record::Field const*, clang::Expr const*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e33a19)
#18 0x0000000007e428f6 clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitList(llvm::ArrayRef<clang::Expr const*>, clang::Expr const*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e428f6)
#19 0x0000000007e2ee7d clang::interp::Compiler<clang::interp::EvalEmitter>::visitInitializer(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e2ee7d)
#20 0x0000000007e303da clang::interp::Compiler<clang::interp::EvalEmitter>::visitVarDecl(clang::VarDecl const*, bool, bool)::'lambda0'(unsigned int)::operator()(unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e303da)
#21 0x0000000007e3090a clang::interp::Compiler<clang::interp::EvalEmitter>::visitVarDecl(clang::VarDecl const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3090a)
#22 0x0000000007e3114d clang::interp::Compiler<clang::interp::EvalEmitter>::visitDecl(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3114d)
#23 0x0000000007e312d0 clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclRef(clang::ValueDecl const*, clang::Expr const*)::'lambda'(clang::VarDecl const*)::operator()(clang::VarDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e312d0)
#24 0x0000000007e31afd clang::interp::Compiler<clang::interp::EvalEmitter>::visitDeclRef(clang::ValueDecl const*, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e31afd)
#25 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#26 0x0000000007e40ae7 clang::interp::Compiler<clang::interp::EvalEmitter>::VisitMemberExpr(clang::MemberExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e40ae7)
#27 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#28 0x0000000007e3c82d clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3c82d)
#29 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#30 0x0000000007dfbafc clang::interp::Compiler<clang::interp::EvalEmitter>::VisitArraySubscriptExpr(clang::ArraySubscriptExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7dfbafc)
#31 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#32 0x0000000007e40ae7 clang::interp::Compiler<clang::interp::EvalEmitter>::VisitMemberExpr(clang::MemberExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e40ae7)
#33 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#34 0x0000000007e3c82d clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3c82d)
#35 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#36 0x0000000007e2d402 clang::interp::Compiler<clang::interp::EvalEmitter>::VisitBuiltinCallExpr(clang::CallExpr const*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e2d402)
#37 0x0000000007e3492e clang::interp::Compiler<clang::interp::EvalEmitter>::VisitCallExpr(clang::CallExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3492e)
#38 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#39 0x0000000007e3dee5 clang::interp::Compiler<clang::interp::EvalEmitter>::VisitBinaryOperator(clang::BinaryOperator const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3dee5)
#40 0x0000000007e3b040 clang::interp::Compiler<clang::interp::EvalEmitter>::visit(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e3b040)
#41 0x0000000007e2ffea clang::interp::Compiler<clang::interp::EvalEmitter>::visitExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7e2ffea)
#42 0x00000000079c5891 clang::interp::EvalEmitter::interpretExpr(clang::Expr const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x79c5891)
#43 0x00000000079b8ecf clang::interp::Context::evaluateAsRValue(clang::interp::State&, clang::Expr const*, clang::APValue&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x79b8ecf)
#44 0x00000000079328e3 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#45 0x0000000007934971 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7934971)
#46 0x000000000692dc56 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x692dc56)
#47 0x000000000696567c clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x696567c)
#48 0x0000000006ce4017 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6ce4017)
#49 0x0000000006aae13a clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6aae13a)
#50 0x000000000671015a clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x671015a)
#51 0x000000000671eb79 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x671eb79)
#52 0x000000000672782f clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x672782f)
#53 0x0000000006727cfc clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6727cfc)
#54 0x00000000067e9952 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67e9952)
#55 0x00000000067ea629 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67ea629)
#56 0x00000000067f278b clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67f278b)
#57 0x00000000067f2f9a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67f2f9a)
#58 0x00000000066e91ab clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66e91ab)
#59 0x000000000671f57d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x671f57d)
#60 0x00000000066dc5ce clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66dc5ce)
#61 0x00000000066dcd6f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66dcd6f)
#62 0x00000000066e45e3 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66e45e3)
#63 0x00000000066e54f5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66e54f5)
#64 0x00000000066d75fa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66d75fa)
#65 0x00000000049c8d28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49c8d28)
#66 0x0000000004cbcd15 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4cbcd15)
#67 0x0000000004c38f6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c38f6e)
#68 0x0000000004dae5f1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4dae5f1)
#69 0x0000000000db0c0f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdb0c0f)
#70 0x0000000000da786a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#71 0x0000000004a30739 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
#72 0x0000000003f68e24 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f68e24)
#73 0x0000000004a30d4f 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
#74 0x00000000049f2fbd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49f2fbd)
#75 0x00000000049f404e 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+0x49f404e)
#76 0x00000000049fbae5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49fbae5)
#77 0x0000000000dad0c5 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdad0c5)
#78 0x0000000000c61054 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc61054)
#79 0x000071fe35c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#80 0x000071fe35c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#81 0x0000000000da7315 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda7315)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
Metadata
Metadata
Assignees
Labels
clang:bytecodeIssues for the clang bytecode constexpr interpreterIssues for the clang bytecode constexpr interpretercrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]