arm.c (thumb_find_work_register): Check argument register number based on current...
authorTerry Guo <terry.guo@arm.com>
Wed, 19 Dec 2012 11:40:52 +0000 (11:40 +0000)
committerXuepeng Guo <xguo@gcc.gnu.org>
Wed, 19 Dec 2012 11:40:52 +0000 (11:40 +0000)
gcc/ChangeLog:

2012-12-19  Terry Guo  <terry.guo@arm.com>

        * config/arm/arm.c (thumb_find_work_register): Check argument
        register number based on current PCS.

gcc/testsuite/ChangeLog:

2012-12-19  Terry Guo  <terry.guo@arm.com>

        * gcc.target/arm/thumb-find-work-register.c: New.

From-SVN: r194605

gcc/ChangeLog
gcc/config/arm/arm.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/thumb-find-work-register.c [new file with mode: 0644]

index 7b103fe..5c6c840 100644 (file)
@@ -1,3 +1,8 @@
+2012-12-19  Terry Guo  <terry.guo@arm.com>
+
+       * config/arm/arm.c (thumb_find_work_register): Check argument
+       register number based on current PCS.
+
 2012-12-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/55562
index 84ce56f..15f9c9b 100644 (file)
@@ -5566,7 +5566,9 @@ thumb_find_work_register (unsigned long pushed_regs_mask)
   if (! cfun->machine->uses_anonymous_args
       && crtl->args.size >= 0
       && crtl->args.size <= (LAST_ARG_REGNUM * UNITS_PER_WORD)
-      && crtl->args.info.nregs < 4)
+      && (TARGET_AAPCS_BASED
+         ? crtl->args.info.aapcs_ncrn < 4
+         : crtl->args.info.nregs < 4))
     return LAST_ARG_REGNUM;
 
   /* Otherwise look for a call-saved register that is going to be pushed.  */
index f5a9835..6719b29 100644 (file)
@@ -1,3 +1,7 @@
+2012-12-19  Terry Guo  <terry.guo@arm.com>
+
+       * gcc.target/arm/thumb-find-work-register.c: New.
+
 2012-12-19  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/55733
diff --git a/gcc/testsuite/gcc.target/arm/thumb-find-work-register.c b/gcc/testsuite/gcc.target/arm/thumb-find-work-register.c
new file mode 100644 (file)
index 0000000..f2c0225
--- /dev/null
@@ -0,0 +1,40 @@
+/* Wrong method to get number of arg reg will cause argument corruption.  */
+/* { dg-do run } */
+/* { dg-require-effective-target arm_eabi } */
+/* { dg-options "-mthumb -O1" } */
+
+extern void abort (void);
+
+int foo (int, int, int, int) __attribute__((noinline));
+
+int
+foo (int a, int b, int c, int d)
+{
+  register int m asm ("r8");
+
+  m = a;
+  m += b;
+  m += c;
+  m += d;
+
+  asm ("" : "=r" (m) : "0" (m));
+
+  return m;
+}
+
+int
+main ()
+{
+  volatile int a = 10;
+  volatile int b = 20;
+  volatile int c = 30;
+  volatile int d = 40;
+  volatile int sum = 0;
+
+  sum = foo (a, b, c, d);
+
+  if (sum != 100)
+    abort ();
+
+  return 0;
+}