Skip to content

[clang][bytecode] assertion failure when accessing vector element with nested cast/initializer in C #158482

@k-arrows

Description

@k-arrows

Reproducer:
https://godbolt.org/z/1ThGnnno4

typedef unsigned char U __attribute__((vector_size(1))); void foo(U f) { f[0] = f[((U)(U){0})[0]]; }

Backtrace:

clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ByteCode/InterpStack.h:41: T clang::interp::InterpStack::pop() [with T = clang::interp::Integral<8, false>]: Assertion `ItemTypes.back() == toPrimType<T>()' 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++ -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 -fexperimental-new-constant-interpreter <source> 1.	<source>:3:41: current parser token ';' 2.	<source>:3:15: parsing function body 'foo' 3.	<source>:3:15: in compound statement ('{}')  #0 0x0000000004177998 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4177998)  #1 0x0000000004174dc4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4174dc4)  #2 0x00000000040b9368 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0  #3 0x000076ccb0842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)  #4 0x000076ccb08969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)  #5 0x000076ccb0842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)  #6 0x000076ccb08287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)  #7 0x000076ccb082871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)  #8 0x000076ccb0839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)  #9 0x0000000007b52b85 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7b52b85) #10 0x0000000007b7925f clang::interp::EvalEmitter::emitRet(clang::interp::PrimType, clang::interp::SourceInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7b7925f) #11 0x0000000007f7dcc9 clang::interp::Compiler<clang::interp::EvalEmitter>::visitExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7f7dcc9) #12 0x0000000007b1edfd clang::interp::EvalEmitter::interpretExpr(clang::Expr const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7b1edfd) #13 0x0000000007aed243 clang::interp::Context::evaluateAsRValue(clang::interp::State&, clang::Expr const*, clang::APValue&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7aed243) #14 0x0000000007a63e23 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0 #15 0x0000000007a6890e EvaluateAsInt(clang::Expr const*, clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::SideEffectsKind, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0 #16 0x0000000007a68c77 clang::Expr::EvaluateAsInt(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::SideEffectsKind, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a68c77) #17 0x0000000006a88a8d clang::Sema::CheckArrayAccess(clang::Expr const*, clang::Expr const*, clang::ArraySubscriptExpr const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a88a8d) #18 0x0000000006a89e9f clang::Sema::CheckArrayAccess(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a89e9f) #19 0x0000000006d8a94d clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8a94d) #20 0x0000000006d8c698 clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8c698) #21 0x0000000006d8cd06 clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8cd06) #22 0x00000000068c6f1a clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68c6f1a) #23 0x00000000068ca539 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68ca539) #24 0x000000000694e539 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x694e539) #25 0x00000000069458c4 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69458c4) #26 0x0000000006946739 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6946739) #27 0x000000000694ec4e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x694ec4e) #28 0x000000000694f46a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x694f46a) #29 0x000000000685656b clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x685656b) #30 0x000000000688c9cd 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+++0x688c9cd) #31 0x000000000684933e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x684933e) #32 0x0000000006849adf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6849adf) #33 0x000000000685191a clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x685191a) #34 0x00000000068528b5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68528b5) #35 0x000000000683332a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x683332a) #36 0x0000000004ab1438 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab1438) #37 0x0000000004dab495 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4dab495) #38 0x0000000004d2682e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d2682e) #39 0x0000000004ea0281 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ea0281) #40 0x0000000000db5abf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb5abf) #41 0x0000000000dac72a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #42 0x0000000004b1a3c9 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 #43 0x00000000040b9804 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40b9804) #44 0x0000000004b1a9df 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 #45 0x0000000004adb5bd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4adb5bd) #46 0x0000000004adc64e 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+++0x4adc64e) #47 0x0000000004ae45e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ae45e5) #48 0x0000000000db1f45 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb1f45) #49 0x0000000000c63e84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc63e84) #50 0x000076ccb0829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #51 0x000076ccb0829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #52 0x0000000000dac1d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdac1d5) 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 interpretercrashPrefer [crash-on-valid] or [crash-on-invalid]

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions