[gcc r12-10980] arm: Handle fixed PIC register in require_pic_register (PR target/115485)

Christophe Lyon clyon@gcc.gnu.org
Fri Mar 7 10:45:29 GMT 2025


https://gcc.gnu.org/g:149b38a44d041d3b4142f50a9b2d6e1190df3b11

commit r12-10980-g149b38a44d041d3b4142f50a9b2d6e1190df3b11
Author: Christophe Lyon <christophe.lyon@linaro.org>
Date:   Mon Mar 3 11:12:18 2025 +0000

    arm: Handle fixed PIC register in require_pic_register (PR target/115485)
    
    Commit r9-4307-g89d7557202d25a forgot to accept a fixed PIC register
    when extending the assert in require_pic_register.
    
    arm_pic_register can be set explicitly by the user
    (e.g. -mpic-register=r9) or implicitly as the default value with
    -fpic/-fPIC/-fPIE and -mno-pic-data-is-text-relative -mlong-calls, and
    we want to use/accept it when recording cfun->machine->pic_reg as used
    to be the case.
    
            PR target/115485
            gcc/
            * config/arm/arm.cc (require_pic_register): Fix typos in
            comment. Handle fixed arm_pic_register.
    
            gcc/testsuite/
            * g++.target/arm/pr115485.C: New test.
    
    (cherry picked from commit b1d0ac28de643e7c810e407a0668737131cdcc00)

Diff:
---
 gcc/config/arm/arm.cc                   |  5 +++--
 gcc/testsuite/g++.target/arm/pr115485.C | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index afaa599b6f0f..f6f0e88ed156 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -7954,8 +7954,8 @@ legitimate_pic_operand_p (rtx x)
 
 /* Record that the current function needs a PIC register.  If PIC_REG is null,
    a new pseudo is allocated as PIC register, otherwise PIC_REG is used.  In
-   both case cfun->machine->pic_reg is initialized if we have not already done
-   so.  COMPUTE_NOW decide whether and where to set the PIC register.  If true,
+   both cases cfun->machine->pic_reg is initialized if we have not already done
+   so.  COMPUTE_NOW decides whether and where to set the PIC register.  If true,
    PIC register is reloaded in the current position of the instruction stream
    irregardless of whether it was loaded before.  Otherwise, it is only loaded
    if not already done so (crtl->uses_pic_offset_table is null).  Note that
@@ -7975,6 +7975,7 @@ require_pic_register (rtx pic_reg, bool compute_now)
   if (!crtl->uses_pic_offset_table || compute_now)
     {
       gcc_assert (can_create_pseudo_p ()
+		  || (arm_pic_register != INVALID_REGNUM)
 		  || (pic_reg != NULL_RTX
 		      && REG_P (pic_reg)
 		      && GET_MODE (pic_reg) == Pmode));
diff --git a/gcc/testsuite/g++.target/arm/pr115485.C b/gcc/testsuite/g++.target/arm/pr115485.C
new file mode 100644
index 000000000000..491b48c726a1
--- /dev/null
+++ b/gcc/testsuite/g++.target/arm/pr115485.C
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-fPIE -mno-pic-data-is-text-relative -mlong-calls -ffunction-sections" } */
+
+struct c1 {
+  virtual void func1() = 0;
+};
+struct  c2 {
+  virtual ~c2() {}
+};
+struct c3 : c2, c1 {
+  void func1() override;
+  void func3();
+};
+void c3::func1() {
+  func3();
+}


More information about the Gcc-cvs mailing list