public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39163]  New: -mstackalign breaks -O2 optimization using g++
@ 2009-02-12  4:18 gyunaev at ulduzsoft dot com
  2009-02-12  4:19 ` [Bug c++/39163] " gyunaev at ulduzsoft dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2009-02-12  4:18 UTC (permalink / raw)
  To: gcc-bugs

This is basically a copy of bug report from
http://www.dribin.org/dave/blog/archives/2006/12/05/missing_third_param/

Using the following sample file saved as test.c:

----------------------------------------------------------------------------
#include <stdio.h>

#define NOINLINE __attribute__((noinline))

NOINLINE static void foo1(int i1)
{
    printf("foo1: %d\n", i1);
}

NOINLINE static void foo2(int i1, int i2)
{
    printf("foo2: %d, %d\n", i1, i2);
}

NOINLINE static void foo3(int i1, int i2, int i3)
{
    printf("foo3: %d, %d, %d\n", i1, i2, i3);
}

NOINLINE static void foo4(int i1, int i2, int i3, int i4)
{
    printf("foo4: %d, %d, %d, %d\n", i1, i2, i3, i4);
}

NOINLINE static void foo5(int i1, int i2, int i3, int i4, int i5)
{
    printf("foo5: %d, %d, %d, %d, %d\n", i1, i2, i3, i4, i5);
}

NOINLINE static void foo6(int i1, int i2, int i3, int i4, int i5, int i6)
{
    printf("foo6: %d, %d, %d, %d, %d, %d\n", i1, i2, i3, i4, i5, i6);
}


int main(int argc, char **argv)
{
    foo1(1);
    foo2(1, 2);
    foo3(1, 2, 3);
    foo4(1, 2, 3, 4);
    foo5(1, 2, 3, 4, 5);
    foo6(1, 2, 3, 4, 5, 6);
    return 0;
}
----------------------------------------------------------------------------

produces invalid output (broken 3rd parameter) if compiled using g++ and
-mstackrealign:

> /usr/toolchains/gcc433/bin/g++ -Wall -mstackrealign -O2 test.c
> ./a.out
foo1: 1
foo2: 1, 2
foo3: 1, 2, -1209632279
foo4: 1, 2, 4, 134520820
foo5: 1, 2, 4, 5, -1074446840
foo6: 1, 2, 4, 5, 6, 134514537



However if gcc is used instead of g++, valid output is generated:

> /usr/toolchains/gcc433/bin/gcc -mstackrealign -Wall -O2 test.c
> ./a.out
foo1: 1
foo2: 1, 2
foo3: 1, 2, 3
foo4: 1, 2, 3, 4
foo5: 1, 2, 3, 4, 5
foo6: 1, 2, 3, 4, 5, 6


Analyze of assembly dump revealed that GCC still uses ECX in main() to pass the
parameter. ix86_internal_arg_pointer() in i386.c works fine, and returns same
values for gcc and g++, so the problem is not there.


-- 
           Summary: -mstackalign breaks -O2 optimization using g++
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gyunaev at ulduzsoft 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=39163


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

* [Bug c++/39163] -mstackalign breaks -O2 optimization using g++
  2009-02-12  4:18 [Bug c++/39163] New: -mstackalign breaks -O2 optimization using g++ gyunaev at ulduzsoft dot com
@ 2009-02-12  4:19 ` gyunaev at ulduzsoft dot com
  2009-02-12  8:12 ` jakub at gcc dot gnu dot org
  2009-02-12 11:10 ` gyunaev at ulduzsoft dot com
  2 siblings, 0 replies; 4+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2009-02-12  4:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from gyunaev at ulduzsoft dot com  2009-02-12 04:19 -------
Created an attachment (id=17284)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17284&action=view)
test.c


-- 


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


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

* [Bug c++/39163] -mstackalign breaks -O2 optimization using g++
  2009-02-12  4:18 [Bug c++/39163] New: -mstackalign breaks -O2 optimization using g++ gyunaev at ulduzsoft dot com
  2009-02-12  4:19 ` [Bug c++/39163] " gyunaev at ulduzsoft dot com
@ 2009-02-12  8:12 ` jakub at gcc dot gnu dot org
  2009-02-12 11:10 ` gyunaev at ulduzsoft dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-02-12  8:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2009-02-12 08:12 -------
Works just fine with gcc trunk.


-- 


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


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

* [Bug c++/39163] -mstackalign breaks -O2 optimization using g++
  2009-02-12  4:18 [Bug c++/39163] New: -mstackalign breaks -O2 optimization using g++ gyunaev at ulduzsoft dot com
  2009-02-12  4:19 ` [Bug c++/39163] " gyunaev at ulduzsoft dot com
  2009-02-12  8:12 ` jakub at gcc dot gnu dot org
@ 2009-02-12 11:10 ` gyunaev at ulduzsoft dot com
  2 siblings, 0 replies; 4+ messages in thread
From: gyunaev at ulduzsoft dot com @ 2009-02-12 11:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gyunaev at ulduzsoft dot com  2009-02-12 11:10 -------
Yes, I recompiled the current trunk and it seems to be fixed in trunk.


-- 

gyunaev at ulduzsoft dot com changed:

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


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


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

end of thread, other threads:[~2009-02-12 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-12  4:18 [Bug c++/39163] New: -mstackalign breaks -O2 optimization using g++ gyunaev at ulduzsoft dot com
2009-02-12  4:19 ` [Bug c++/39163] " gyunaev at ulduzsoft dot com
2009-02-12  8:12 ` jakub at gcc dot gnu dot org
2009-02-12 11:10 ` gyunaev at ulduzsoft 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).