]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
arm: fully validate mem_noofs_operand [PR120351]
authorRichard Earnshaw <rearnsha@arm.com>
Mon, 19 May 2025 15:19:39 +0000 (16:19 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 1 Aug 2025 07:37:57 +0000 (09:37 +0200)
It's not enough to just check that a memory operand is of the form
mem(reg); after RA we also need to validate the register being used.
The safest way to do this is to call memory_operand.

PR target/120351

gcc/ChangeLog:

* config/arm/predicates.md (mem_noofs_operand): Also check the op
is a valid memory_operand.

gcc/testsuite/ChangeLog:

* gcc.target/arm/pr120351.c: New test.

(cherry picked from commit e5bb7a328eb71daa02d15b48d3a6c6b8cd24abc5)

gcc/config/arm/predicates.md
gcc/testsuite/gcc.target/arm/pr120351.c [new file with mode: 0644]

index 75c06d9be255257e1c6783a157a4c72274c0b234..655f60312defe02a23d69c8b6c2f4e8f947cee95 100644 (file)
 
 (define_predicate "mem_noofs_operand"
   (and (match_code "mem")
-       (match_code "reg" "0")))
+       (match_code "reg" "0")
+       (match_operand 0 "memory_operand")))
 
 (define_predicate "call_insn_operand"
   (ior (and (match_code "symbol_ref")
diff --git a/gcc/testsuite/gcc.target/arm/pr120351.c b/gcc/testsuite/gcc.target/arm/pr120351.c
new file mode 100644 (file)
index 0000000..d8e9d73
--- /dev/null
@@ -0,0 +1,47 @@
+/* { dg-do assemble } */
+/* { dg-require-effective-target arm_neon_ok } */
+/* { dg-add-options arm_neon } */
+/* { dg-additional-options "-O2" } */
+
+
+typedef struct A
+{
+  int f1;
+} A;
+
+__inline void ref (A* x)
+{
+  __atomic_fetch_add(&x->f1, 1, 0);
+}
+
+typedef struct B
+{
+  A *d;
+  int *ptr;
+} B;
+
+void insertOne (B*, B*);
+
+void init (B *);
+__inline void copy (B *p, B *q)
+{
+  p->d  = q->d;
+  p->ptr = q->ptr;
+  ref (p->d);
+}
+
+__inline void emplace(B* x)
+{
+  B dummy;
+  B _tmp;
+  init (&dummy);
+  copy (&_tmp, &dummy);
+  insertOne(x, &_tmp);
+}
+
+void testing ()
+{
+  B test;
+  init (&test);
+  emplace(&test);
+}