public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/49873] New: Optimizer regression
@ 2011-07-27 16:58 abenea at gmail dot com
  2011-07-27 17:00 ` [Bug tree-optimization/49873] " pinskia at gcc dot gnu.org
  2011-07-28  9:56 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: abenea at gmail dot com @ 2011-07-27 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Optimizer regression
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: abenea@gmail.com


Test code:

typedef struct {
    char *ptr;
} S;

void f1(char* data) {
    S s;
    s.ptr = 0;
    char *same_data = s.ptr + (data - s.ptr);
    same_data[0] = 1;
}

int main() {
    char c;
    f1(&c);
    if (c != 1)
        return 1;
    return 0;
}

Compiled with gcc version 4.4.6, the program above returns 0 regardless of the
optimization level.

Compiled with gcc versions 4.5.3 or 4.6.1, the return value is 0 only with -O0.
Using -O1, -O2, -O3 or -Os, the return value is 1.

The correct value (0) is returned if s.ptr is replaced with a local variable or
the code from the function f1 is moved inside main.


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

* [Bug tree-optimization/49873] Optimizer regression
  2011-07-27 16:58 [Bug tree-optimization/49873] New: Optimizer regression abenea at gmail dot com
@ 2011-07-27 17:00 ` pinskia at gcc dot gnu.org
  2011-07-28  9:56 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-07-27 17:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-07-27 17:00:06 UTC ---
I think this code is undefined because you are subtracting two "arrays" which
produces an undefined result in C.


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

* [Bug tree-optimization/49873] Optimizer regression
  2011-07-27 16:58 [Bug tree-optimization/49873] New: Optimizer regression abenea at gmail dot com
  2011-07-27 17:00 ` [Bug tree-optimization/49873] " pinskia at gcc dot gnu.org
@ 2011-07-28  9:56 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-28  9:56 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-28 09:55:58 UTC ---
    char *same_data = s.ptr + (data - s.ptr);
    same_data[0] = 1;

same_data now points to s.ptr plus some offset that isn't computed in any
standard compliant way.  As s.ptr is NULL the store is dead.

With

  char *same_data = (char *)((uintptr_t) s.ptr + (uintptr_t) data - (uintptr_t)
s.ptr));

you would get the correct answer, avoiding all the undefinedness in your code.


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

end of thread, other threads:[~2011-07-28  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-27 16:58 [Bug tree-optimization/49873] New: Optimizer regression abenea at gmail dot com
2011-07-27 17:00 ` [Bug tree-optimization/49873] " pinskia at gcc dot gnu.org
2011-07-28  9:56 ` rguenth at gcc dot gnu.org

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).