]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Handling exception input of __builtin_ia32_prefetch. [PR117416]
authorHu, Lin1 <lin1.hu@intel.com>
Mon, 4 Nov 2024 06:52:56 +0000 (14:52 +0800)
committerHu, Lin1 <lin1.hu@intel.com>
Tue, 5 Nov 2024 07:52:42 +0000 (15:52 +0800)
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.

gcc/config/i386/i386-expand.cc
gcc/testsuite/gcc.target/i386/pr117416-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr117416-2.c [new file with mode: 0644]

index 6eef27f3fcda2f50d71b593e0d78065ad35796ba..ff07ab40848e887b6d9209c3263b03d01ce1cd16 100644 (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);
diff --git a/gcc/testsuite/gcc.target/i386/pr117416-1.c b/gcc/testsuite/gcc.target/i386/pr117416-1.c
new file mode 100644 (file)
index 0000000..65788f2
--- /dev/null
@@ -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" } */
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr117416-2.c b/gcc/testsuite/gcc.target/i386/pr117416-2.c
new file mode 100644 (file)
index 0000000..07799e3
--- /dev/null
@@ -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" } */
+}