public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37609]  New: Pointer arithmetic yields strange result
@ 2008-09-21 16:01 john dot spelis at 3dlabs dot com
  2008-09-21 16:03 ` [Bug c/37609] " john dot spelis at 3dlabs dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: john dot spelis at 3dlabs dot com @ 2008-09-21 16:01 UTC (permalink / raw)
  To: gcc-bugs

An expression using ptr arithmetic yields an unusual result
unless a cast is applied;
The problematic expression;
 MaxTimings = ((EDIDDetailed *) &pExt->checksum) - pDTD;
works only when cast as;
 MaxTimings = (((uintptr_t) &pExt->checksum) - ((uintptr_t)
pDTD))/sizeof(*pDTD);

This occurs on compilers back to 3.0.3 when testing on a x86. It's also present
in a cross compiler built using 4.3.0 source
Works on a Sun/Solaris compiler.
A test program is attached


-- 
           Summary: Pointer arithmetic yields strange result
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john dot spelis at 3dlabs dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/37609] Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
@ 2008-09-21 16:03 ` john dot spelis at 3dlabs dot com
  2008-09-21 16:31 ` [Bug target/37609] " rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: john dot spelis at 3dlabs dot com @ 2008-09-21 16:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from john dot spelis at 3dlabs dot com  2008-09-21 16:01 -------
Created an attachment (id=16372)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16372&action=view)
A standalone program which illustrates the problem


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/37609] Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
  2008-09-21 16:03 ` [Bug c/37609] " john dot spelis at 3dlabs dot com
@ 2008-09-21 16:31 ` rguenth at gcc dot gnu dot org
  2008-09-21 16:36 ` [Bug c/37609] New: " Andrew Thomas Pinski
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-09-21 16:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-09-21 16:29 -------
Confirmed.  This looks like a target issue to me, for bad we produce

testPtrBad:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        addl    $127, %eax
        subl    12(%ebp), %eax
        popl    %ebp
        sarl    %eax
        imull   $954437177, %eax, %eax
        ret


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |uros at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
          Component|c                           |target
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |3.3.6 4.3.2
   Last reconfirmed|0000-00-00 00:00:00         |2008-09-21 16:29:39
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug c/37609]  New: Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
  2008-09-21 16:03 ` [Bug c/37609] " john dot spelis at 3dlabs dot com
  2008-09-21 16:31 ` [Bug target/37609] " rguenth at gcc dot gnu dot org
@ 2008-09-21 16:36 ` Andrew Thomas Pinski
  2008-09-21 16:37 ` [Bug target/37609] " pinskia at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andrew Thomas Pinski @ 2008-09-21 16:36 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs



Sent from my iPhone

On Sep 21, 2008, at 9:00 AM, "john dot spelis at 3dlabs dot com" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> An expression using ptr arithmetic yields an unusual result
> unless a cast is applied;
> The problematic expression;
> MaxTimings = ((EDIDDetailed *) &pExt->checksum) - pDTD;

That is a signed division while the below is unsigned.

>
> works only when cast as;
> MaxTimings = (((uintptr_t) &pExt->checksum) - ((uintptr_t)
> pDTD))/sizeof(*pDTD);
>
> This occurs on compilers back to 3.0.3 when testing on a x86. It's  
> also present
> in a cross compiler built using 4.3.0 source
> Works on a Sun/Solaris compiler.
> A test program is attached
>
>
> -- 
>           Summary: Pointer arithmetic yields strange result
>           Product: gcc
>           Version: 4.3.0
>            Status: UNCONFIRMED
>          Severity: normal
>          Priority: P3
>         Component: c
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: john dot spelis at 3dlabs dot com
> GCC build triplet: i686-pc-linux-gnu
>  GCC host triplet: i686-pc-linux-gnu
> GCC target triplet: i686-pc-linux-gnu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/37609] Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
                   ` (2 preceding siblings ...)
  2008-09-21 16:36 ` [Bug c/37609] New: " Andrew Thomas Pinski
@ 2008-09-21 16:37 ` pinskia at gmail dot com
  2008-09-22 19:55 ` [Bug c/37609] " pinskia at gcc dot gnu dot org
  2008-09-22 20:41 ` john dot spelis at 3dlabs dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gmail dot com @ 2008-09-21 16:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gmail dot com  2008-09-21 16:36 -------
Subject: Re:   New: Pointer arithmetic yields strange result



Sent from my iPhone

On Sep 21, 2008, at 9:00 AM, "john dot spelis at 3dlabs dot com"
<gcc-bugzilla@gcc.gnu.org 
 > wrote:

> An expression using ptr arithmetic yields an unusual result
> unless a cast is applied;
> The problematic expression;
> MaxTimings = ((EDIDDetailed *) &pExt->checksum) - pDTD;

That is a signed division while the below is unsigned.

>
> works only when cast as;
> MaxTimings = (((uintptr_t) &pExt->checksum) - ((uintptr_t)
> pDTD))/sizeof(*pDTD);
>
> This occurs on compilers back to 3.0.3 when testing on a x86. It's  
> also present
> in a cross compiler built using 4.3.0 source
> Works on a Sun/Solaris compiler.
> A test program is attached
>
>
> -- 
>           Summary: Pointer arithmetic yields strange result
>           Product: gcc
>           Version: 4.3.0
>            Status: UNCONFIRMED
>          Severity: normal
>          Priority: P3
>         Component: c
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: john dot spelis at 3dlabs dot com
> GCC build triplet: i686-pc-linux-gnu
>  GCC host triplet: i686-pc-linux-gnu
> GCC target triplet: i686-pc-linux-gnu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/37609] Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
                   ` (3 preceding siblings ...)
  2008-09-21 16:37 ` [Bug target/37609] " pinskia at gmail dot com
@ 2008-09-22 19:55 ` pinskia at gcc dot gnu dot org
  2008-09-22 20:41 ` john dot spelis at 3dlabs dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-22 19:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2008-09-22 19:54 -------
This is invalid code as the difference between  ((EDIDDetailed *)
&pExt->checksum) - pDTD is 88 which is not a multiple of 18.  This happens the
same way on powerpc.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
          Component|target                      |c
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/37609] Pointer arithmetic yields strange result
  2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
                   ` (4 preceding siblings ...)
  2008-09-22 19:55 ` [Bug c/37609] " pinskia at gcc dot gnu dot org
@ 2008-09-22 20:41 ` john dot spelis at 3dlabs dot com
  5 siblings, 0 replies; 7+ messages in thread
From: john dot spelis at 3dlabs dot com @ 2008-09-22 20:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from john dot spelis at 3dlabs dot com  2008-09-22 20:40 -------
Subject: Re:  Pointer arithmetic yields strange result


Apologies; never realised that pointer arithmetic was defined
in that fashion (i.e. must always be a multiple of the object size).
Sorry to have bothered you.
Best Regards.



On 22 Sep 2008, pinskia at gcc dot gnu dot org wrote:

> 
> 
> ------- Comment #4 from pinskia at gcc dot gnu dot org  2008-09-22 19:54 -------
> This is invalid code as the difference between  ((EDIDDetailed *)
> &pExt->checksum) - pDTD is 88 which is not a multiple of 18.  This happens the
> same way on powerpc.
> 
> 
> -- 
> 
> pinskia at gcc dot gnu dot org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|NEW                         |RESOLVED
>           Component|target                      |c
>          Resolution|                            |INVALID
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37609


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-09-22 20:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-21 16:01 [Bug c/37609] New: Pointer arithmetic yields strange result john dot spelis at 3dlabs dot com
2008-09-21 16:03 ` [Bug c/37609] " john dot spelis at 3dlabs dot com
2008-09-21 16:31 ` [Bug target/37609] " rguenth at gcc dot gnu dot org
2008-09-21 16:36 ` [Bug c/37609] New: " Andrew Thomas Pinski
2008-09-21 16:37 ` [Bug target/37609] " pinskia at gmail dot com
2008-09-22 19:55 ` [Bug c/37609] " pinskia at gcc dot gnu dot org
2008-09-22 20:41 ` john dot spelis at 3dlabs dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).