Skip to content

Commit e644f5f

Browse files
authored
[clang] [Sema] Check argument range for prefetchi* intrinsics (llvm#149745)
Fixes llvm#144857 . I can create a test if desired, but I think the fix is trivial enough. <img width="805" height="105" alt="image" src="https://github.com/user-attachments/assets/aaee8e5f-6e65-4f04-b8b9-e4ae1434d958" />
1 parent eafe31b commit e644f5f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/lib/Sema/SemaX86.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,11 @@ bool SemaX86::CheckBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
954954
l = 0;
955955
u = 15;
956956
break;
957+
case X86::BI__builtin_ia32_prefetchi:
958+
i = 1;
959+
l = 2; // _MM_HINT_T1
960+
u = 3; // _MM_HINT_T0
961+
break;
957962
}
958963

959964
// Note that we don't force a hard error on the range check here, allowing
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +prefetchi -fsyntax-only -verify
2+
3+
#include <immintrin.h>
4+
5+
void test_invalid_prefetchi(void* p) {
6+
__builtin_ia32_prefetchi(p, 1); // expected-error {{argument value 1 is outside the valid range [2, 3]}}
7+
}

0 commit comments

Comments
 (0)