Skip to content

Clang assertion failure: isVectorType() check fails for atomic vector operations in constant expression evaluation #169907

@AbyssStaror

Description

@AbyssStaror

Link for quick verification: https://godbolt.org/z/sMjK53n3P

#include <stdatomic.h>
#include <signal.h>

typedef __attribute__((__vector_size__(8))) char V;

_Atomic V g_atomic_vector;

void handle(int signum) {
    V v = g_atomic_vector;
    v ^= (V){1, 2, 3, 4, 5, 6, 7, 8}; 
    g_atomic_vector = v;
}

Clang crashes with an ICE when compiling code that performs vector operations on atomic vector types within a signal handler function. The assertion fails in ExprConstant.cpp during constant expression evaluation of binary operations on vector types.

The stack dump:

clang-21: /workspace/install/llvm/src/llvm-project/clang/lib/AST/ExprConstant.cpp:11345: bool {anonymous}::VectorExprEvaluator::VisitBinaryOperator(const clang::BinaryOperator*): Assertion `LHS->getType()->isVectorType() && RHS->getType()->isVectorType() && "Must both be vector types"' 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: /workspace/install/llvm/build_21.1.4/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -O3 -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name 33794.fuzz -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/workspace/exps -fcoverage-compilation-dir=/workspace/exps -resource-dir /workspace/install/llvm/build_21.1.4/lib/clang/21 -internal-isystem /workspace/install/llvm/build_21.1.4/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fmessage-length=167 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/33794-c1b535.o -x c /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/33794.fuzz
1.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/33794.fuzz:17:1: current parser token '}'
2.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/33794.fuzz:12:25: parsing function body 'handle'
3.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/33794.fuzz:12:25: in compound statement ('{}')
 #0 0x00005999d93bac2a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9691c2a)
 #1 0x00005999d93bb457 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #2 0x00005999d93b4f57 llvm::sys::RunSignalHandlers() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x968bf57)
 #3 0x00005999d93b51c7 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #4 0x00007ade4efd0330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x00007ade4f029b2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007ade4f029b2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007ade4f029b2c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007ade4efd027e raise ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007ade4efb38ff abort ./stdlib/abort.c:81:7
#10 0x00007ade4efb381b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007ade4efc6517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#12 0x00005999de528cd3 (anonymous namespace)::VectorExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) ExprConstant.cpp:0:0
#13 0x00005999de4d609b clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VectorExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#14 0x00005999de4d9263 EvaluateVector(clang::Expr const*, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#15 0x00005999de4d94ae Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#16 0x00005999de4e2d5d EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#17 0x00005999de4e3a25 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xe7baa25)
#18 0x00005999dcbbba9d clang::Sema::CheckForIntOverflow(clang::Expr const*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xce92a9d)
#19 0x00005999dcc13acc clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xceeaacc)
#20 0x00005999dd18b8da clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xd4628da)
#21 0x00005999dd61f4a7 clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xd8f64a7)
#22 0x00005999dca01081 clang::Parser::handleExprStmt(clang::ActionResult<clang::Expr*, true>, clang::Parser::ParsedStmtContext) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xccd8081)
#23 0x00005999dca07353 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xccde353)
#24 0x00005999dca09487 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcce0487)
#25 0x00005999dca0a099 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcce1099)
#26 0x00005999dca0be9e clang::Parser::ParseCompoundStatementBody(bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcce2e9e)
#27 0x00005999dca0c8c2 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcce38c2)
#28 0x00005999dc8b0337 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb87337)
#29 0x00005999dc909d18 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcbe0d18)
#30 0x00005999dc8a6307 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb7d307)
#31 0x00005999dc8a6e9e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb7de9e)
#32 0x00005999dc8b2f98 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb89f98)
#33 0x00005999dc8b459d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb8b59d)
#34 0x00005999dc89a9d0 clang::ParseAST(clang::Sema&, bool, bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb719d0)
#35 0x00005999da5e292b clang::ASTFrontendAction::ExecuteAction() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa8b992b)
#36 0x00005999da1d0360 clang::CodeGenAction::ExecuteAction() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa4a7360)
#37 0x00005999da5ea9cf clang::FrontendAction::Execute() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa8c19cf)
#38 0x00005999da530f46 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa807f46)
#39 0x00005999da772f7b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xaa49f7b)
#40 0x00005999d44e1523 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47b8523)
#41 0x00005999d44d1c58 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#42 0x00005999d44d7b28 clang_main(int, char**, llvm::ToolContext const&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47aeb28)
#43 0x00005999d4332b4a main (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x4609b4a)
#44 0x00007ade4efb51ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#45 0x00007ade4efb528b call_init ./csu/../csu/libc-start.c:128:20
#46 0x00007ade4efb528b __libc_start_main ./csu/../csu/libc-start.c:347:5
#47 0x00005999d44cff55 _start (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47a6f55)
clang: error: unable to execute command: Aborted (core dumped)

The clang version:

clang version 21.1.4 (https://github.com/llvm/llvm-project.git 222fc11f2b8f25f6a0f4976272ef1bb7bf49521d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /workspace/install/llvm/build_21.1.4/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationcrashPrefer [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