https://github.com/jjppp updated https://github.com/llvm/llvm-project/pull/201623
>From f5bbc312665a222a06f9ac9dc067c29b9fc5da2b Mon Sep 17 00:00:00 2001 From: jpwang <[email protected]> Date: Fri, 5 Jun 2026 00:37:01 +0800 Subject: [PATCH] [Clang][CodeGen] Avoid failing downcast when __builtin_prefetch's immarg is poison --- clang/lib/CodeGen/CGBuiltin.cpp | 4 ++++ clang/test/CodeGen/prefetch-poison-arg.c | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 clang/test/CodeGen/prefetch-poison-arg.c diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 7ce38c5d1922c..b5aaa0b4b8f7e 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4308,8 +4308,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, // FIXME: Technically these constants should of type 'int', yes? RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : llvm::ConstantInt::get(Int32Ty, 0); + if (isa<llvm::PoisonValue>(RW)) + RW = llvm::ConstantInt::get(Int32Ty, 0); Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : llvm::ConstantInt::get(Int32Ty, 3); + if (isa<llvm::PoisonValue>(Locality)) + Locality = llvm::ConstantInt::get(Int32Ty, 3); Value *Data = llvm::ConstantInt::get(Int32Ty, 1); Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType()); Builder.CreateCall(F, {Address, RW, Locality, Data}); diff --git a/clang/test/CodeGen/prefetch-poison-arg.c b/clang/test/CodeGen/prefetch-poison-arg.c new file mode 100644 index 0000000000000..8a6bed46e869b --- /dev/null +++ b/clang/test/CodeGen/prefetch-poison-arg.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm %s -o - | FileCheck %s + +void test_poison_rw(void) { + __builtin_prefetch(0, 2 >> 32, 2 >> 32); + // CHECK: call void @llvm.prefetch.p0(ptr null, i32 0, i32 3, i32 1) +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
