Skip to content

[clang] [Sema] Check argument range for prefetchi* intrinsics #149745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/X86/prefetchi-error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +prefetchi -fsyntax-only -verify

#include <immintrin.h>

void test_invalid_prefetchi(void* p) {
__builtin_ia32_prefetchi(p, 1); // expected-error {{argument value 1 is outside the valid range [2, 3]}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a lower and upper range, testing should validate both. Tests should be as complete, especially when it is apparent and to prevent regression in behavior in the future due to new changes.

}
Loading