https://github.com/anematode updated 
https://github.com/llvm/llvm-project/pull/149745

>From d36dcec834f1846f050b89650b31bee4e138ddc3 Mon Sep 17 00:00:00 2001
From: Timothy Herchen <timothy.herc...@gmail.com>
Date: Sun, 20 Jul 2025 16:11:22 -0700
Subject: [PATCH 1/2] [clang] [Sema] Check argument range for prefetchi*
 intrinsics

---
 clang/lib/Sema/SemaX86.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang/lib/Sema/SemaX86.cpp b/clang/lib/Sema/SemaX86.cpp
index 5c149bdec7073..6bb3558972126 100644
--- a/clang/lib/Sema/SemaX86.cpp
+++ b/clang/lib/Sema/SemaX86.cpp
@@ -954,6 +954,11 @@ bool SemaX86::CheckBuiltinFunctionCall(const TargetInfo 
&TI, unsigned BuiltinID,
     l = 0;
     u = 15;
     break;
+  case X86::BI__builtin_ia32_prefetchi:
+    i = 1;
+    l = 2; // _MM_HINT_T1
+    u = 3; // _MM_HINT_T0
+    break;
   }
 
   // Note that we don't force a hard error on the range check here, allowing

>From 8f27a35472dd4318a891261cb669163045d35774 Mon Sep 17 00:00:00 2001
From: Timothy Herchen <timothy.herc...@gmail.com>
Date: Mon, 21 Jul 2025 21:20:03 -0700
Subject: [PATCH 2/2] add test

---
 clang/test/CodeGen/X86/prefetchi-error.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/prefetchi-error.c

diff --git a/clang/test/CodeGen/X86/prefetchi-error.c 
b/clang/test/CodeGen/X86/prefetchi-error.c
new file mode 100644
index 0000000000000..782bbe62cc9a3
--- /dev/null
+++ b/clang/test/CodeGen/X86/prefetchi-error.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple=i686-unknown-unknown 
-target-feature +sm3  -fsyntax-only -verify
+
+#include <immintrin.h>
+
+__m128i test_mm_sm3rnds2_epi32(__m128i __A, __m128i __B, __m128i __C) {
+  return _mm_sm3rnds2_epi32(__A, __B, __C, 256); // expected-error {{argument 
value 256 is outside the valid range [0, 255]}}
+}
+
+void test_invalid_prefetchi(void* p) {
+  return __builtin_ia32_prefetchi(p, 1); // expected-error {{argument value 1 
is outside the valid range [2, 3]}}
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to