i386: Handling exception input of __builtin_ia32_prefetch. [PR117416]

op1 should be between 0 and 2. Add an error handler, and op3 should be 0
or 1, raise a warning, when op3 is an invalid value.

gcc/ChangeLog:

	PR target/117416
	* config/i386/i386-expand.cc (ix86_expand_builtin): Raise warning when
	op1 isn't in range of [0, 2] and set op1 as const0_rtx, and raise
	warning when op3 isn't in range of [0, 1].

gcc/testsuite/ChangeLog:

	PR target/117416
	* gcc.target/i386/pr117416-1.c: New test.
	* gcc.target/i386/pr117416-2.c: Ditto.
This commit is contained in:
Hu, Lin1 2024-11-04 14:52:56 +08:00
parent 2fc25a2182
commit ea46a216d4
3 changed files with 37 additions and 0 deletions

View File

@ -14202,6 +14202,13 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
return const0_rtx;
}
if (!IN_RANGE (INTVAL (op1), 0, 2))
{
warning (0, "invalid second argument to"
" %<__builtin_ia32_prefetch%>; using zero");
op1 = const0_rtx;
}
if (INTVAL (op3) == 1)
{
if (INTVAL (op2) < 2 || INTVAL (op2) > 3)
@ -14224,6 +14231,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
}
else
{
if (INTVAL (op3) != 0)
warning (0, "invalid forth argument to"
" %<__builtin_ia32_prefetch%>; using zero");
if (!address_operand (op0, VOIDmode))
{
op0 = convert_memory_address (Pmode, op0);

View File

@ -0,0 +1,13 @@
/* PR target/117416 */
/* { dg-do compile } */
/* { dg-options "-O0" } */
#include <x86intrin.h>
void* p;
void extern
prefetch_test (void)
{
__builtin_ia32_prefetch (p, 5, 0, 0); /* { dg-warning "invalid second argument to '__builtin_ia32_prefetch'; using zero" } */
}

View File

@ -0,0 +1,13 @@
/* PR target/117416 */
/* { dg-do compile } */
/* { dg-options "-O0" } */
#include <x86intrin.h>
void* p;
void extern
prefetch_test (void)
{
__builtin_ia32_prefetch (p, 0, 0, 2); /* { dg-warning "invalid forth argument to '__builtin_ia32_prefetch'; using zero" } */
}