From: Hu, Lin1 Date: Mon, 4 Nov 2024 06:52:56 +0000 (+0800) Subject: i386: Handling exception input of __builtin_ia32_prefetch. [PR117416] X-Git-Tag: basepoints/gcc-16~4601 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea46a216d48597b220ae69e79f6513c763f953be;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 6eef27f3fcda..ff07ab40848e 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -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); diff --git a/gcc/testsuite/gcc.target/i386/pr117416-1.c b/gcc/testsuite/gcc.target/i386/pr117416-1.c new file mode 100644 index 000000000000..65788f268d9d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr117416-1.c @@ -0,0 +1,13 @@ +/* PR target/117416 */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +#include + +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" } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr117416-2.c b/gcc/testsuite/gcc.target/i386/pr117416-2.c new file mode 100644 index 000000000000..07799e36cfe1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr117416-2.c @@ -0,0 +1,13 @@ +/* PR target/117416 */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +#include + +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" } */ +}