Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang ICE: 'Align can't be zero' with large number passed to ext_vector_type attribute #61747

Open
langston-barrett opened this issue Mar 28, 2023 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@langston-barrett
Copy link
Contributor

langston-barrett commented Mar 28, 2023

This bug was found with a fuzzer; please feel free to close if it's not helpful.

typedef float t __attribute__((ext_vector_type(0xfffffff)));
struct s {
  t position;
};
struct s x = {0};

Godbolt

clang++: /root/llvm-project/llvm/include/llvm/Support/MathExtras.h:486: uint64_t llvm::alignTo(uint64_t, uint64_t): Assertion `Align != 0u && "Align can't be 0."' 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -c -O0 <source>
1.	<source>:5:17: current parser token ';'
 #0 0x000055ebb681449f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401f49f)
 #1 0x000055ebb68121dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401d1dc)
 #2 0x000055ebb675f2f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f1a5afb3420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f1a5aa8000b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f1a5aa5f859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f1a5aa5f729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f1a5aa70fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055ebba1d44c5 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79df4c5)
 #9 0x000055ebba1e0668 (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutField(clang::FieldDecl const*, bool) RecordLayoutBuilder.cpp:0:0
#10 0x000055ebba1e1d4f (anonymous namespace)::ItaniumRecordLayoutBuilder::LayoutFields(clang::RecordDecl const*) RecordLayoutBuilder.cpp:0:0
#11 0x000055ebba1deb00 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79e9b00)
#12 0x000055ebba021ff0 (anonymous namespace)::RecordExprEvaluator::VisitCXXParenListOrInitListExpr(clang::Expr const*, llvm::ArrayRef<clang::Expr*>) ExprConstant.cpp:0:0
#13 0x000055ebba0553d2 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::RecordExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#14 0x000055ebba055ee4 EvaluateRecord(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#15 0x000055ebba020125 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0
#16 0x000055ebba05a839 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7865839)
#17 0x000055ebb9f2d7c2 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77387c2)
#18 0x000055ebb9f2dba9 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7738ba9)
#19 0x000055ebb9243a45 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a4ea45)
#20 0x000055ebb9258d2a clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a63d2a)
#21 0x000055ebb8f1f28e clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x672a28e)
#22 0x000055ebb8f30818 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x673b818)
#23 0x000055ebb8ef8eb2 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6703eb2)
#24 0x000055ebb8ef976f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#25 0x000055ebb8f001f9 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x670b1f9)
#26 0x000055ebb8f00b4d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x670bb4d)
#27 0x000055ebb8ef4a1a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66ffa1a)
#28 0x000055ebb7a34268 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x523f268)
#29 0x000055ebb7298f09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4aa3f09)
#30 0x000055ebb721d436 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a28436)
#31 0x000055ebb737cbf7 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b87bf7)
#32 0x000055ebb3d995f6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15a45f6)
#33 0x000055ebb3d9541a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x000055ebb708619d 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
#35 0x000055ebb675f7e0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f6a7e0)
#36 0x000055ebb7086a5f 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
#37 0x000055ebb704e29c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x485929c)
#38 0x000055ebb704ed3d 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+++0x4859d3d)
#39 0x000055ebb70569ed clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48619ed)
#40 0x000055ebb3d97aa0 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15a2aa0)
#41 0x000055ebb3ca34d5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x14ae4d5)
#42 0x00007f1a5aa61083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#43 0x000055ebb3d9012e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x159b12e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Mar 28, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Mar 28, 2023

It looks like there are multiple crash bugs associated with this feature (clearly not good enough coverage) if we use __attribute__((ext_vector_type(0x0004ffff))) instead: https://godbolt.org/z/EoP4PxjP4 we obtain a different assert based on bitwidth:

clang++: /root/llvm-project/llvm/lib/IR/Type.cpp:333:
static llvm::IntegerType* llvm::IntegerType::get(llvm::LLVMContext&, unsigned int):
Assertion `NumBits <= MAX_INT_BITS && "bitwidth too large"' failed.

We should be issues diagnostics instead of crashing.

@shafik shafik added the confirmed Verified by a second party label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants