]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix out-of-bounds ENCODED_ELT access [PR113572]
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 25 Jan 2024 12:03:18 +0000 (12:03 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 25 Jan 2024 12:03:18 +0000 (12:03 +0000)
When generalising vector_cst_all_same, I'd forgotten to update
VECTOR_CST_ENCODED_ELT to VECTOR_CST_ELT.  The check deliberately
looks at implicitly encoded elements in some cases.

gcc/
PR target/113572
* config/aarch64/aarch64-sve-builtins.cc (vector_cst_all_same):
Check VECTOR_CST_ELT instead of VECTOR_CST_ENCODED_ELT

gcc/testsuite/
PR target/113572
* gcc.target/aarch64/sve/pr113572.c: New test.

gcc/config/aarch64/aarch64-sve-builtins.cc
gcc/testsuite/gcc.target/aarch64/sve/pr113572.c [new file with mode: 0644]

index c2f1486315f02c3e38f808b3124a9b4cf49a4708..11f5c5c500c8331094933cb1c1205a1360eca79b 100644 (file)
@@ -3474,7 +3474,7 @@ vector_cst_all_same (tree v, unsigned int step)
   unsigned int nelts = lcm * VECTOR_CST_NELTS_PER_PATTERN (v);
   tree first_el = VECTOR_CST_ENCODED_ELT (v, 0);
   for (unsigned int i = 0; i < nelts; i += step)
-    if (!operand_equal_p (VECTOR_CST_ENCODED_ELT (v, i), first_el, 0))
+    if (!operand_equal_p (VECTOR_CST_ELT (v, i), first_el, 0))
       return false;
 
   return true;
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr113572.c b/gcc/testsuite/gcc.target/aarch64/sve/pr113572.c
new file mode 100644 (file)
index 0000000..a5e6b7e
--- /dev/null
@@ -0,0 +1,12 @@
+#include <arm_sve.h>
+
+uint64_t u;
+struct S { int i; } he;
+
+void
+foo ()
+{
+  svuint64_t vld_clz = svld1_u64 (svwhilelt_b64 (0, 4), (uint64_t *) &he);
+  vld_clz = svclz_u64_z (svwhilelt_b64 (0, 1), vld_clz);
+  svst1_u64 (svwhilelt_b64 (0, 1), &u, vld_clz);
+}