[avr] Fix PR60991

Submitted by Senthil Kumar Selvaraj on May 12, 2014, 10:17 a.m.

Details

Message ID 20140512101714.GB1830@atmel.com
State New
Headers show

Commit Message

Senthil Kumar Selvaraj May 12, 2014, 10:17 a.m.
This trivial patch fixes PR60991 by correcting the constant used to
restore Y in one of the assembler template variants used in avr_out_store_psi.
I've also added a testcase (modified from the original poster's code).

If ok, could someone commit please? I don't have commit access. It would
be great if this was also committed to 4.9 and 4.8 branches as well.

Regards
Senthil

gcc/ChangeLog

2014-05-12  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR target/60991
	* config/avr/avr.c (avr_out_store_psi): Use correct constant
	to restore Y.

gcc/testsuite/ChangeLog
2014-05-12  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR target/60991
	* gcc.target/avr/pr60991.c: New testcase.

Comments

Denis Chertykov May 12, 2014, 4:08 p.m.
2014-05-12 14:17 GMT+04:00 Senthil Kumar Selvaraj
<senthil_kumar.selvaraj@atmel.com>:
> This trivial patch fixes PR60991 by correcting the constant used to
> restore Y in one of the assembler template variants used in avr_out_store_psi.
> I've also added a testcase (modified from the original poster's code).
>
> If ok, could someone commit please? I don't have commit access. It would
> be great if this was also committed to 4.9 and 4.8 branches as well.

Committed and backported to 4.9 and 4.8

Denis.

Patch hide | download patch | download mbox

diff --git gcc/config/avr/avr.c gcc/config/avr/avr.c
index 536fe68..fc6c9f6 100644
--- gcc/config/avr/avr.c
+++ gcc/config/avr/avr.c
@@ -3999,7 +3999,7 @@  avr_out_store_psi (rtx insn, rtx *op, int *plen)
                                 "std Y+61,%A1"    CR_TAB
                                 "std Y+62,%B1"    CR_TAB
                                 "std Y+63,%C1"    CR_TAB
-                                "sbiw r28,%o0-60", op, plen, -5);
+                                "sbiw r28,%o0-61", op, plen, -5);
 
           return avr_asm_len ("subi r28,lo8(-%o0)" CR_TAB
                               "sbci r29,hi8(-%o0)" CR_TAB
diff --git gcc/testsuite/gcc.target/avr/pr60991.c gcc/testsuite/gcc.target/avr/pr60991.c
new file mode 100644
index 0000000..a09f42a
--- /dev/null
+++ gcc/testsuite/gcc.target/avr/pr60991.c
@@ -0,0 +1,21 @@ 
+/* { dg-do run } */
+/* { dg-options "-O1" } */
+
+/* This testcase (simplified from the original bug report) exposes 
+   PR60991. The code generated for writing the __int24 value corrupts
+   the frame pointer if the offset is <= 63 + MAX_LD_OFFSET */
+
+#include <stdlib.h>
+
+int main(void)
+{
+    volatile char junk[62];
+    junk[0] = 5;
+    volatile __int24 staticConfig = 0;
+
+    if (junk[0] != 5)
+      abort();
+
+    exit(0);
+    return 0;
+}