Darwin : Fix out-of-bounds access to df_regs_ever_live.
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 3 Apr 2021 09:07:48 +0000 (10:07 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sat, 3 Apr 2021 20:28:15 +0000 (21:28 +0100)
During changes made for LRA (or, perhaps, even before) we omitted
a check that the current register we are working on is a hard reg
before we tried to note its liveness.

A stage 1 built with fsanitize=address catches this, as does any
attempt to build master with clang and -std=c++11.

gcc/ChangeLog:

* config/darwin.c (machopic_legitimize_pic_address): Check
that the current pic register is one of the hard reg set
before setting liveness.

gcc/config/darwin.c

index c1086a0..5d17391 100644 (file)
@@ -907,7 +907,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg)
                  pic = reg;
                }
 
-             if (lra_in_progress)
+             if (lra_in_progress && HARD_REGISTER_P (pic))
                df_set_regs_ever_live (REGNO (pic), true);
              pic_ref = gen_rtx_PLUS (Pmode, pic,
                                      machopic_gen_offset (XEXP (orig, 0)));
@@ -974,7 +974,8 @@ machopic_legitimize_pic_address (rtx orig, machine_mode mode, rtx reg)
                      emit_move_insn (reg, pic);
                      pic = reg;
                    }
-                 if (lra_in_progress)
+
+                 if (lra_in_progress && HARD_REGISTER_P (pic))
                    df_set_regs_ever_live (REGNO (pic), true);
                  pic_ref = gen_rtx_PLUS (Pmode,
                                          pic,