]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix up RTL sharing bug in aarch64_load_symref_appropriately [PR104910]
authorJakub Jelinek <jakub@redhat.com>
Wed, 16 Mar 2022 10:04:16 +0000 (11:04 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 16 Mar 2022 10:04:16 +0000 (11:04 +0100)
We unshare all RTL created during expansion, but when
aarch64_load_symref_appropriately is called after expansion like in the
following testcases, we use imm in both HIGH and LO_SUM operands.
If imm is some RTL that shouldn't be shared like a non-sharable CONST,
we get at least with --enable-checking=rtl a checking ICE, otherwise might
just get silently wrong code.

The following patch fixes that by copying it if it can't be shared.

2022-03-16  Jakub Jelinek  <jakub@redhat.com>

PR target/104910
* config/aarch64/aarch64.cc (aarch64_load_symref_appropriately): Copy
imm rtx.

* gcc.dg/pr104910.c: New test.

gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.dg/pr104910.c [new file with mode: 0644]

index dbeaaf484dbc070ae3fcc08530ec9bd20b8ab651..7a0337591f52a4666710c194ee00ee1e0092f044 100644 (file)
@@ -3971,7 +3971,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
        if (can_create_pseudo_p ())
          tmp_reg = gen_reg_rtx (mode);
 
-       emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
+       emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, copy_rtx (imm)));
        emit_insn (gen_add_losym (dest, tmp_reg, imm));
        return;
       }
diff --git a/gcc/testsuite/gcc.dg/pr104910.c b/gcc/testsuite/gcc.dg/pr104910.c
new file mode 100644 (file)
index 0000000..10fed81
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR target/104910 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fno-forward-propagate" } */
+/* { dg-additional-options "-fstack-protector-all" { target fstack_protector } } */
+
+void
+bar (void);
+
+void
+foo (int x)
+{
+  if (x)
+    bar ();
+}