[clang] [Clang] Avoid crash with wide string CPU builtin argument (PR #245515)
Bhavya Gautam via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 02:42:30 PST 2026
gautam899 wrote:
With the provided reproducible along with the flag `-Wno-error=incompatible-pointer-types`, I noticed a crash with the below BT
`repro.c:2:33: warning: incompatible pointer types passing 'int[5]' to parameter of type 'const char *' [-Wincompatible-pointer-types]
2 | return __builtin_cpu_supports(L"wide");
| ^~~~~~~
clang-24: /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/include/clang/AST/Expr.h:1913: llvm::StringRef clang::StringLiteral::getString() const: Assertion `(isUnevaluated() || getCharByteWidth() == 1) && "This function is used in places that assume strings use char"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name repro.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -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=/mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug -fcoverage-compilation-dir=/mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug -resource-dir /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/lib/clang/24 -internal-isystem /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/lib/clang/24/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=incompatible-pointer-types -ferror-limit 19 -fmessage-length=209 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -faddrsig -fdwarf2-cfi-asm -o /tmp/repro-fab9cc.o -x c repro.c
1. <eof> parser at end of file
2. repro.c:1:5: LLVM IR generation of declaration 'main'
3. repro.c:1:5: Generating code for declaration 'main'
#0 0x00005835ecbf85e2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/llvm/lib/Support/Unix/Signals.inc:931:22
#1 0x00005835ecbf8a55 PrintStackTraceSignalHandler(void*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/llvm/lib/Support/Unix/Signals.inc:1013:1
#2 0x00005835ecbf58bf llvm::sys::RunSignalHandlers() /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/llvm/lib/Support/Signals.cpp:108:20
#3 0x00005835ecbf7d02 SignalHandler(int, siginfo_t*, void*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/llvm/lib/Support/Unix/Signals.inc:474:14
#4 0x00005835ecbf7def SignalHandlerTerminate(int, siginfo_t*, void*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/llvm/lib/Support/Unix/Signals.inc:514:25
#5 0x00007fe11da45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#6 0x00007fe11da9ebec __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#7 0x00007fe11da9ebec __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#8 0x00007fe11da9ebec pthread_kill ./nptl/pthread_kill.c:89:10
#9 0x00007fe11da4527e raise ./signal/../sysdeps/posix/raise.c:27:6
#10 0x00007fe11da288ff abort ./stdlib/abort.c:81:7
#11 0x00007fe11da2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#12 0x00007fe11da3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#13 0x00005835ed232f3d clang::StringLiteral::getString() const /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/include/clang/AST/Expr.h:1915:55
#14 0x00005835ed98a438 clang::CodeGen::CodeGenFunction::EmitX86CpuSupports(clang::CallExpr const*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/TargetBuiltins/X86.cpp:675:69
#15 0x00005835ed98b149 clang::CodeGen::CodeGenFunction::EmitX86BuiltinExpr(unsigned int, clang::CallExpr const*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/TargetBuiltins/X86.cpp:756:30
#16 0x00005835eda496af EmitTargetArchBuiltinExpr(clang::CodeGen::CodeGenFunction*, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Triple::ArchType) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp:106:48
#17 0x00005835eda499b6 clang::CodeGen::CodeGenFunction::EmitTargetBuiltinExpr(unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp:154:35
#18 0x00005835eda766cb clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGBuiltin.cpp:7039:39
#19 0x00005835ed21dc96 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExpr.cpp:6682:27
#20 0x00005835ed2d8ce6 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:692:32
#21 0x00005835ed2fd08a clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/tools/clang/include/clang/AST/StmtNodes.inc:634:1
#22 0x00005835ed2d797d (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:501:57
#23 0x00005835ed2e65aa (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:3076:32
#24 0x00005835ed2feaa7 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/tools/clang/include/clang/AST/StmtNodes.inc:554:1
#25 0x00005835ed2fcf9a clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/tools/clang/include/clang/AST/StmtNodes.inc:554:1
#26 0x00005835ed2d797d (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:501:57
#27 0x00005835ed2fa2e3 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:6212:1
#28 0x00005835ed507f12 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGStmt.cpp:1667:40
#29 0x00005835ed500a39 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGStmt.cpp:163:75
#30 0x00005835ed501f34 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CGStmt.cpp:591:3
#31 0x00005835ed5db6fd clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1421:33
#32 0x00005835ed5dcbdf clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1661:21
#33 0x00005835ed61f94f clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:7145:5
#34 0x00005835ed616823 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5245:47
#35 0x00005835ed615961 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5008:27
#36 0x00005835ed6248fd clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:8092:37
#37 0x00005835edbf904d (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:200:7
#38 0x00005835edbec9c0 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:151:7
#39 0x00005835f37d63bf clang::ParseAST(clang::Sema&, bool, bool) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/Parse/ParseAST.cpp:169:20
#40 0x00005835edff4a9d clang::ASTFrontendAction::ExecuteAction() /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1497:11
#41 0x00005835edbef224 clang::CodeGenAction::ExecuteAction() /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:531:5
#42 0x00005835edff42f3 clang::FrontendAction::Execute() /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1381:38
#43 0x00005835edf0eeac clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1040:42
#44 0x00005835ee1697b1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:326:38
#45 0x00005835ea9867f0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/tools/driver/cc1_main.cpp:330:38
#46 0x00005835ea9775e2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/tools/driver/driver.cpp:229:20
#47 0x00005835ea977bf6 clang_main(int, char**, llvm::ToolContext const&) /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/clang/tools/driver/driver.cpp:277:26
#48 0x00005835ea9ace18 main /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/tools/clang/tools/driver/clang-driver.cpp:17:20
#49 0x00007fe11da2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#50 0x00007fe11da2a28b call_init ./csu/../csu/libc-start.c:128:20
#51 0x00007fe11da2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#52 0x00005835ea9768c5 _start (/mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/bin/clang-24+0x166f8c5)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed with exit code -2 (use -v to see invocation)
clang version 24.0.0git (git at github.com:gautam899/llvm-project.git 8817a66ccf36c5585c36b424ee3eaf3f2bad6848)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/8f8d3ac7-c581-458d-8040-5a5ae3812454/bgautam/llvm-project/build-debug/bin
Build config: +unoptimized, +assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
clang: note: diagnostic msg: /tmp/repro-f76919.c
clang: note: diagnostic msg: /tmp/repro-f76919.sh
clang: note: diagnostic msg:
********************
Aborted (core dumped)`
I noticed a similar crash with `__builtin_cpu_is`.
To address both these cases I have added checks in CodeGen/TargetBuiltins/X86.cpp for both `EmitX86CpuIs` and `EmitX86CpuSupports`. Should this all be added in two commits or one commit is fine?
https://github.com/llvm/llvm-project/pull/245515
More information about the cfe-commits
mailing list