Skip to content

Commit ea46a21

Browse files
committed
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.
1 parent 2fc25a2 commit ea46a21

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

gcc/config/i386/i386-expand.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14202,6 +14202,13 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
1420214202
return const0_rtx;
1420314203
}
1420414204

14205+
if (!IN_RANGE (INTVAL (op1), 0, 2))
14206+
{
14207+
warning (0, "invalid second argument to"
14208+
" %<__builtin_ia32_prefetch%>; using zero");
14209+
op1 = const0_rtx;
14210+
}
14211+
1420514212
if (INTVAL (op3) == 1)
1420614213
{
1420714214
if (INTVAL (op2) < 2 || INTVAL (op2) > 3)
@@ -14224,6 +14231,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
1422414231
}
1422514232
else
1422614233
{
14234+
if (INTVAL (op3) != 0)
14235+
warning (0, "invalid forth argument to"
14236+
" %<__builtin_ia32_prefetch%>; using zero");
14237+
1422714238
if (!address_operand (op0, VOIDmode))
1422814239
{
1422914240
op0 = convert_memory_address (Pmode, op0);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* PR target/117416 */
2+
/* { dg-do compile } */
3+
/* { dg-options "-O0" } */
4+
5+
#include <x86intrin.h>
6+
7+
void* p;
8+
9+
void extern
10+
prefetch_test (void)
11+
{
12+
__builtin_ia32_prefetch (p, 5, 0, 0); /* { dg-warning "invalid second argument to '__builtin_ia32_prefetch'; using zero" } */
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* PR target/117416 */
2+
/* { dg-do compile } */
3+
/* { dg-options "-O0" } */
4+
5+
#include <x86intrin.h>
6+
7+
void* p;
8+
9+
void extern
10+
prefetch_test (void)
11+
{
12+
__builtin_ia32_prefetch (p, 0, 0, 2); /* { dg-warning "invalid forth argument to '__builtin_ia32_prefetch'; using zero" } */
13+
}

0 commit comments

Comments
 (0)