]> gcc.gnu.org Git - gcc.git/commitdiff
re PR target/5755 (-mregparm=3 and -fomit-frame-pointer corrupt esp register)
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Feb 2002 22:49:44 +0000 (23:49 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Feb 2002 22:49:44 +0000 (23:49 +0100)
PR target/5755
* config/i386/i386.c (ix86_return_pops_args): Only pop
fake structure return argument if it was passed on the stack.

* gcc.dg/20020224-1.c: New test.

From-SVN: r50028

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20020224-1.c [new file with mode: 0644]

index f2faf55a6529f4d5d5b77f880d5c97cbea6b05d2..8925413080d5f55bf6191a2bbb4a55317a9532fe 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/5755
+       * config/i386/i386.c (ix86_return_pops_args): Only pop
+       fake structure return argument if it was passed on the stack.
+
 2002-02-25  Jason Merrill  <jason@redhat.com>
 
        * attribs.c (decl_attributes): Also re-layout PARM_DECL and
index 009b5d8511bc02c6b63d164bea3f4b0b92f60e6d..fc78c57ec5cf463660f2adb7652c69ab4cb33d41 100644 (file)
@@ -1466,12 +1466,25 @@ ix86_return_pops_args (fundecl, funtype, size)
       return size;
   }
 
-  /* Lose any fake structure return argument.  */
+  /* Lose any fake structure return argument if it is passed on the stack.  */
   if (aggregate_value_p (TREE_TYPE (funtype))
       && !TARGET_64BIT)
-    return GET_MODE_SIZE (Pmode);
+    {
+      int nregs = ix86_regparm;
 
-    return 0;
+      if (funtype)
+       {
+         tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (funtype));
+
+         if (attr)
+           nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
+       }
+
+      if (!nregs)
+       return GET_MODE_SIZE (Pmode);
+    }
+
+  return 0;
 }
 \f
 /* Argument support functions.  */
index 8d445c87f258522c5d164c601817b2d5da11c795..393aec7b9c76f522bd65c29a9050857ed83af03f 100644 (file)
@@ -1,3 +1,7 @@
+2002-02-25  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.dg/20020224-1.c: New test.
+
 2002-02-25  Alan Modra  <amodra@bigpond.net.au>
 
        * gcc.c-torture/execute/20020225-1.c: New.
diff --git a/gcc/testsuite/gcc.dg/20020224-1.c b/gcc/testsuite/gcc.dg/20020224-1.c
new file mode 100644 (file)
index 0000000..a286b6b
--- /dev/null
@@ -0,0 +1,41 @@
+/* PR target/5755
+   This testcase failed because the caller of a function returning struct
+   expected the callee to pop up the hidden return structure pointer,
+   while callee was actually not poping it up (as the hidden argument
+   was passed in register).  */
+/* { dg-do run { target i?86-*-* } } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
+
+extern void abort (void);
+extern void exit (int);
+
+typedef struct {
+   int a1, a2;
+} A;
+
+A a;
+
+A __attribute__ ((regparm (2)))
+foo (int x)
+{
+  return a;
+}
+
+int __attribute__ ((regparm (2)))
+bar (int x)
+{
+  int r = foo(0).a2;
+  return r;
+}
+
+int
+main ()
+{
+  int f;
+  a.a1 = 530;
+  a.a2 = 980;
+  f = bar (0);
+  if (f != 980)
+    abort ();
+  exit (0);
+}
This page took 0.109812 seconds and 5 git commands to generate.