Hi, all

__builtin_ia32_prefetch's op1 should be between 0 and 2. So add an error 
handler.

Bootstrapped and regtested on x86_64-pc-linux-gnu, there is a unrelated FAIL
that has yet to be found root cause, just send patch for review.

BRs,
Lin

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;

gcc/testsuite/ChangeLog:

        PR target/117416
        * gcc.target/i386/pr117416-1.c: New test.
---
 gcc/config/i386/i386-expand.cc             |  7 +++++++
 gcc/testsuite/gcc.target/i386/pr117416-1.c | 12 ++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr117416-1.c

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 515334aa5a3..5dab5859463 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -14194,6 +14194,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)
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 00000000000..7062f27e21a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr117416-1.c
@@ -0,0 +1,12 @@
+/* { 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" } */
+}
-- 
2.31.1

Reply via email to