TR : Possible GCC bug on m68k

Chris Johns chrisj at rtems.org
Wed Nov 3 03:08:12 UTC 2004


etienne.fortin at sensio.tv wrote:
> Hi Chris,
> I may be mystaken, but your example is not valid since char and short
> varargs are promoted to int. This is from the opengroup web site on
> varargs.h:
> 
> "
> C language converts type char and short arguments to int and converts type
> float arguments to double before passing them to a function.
> "
> 
> So the promotion to int, in your example, is not from the ~ operator but
> from the fact that varargs are promoted to int.
> 

Hmmm. What about this example:

/* m68k-rtems-gcc -g -c -o comp.o comp.c */
#include <stdio.h>
int main ()
{
         unsigned char l = 0xff;
         unsigned char r = 0;
         if (l == ~r)
                 printf ("i) yes\n");
         else
                 printf ("i) no\n");
         if (l == (unsigned char) ~r)
                 printf ("ii) yes\n");
         else
                 printf ("ii) no\n");
         return 0;
}

The result on Linux is :

$ ./comp
i) no
ii) yes

and the m68k code is:

00000000 <main>:
main():
/opt/users/cjohns/src/test/comp.c:4
/* m68k-rtems-gcc -g -c -o comp.o comp.c */
#include <stdio.h>
int main ()
{
    0:   4e56 fffc       linkw %fp,#-4
comp.c:5
         unsigned char l = 0xff;
    4:   50ee ffff       st %fp@(-1)
comp.c:6
         unsigned char r = 0;
    8:   422e fffe       clrb %fp@(-2)
comp.c:7
         if (l == ~r)
    c:   4280            clrl %d0
    e:   102e ffff       moveb %fp@(-1),%d0
   12:   4281            clrl %d1
   14:   122e fffe       moveb %fp@(-2),%d1
   18:   4681            notl %d1
   1a:   b280            cmpl %d0,%d1
   1c:   6610            bnes 2e <main+0x2e>
comp.c:8
                 printf ("i) yes\n");
   1e:   4879 0000 0000  pea 0 <main>
   24:   61ff 0000 0000  bsrl 26 <main+0x26>
   2a:   588f            addql #4,%sp
   2c:   600e            bras 3c <main+0x3c>
comp.c:10
         else
                 printf ("i) no\n");
   2e:   4879 0000 0000  pea 0 <main>
   34:   61ff 0000 0000  bsrl 36 <main+0x36>
   3a:   588f            addql #4,%sp
comp.c:11
         if (l == (unsigned char) ~r)
   3c:   102e fffe       moveb %fp@(-2),%d0
   40:   4600            notb %d0
   42:   b02e ffff       cmpb %fp@(-1),%d0  <-- compare byte
   46:   6610            bnes 58 <main+0x58>
comp.c:12
                 printf ("ii) yes\n");
   48:   4879 0000 0000  pea 0 <main>
   4e:   61ff 0000 0000  bsrl 50 <main+0x50>
   54:   588f            addql #4,%sp
   56:   600e            bras 66 <main+0x66>
comp.c:14
         else
                 printf ("ii) no\n");
   58:   4879 0000 0000  pea 0 <main>
   5e:   61ff 0000 0000  bsrl 60 <main+0x60>
   64:   588f            addql #4,%sp
comp.c:15
         return 0;
   66:   4280            clrl %d0
comp.c:16
}
   68:   4e5e            unlk %fp
   6a:   4e75            rts

-- 
  Chris Johns



More information about the users mailing list