alpha.c (alpha_does_function_need_gp): Return true if the function contains a nonloca...
authorRichard Henderson <rth@gcc.gnu.org>
Fri, 5 Dec 2003 11:21:48 +0000 (03:21 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Fri, 5 Dec 2003 11:21:48 +0000 (03:21 -0800)
        * config/alpha/alpha.c (alpha_does_function_need_gp): Return
        true if the function contains a nonlocal goto.
* gcc.c-torture/execute/nestfunc-6.c: New.

From-SVN: r74327

gcc/config/alpha/alpha.c
gcc/testsuite/gcc.c-torture/execute/nestfunc-6.c [new file with mode: 0644]

index 0d59c343d843607fe8df7ec7d68e74bc16bac6ba..c540d5a50805f1175ea47bfc9a028c0f7250dc54 100644 (file)
@@ -6926,12 +6926,21 @@ alpha_does_function_need_gp (void)
   if (! TARGET_ABI_OSF)
     return 0;
 
+  /* We need the gp to load the address of __mcount.  */
   if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
     return 1;
 
+  /* The code emitted by alpha_output_mi_thunk_osf uses the gp.  */
   if (current_function_is_thunk)
     return 1;
 
+  /* The nonlocal receiver pattern assumes that the gp is valid for
+     the nested function.  Reasonable because it's almost always set
+     correctly already.  For the cases where that's wrong, make sure
+     the nested function loads its gp on entry.  */
+  if (current_function_has_nonlocal_goto)
+    return 1;
+
   /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
      Even if we are a static function, we still need to do this in case
      our address is taken and passed to something like qsort.  */
diff --git a/gcc/testsuite/gcc.c-torture/execute/nestfunc-6.c b/gcc/testsuite/gcc.c-torture/execute/nestfunc-6.c
new file mode 100644 (file)
index 0000000..c8e8243
--- /dev/null
@@ -0,0 +1,29 @@
+/* Test that the GP gets properly restored, either by the nonlocal
+   receiver or the nested function.  */
+
+#ifndef NO_TRAMPOLINES
+
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+extern void exit (int);
+extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
+
+int main ()
+{
+  __label__ nonlocal;
+  int compare (const void *a, const void *b)
+  {
+    goto nonlocal;
+  }
+
+  char array[3];
+  qsort (array, 3, 1, compare);
+  abort ();
+
+ nonlocal:
+  exit (0);
+}
+
+#else
+int main() { return 0; }
+#endif