Advertisement

GCC 3.3 - 3.4.. regparm problems [solved]

Started by November 04, 2004 09:42 AM
1 comment, last by Winograd 20 years, 2 months ago
Hi! I have succesfully used regparm attribute in function declarations when compiling with gcc 3.3.2. Then I switched to gcc 3.4.2 and things seem to have changed, because in 3.4.2 my code does not compile. Here's some code: test.c

int c;
int d;
void test(int a, int b) __attribute__ ((regparm(3)));

void test(int a, int b)
{
        c = a + b;
}

int main(void)
{
        test(c,d);
        return 0;
}


I compile this with gcc 3.3.2 like this: gcc test.c -S and I receive asm dump as I should.. great. Here's that:

        .file   "test.c"
        .text
.globl test
        .type   test, @function
test:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    %eax, -4(%ebp)
        movl    %edx, -8(%ebp)
        movl    -8(%ebp), %eax
        addl    -4(%ebp), %eax
        movl    %eax, c
        leave
        ret
        .size   test, .-test
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        subl    %eax, %esp
        movl    d, %edx
        movl    c, %eax
        call    test
        movl    $0, %eax
        leave
        ret
        .size   main, .-main
        .comm   c,4,4
        .comm   d,4,4
        .ident  "GCC: (GNU) 3.3.2"


Clearly it passes parameters for test in registers eax and edx and test clearly receives it's parameters correctly. Fine.. Now switch to 3.4.2: gcc test.c -S test.c:6: error: conflicting types for 'test' test.c:3: error: previous declaration of 'test' was here test.c:6: error: conflicting types for 'test' test.c:3: error: previous declaration of 'test' was here What happened? Only way around this is to use -mregparm=3 switch. This implies that ALL calls should be made with that calling convention, including ones to the libraries. Not good. So finally, my question is: What I have missed? Why regparm attribute does not work anymore as it used to? Thanks in advance! I'm really lost with this. [Edited by - Winograd on November 5, 2004 12:36:59 AM]
gcc 3.3 wants it on at least the prototype.

gcc 2.4 wants it on both prototype and defintion.

And I'd suggest doing some #define magic there.

#define RP3 __attribute__ ((regparm(3)))
Advertisement
Thanks, I thought something like that also. I tried to use __attribute__ in definition like this:

void test(int a,int b) __attribute__ ((regparm(3))){    ...}


And obviously it didn't work and I stopped trying. This instead does work and thanks to C-Junkie I decided to give it a try.

void __attribute__ ((regparm(3))) test(int a,int b) {    ...}


Wonder why they (gcc developers) haven't documented this change. On info pages they just mention that regparm is used with declarations.

This topic is closed to new replies.

Advertisement