Bug 12210 - Bug in `expand_builtin_apply'
Summary: Bug in `expand_builtin_apply'
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Eric Botcazou
URL:
Keywords:
: 13531 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-09-08 15:01 UTC by Ossadchy Yury A.
Modified: 2003-12-31 18:04 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-11-24 06:16:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ossadchy Yury A. 2003-09-08 15:01:18 UTC
BUGREPORT
 Ossadchy Yury A., waspcoder@mail.ru
 GCC 3.3.1 fails on test
--- CODE ---
#include <stdio.h>

__attribute__ ((regparm (0))) int fn1 (int arg1, int arg2)
{
    printf ("fn1 (%i, %i)\n", arg1, arg2);
    return -20;
}

__attribute__ ((regparm (0))) int caller (int arg1, int arg2)
{
    void * args = __builtin_apply_args ();

    printf ("caller (%i, %i)\n", arg1, arg2);
    __builtin_return (__builtin_apply ((void (*)())&fn1, args, sizeof (int)*2));
							    // ^^^^^^^^^^^^^^
							    // it's bad, but it must work!
							    // regparm (0)!
}

int main ()
{
    printf ("result == %i\n", caller (10, 34));
}
--- /CODE ---

gcc-2.96:
>caller (10, 34)
>fn1 (10, 34)
>result == -20
    
gcc-3.3.1:
>caller (10, 34)
>fn1 (1074217344, 1075033152)
>result == -20

gcc -v:
>Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
>Configured with: ../gcc-3.3.1/configure --enable-languages=c objc++
>Thread model: posix
>gcc version 3.3.1

NOTE: include somewhat like my test into `testsuite'!

Problem is in `builtins.c::expand_builtin_apply', when pushing parameters.
Simplest `bugfix':
  /* WASP: dest = allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
           does NOT works, use this:  */
  dest = push_block (argsize, 0, 1);
Comment 1 Ossadchy Yury A. 2003-09-08 15:03:15 UTC
 BUGREPORT
 Ossadchy Yury A., waspcoder@mail.ru
 GCC 3.3.1 fails on test
--- CODE ---
#include <stdio.h>

__attribute__ ((regparm (0))) int fn1 (int arg1, int arg2)
{
    printf ("fn1 (%i, %i)\n", arg1, arg2);
    return -20;
}

__attribute__ ((regparm (0))) int caller (int arg1, int arg2)
{
    void * args = __builtin_apply_args ();

    printf ("caller (%i, %i)\n", arg1, arg2);
    __builtin_return (__builtin_apply ((void (*)())&fn1, args, sizeof (int)*2));
							    // ^^^^^^^^^^^^^^
							    // it's bad, but it must work!
							    // regparm (0)!
}

int main ()
{
    printf ("result == %i\n", caller (10, 34));
}
--- /CODE ---

gcc-2.96:
>caller (10, 34)
>fn1 (10, 34)
>result == -20
    
gcc-3.3.1:
>caller (10, 34)
>fn1 (1074217344, 1075033152)
>result == -20

gcc -v:
>Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
>Configured with: ../gcc-3.3.1/configure --enable-languages=c objc++
>Thread model: posix
>gcc version 3.3.1

NOTE: include somewhat like my test into `testsuite'!

Problem is in `builtins.c::expand_builtin_apply', when pushing parameters.
Simplest `bugfix':
  /* WASP: dest = allocate_dynamic_stack_space (argsize, 0, BITS_PER_UNIT);
           does NOT works, use this:  */
  dest = push_block (argsize, 0, 1);
Comment 2 Andrew Pinski 2003-09-08 15:07:04 UTC
I want to say this is the same bug as PR 9890 but I do not know.
Comment 3 Eric Botcazou 2003-11-24 06:16:48 UTC
__builtin_apply is indeed broken.
Comment 4 Eric Botcazou 2003-11-24 06:17:28 UTC
I'm already in this business :-)
Comment 5 Eric Botcazou 2003-11-25 18:51:23 UTC
I don't think the fix is right, since push_block statically allocates memory on
the stack while we really want to dynamically allocate in this case.
Comment 6 Eric Botcazou 2003-11-27 06:24:28 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-10/msg00897.html
Comment 7 Eric Botcazou 2003-12-31 18:04:39 UTC
*** Bug 13531 has been marked as a duplicate of this bug. ***