tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Tinycc-devel] 64bits - Wrong comparison betweenpointerandlong cste


From: Christian Jullien
Subject: RE: [Tinycc-devel] 64bits - Wrong comparison betweenpointerandlong cste
Date: Tue, 8 Dec 2009 18:55:41 +0100

I don't know if it's enough but at least this diff seems to fix the reported
bug:

*** tccgen.c    2009-12-08 18:49:50.484375000 +0100
--- tccgen.c.org        2009-12-08 18:53:19.546875000 +0100
***************
*** 1543,1549 ****
                      vtop->c.ll = vtop->c.ull;
                  else if (sbt & VT_UNSIGNED)
                      vtop->c.ll = vtop->c.ui;
!                 else if (sbt != VT_LLONG && sbt != VT_PTR )
                      vtop->c.ll = vtop->c.i;

                  if (dbt == (VT_LLONG|VT_UNSIGNED))
--- 1543,1549 ----
                      vtop->c.ll = vtop->c.ull;
                  else if (sbt & VT_UNSIGNED)
                      vtop->c.ll = vtop->c.ui;
!                 else if (sbt != VT_LLONG)
                      vtop->c.ll = vtop->c.i;

                  if (dbt == (VT_LLONG|VT_UNSIGNED))

Please review and commit change if you agree.

C.

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Christian Jullien
Sent: mardi 8 décembre 2009 08:56
To: address@hidden
Subject: RE: [Tinycc-devel] 64bits - Wrong comparison betweenpointerandlong
cste


Update, error comes from cast.

Using

        res =  (p != 0x12345678ABCD000F );
        return res;

prints a warning but returns correct result.

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Christian Jullien
Sent: mardi 8 décembre 2009 07:42
To: address@hidden
Subject: RE: [Tinycc-devel] 64bits - Wrong comparison between pointerandlong
cste


Thanks for your advice, I checked with objdump:

#include <stdio.h>

int
main(int argc, char *argv[])
{
        char *p = (char *)0x12345678ABCD000F;
        int res;

        res =  (p != (char *)0x12345678ABCD000F );
        return res;
}

Compiles to:

foo.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 81 ec 10 00 00 00    sub    $0x10,%rsp
   b:   48 89 4d 10             mov    %rcx,0x10(%rbp)
   f:   48 89 55 18             mov    %rdx,0x18(%rbp)
  13:   48 b8 0f 00 cd ab 78    movabs $0x12345678abcd000f,%rax
  1a:   56 34 12
  1d:   48 89 45 f8             mov    %rax,-0x8(%rbp)
  21:   48 8b 45 f8             mov    -0x8(%rbp),%rax
> 25:   48 b9 0f 00 cd ab ff    movabs $0xffffffffabcd000f,%rcx
  2c:   ff ff ff
  2f:   48 39 c8                cmp    %rcx,%rax
  32:   b8 00 00 00 00          mov    $0x0,%eax
  37:   0f 95 c0                setne  %al
  3a:   89 45 f4                mov    %eax,-0xc(%rbp)
  3d:   8b 45 f4                mov    -0xc(%rbp),%eax
  40:   e9 00 00 00 00          jmpq   45 <main+0x45>
  45:   c9                      leaveq
  46:   c3                      retq

You can see that line 13 mobabs correctly set %rax to $0x12345678abcd000f

But for strange reason, %rcx line 25 is set to $0xffffffffabcd000f

A slightly modified version using - instead of != use the right value:

#include <stdio.h>

int
main(int argc, char *argv[])
{
        char *p = (char *)0x12345678ABCD000F;
        int res;

        res =  (p - (char *)0x12345678ABCD000F );
        return res;
}


Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 81 ec 10 00 00 00    sub    $0x10,%rsp
   b:   48 89 4d 10             mov    %rcx,0x10(%rbp)
   f:   48 89 55 18             mov    %rdx,0x18(%rbp)
  13:   48 b8 0f 00 cd ab 78    movabs $0x12345678abcd000f,%rax
  1a:   56 34 12
  1d:   48 89 45 f8             mov    %rax,-0x8(%rbp)
  21:   48 8b 45 f8             mov    -0x8(%rbp),%rax
> 25:   48 b9 0f 00 cd ab 78    movabs $0x12345678abcd000f,%rcx
  2c:   56 34 12
  2f:   48 29 c8                sub    %rcx,%rax
  32:   89 45 f4                mov    %eax,-0xc(%rbp)
  35:   8b 45 f4                mov    -0xc(%rbp),%eax
  38:   e9 00 00 00 00          jmpq   3d <main+0x3d>
  3d:   c9                      leaveq
  3e:   c3                      retq

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
grischka
Sent: lundi 7 décembre 2009 15:55
To: address@hidden
Subject: Re: [Tinycc-devel] 64bits - Wrong comparison between pointer
andlong cste


Christian Jullien wrote:
> Q. how can I see the .s output (as generally using -S on most compilers) ?

TCC outputs machine code, not assembler.

You can disassemble it though:
$ tcc -c x.c
$ objdump -D x.o
on win64:
$ x86_64-pc-mingw32-objdump -D x.o

--- grischka


_______________________________________________
Tinycc-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel
----------------------------------------------------------------------------
-----------
Orange vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
Aucun virus connu a ce jour par nos services n'a ete detecte.








_______________________________________________
Tinycc-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel
----------------------------------------------------------------------------
-----------
Orange vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
Aucun virus connu a ce jour par nos services n'a ete detecte.








_______________________________________________
Tinycc-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel
----------------------------------------------------------------------------
-----------
Orange vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
Aucun virus connu a ce jour par nos services n'a ete detecte.










reply via email to

[Prev in Thread] Current Thread [Next in Thread]