Skip to content

Commit 77a67e3

Browse files
hjl-toolsH.J. Lu
authored andcommitted
x86: Check invalid third argument to __builtin_ia32_prefetch
Check invalid third argument to __builtin_ia32_prefetch when expaning __builtin_ia32_prefetch to avoid ICE later. gcc/ PR target/108436 * config/i386/i386-expand.cc (ix86_expand_builtin): Check invalid third argument to __builtin_ia32_prefetch. gcc/testsuite/ * gcc.target/i386/pr108436.c: New test.
1 parent 46644ec commit 77a67e3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

gcc/config/i386/i386-expand.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13175,6 +13175,12 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
1317513175

1317613176
if (INTVAL (op3) == 1)
1317713177
{
13178+
if (INTVAL (op2) < 2 || INTVAL (op2) > 3)
13179+
{
13180+
error ("invalid third argument");
13181+
return const0_rtx;
13182+
}
13183+
1317813184
if (TARGET_64BIT && TARGET_PREFETCHI
1317913185
&& local_func_symbolic_operand (op0, GET_MODE (op0)))
1318013186
emit_insn (gen_prefetchi (op0, op2));
@@ -13195,6 +13201,12 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
1319513201
op0 = copy_addr_to_reg (op0);
1319613202
}
1319713203

13204+
if (INTVAL (op2) < 0 || INTVAL (op2) > 3)
13205+
{
13206+
warning (0, "invalid third argument to %<__builtin_ia32_prefetch%>; using zero");
13207+
op2 = const0_rtx;
13208+
}
13209+
1319813210
if (TARGET_3DNOW || TARGET_PREFETCH_SSE
1319913211
|| TARGET_PRFCHW || TARGET_PREFETCHWT1)
1320013212
emit_insn (gen_prefetch (op0, op1, op2));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-mprefetchi" } */
3+
4+
int
5+
foo (int a)
6+
{
7+
return a + 1;
8+
}
9+
10+
void
11+
bad (int *p)
12+
{
13+
__builtin_ia32_prefetch (p, 0, 4, 0); /* { dg-warning "invalid third argument to '__builtin_ia32_prefetch'; using zero" } */
14+
__builtin_ia32_prefetch (foo, 0, 4, 1); /* { dg-error "invalid third argument" } */
15+
}

0 commit comments

Comments
 (0)