[SPARC] Make sure that jump is to a label in errata workaround

Message ID 20171211091625.25042-1-cederman@gaisler.com
State New
Headers show
Series
  • [SPARC] Make sure that jump is to a label in errata workaround
Related show

Commit Message

Daniel Cederman Dec. 11, 2017, 9:16 a.m.
In some cases the jump could be to a return instruction and in those
cases the next_active_insn() function tries to follow an invalid pointer
which leads to a crash. This error did not manifest when using a 32-bit
version of GCC which is why I did not detect it before. Thanks to Sebastian
for reporting this to me.

gcc/ChangeLog:

2017-12-11  Daniel Cederman  <cederman@gaisler.com>

	* config/sparc/sparc.c (sparc_do_work_around_errata): Make sure
	the jump is to a label.
---
 gcc/config/sparc/sparc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.9.3

Comments

Eric Botcazou Dec. 11, 2017, 10:35 a.m. | #1
> 2017-12-11  Daniel Cederman  <cederman@gaisler.com>

> 

> 	* config/sparc/sparc.c (sparc_do_work_around_errata): Make sure

> 	the jump is to a label.


OK for mainline and 7 branch, thanks.

-- 
Eric Botcazou

Patch

diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index 00b90e5..b9c8dcc 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -1032,6 +1032,7 @@  sparc_do_work_around_errata (void)
 	 floating-point operation or a floating-point branch.  */
       if (sparc_fix_gr712rc
 	  && jump
+	  && jump_to_label_p (jump)
 	  && get_attr_branch_type (jump) == BRANCH_TYPE_ICC)
 	{
 	  rtx_insn *target = next_active_insn (JUMP_LABEL_AS_INSN (jump));
@@ -1051,7 +1052,7 @@  sparc_do_work_around_errata (void)
 	  && mem_ref (SET_SRC (set))
 	  && REG_P (SET_DEST (set)))
 	{
-	  if (jump)
+	  if (jump && jump_to_label_p (jump))
 	    {
 	      rtx_insn *target = next_active_insn (JUMP_LABEL_AS_INSN (jump));
 	      if (target && atomic_insn_for_leon3_p (target))