public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32697]  New: O2 optimizes away assignment
@ 2007-07-09 13:20 Dries dot Decock at excentis dot com
  2007-07-09 13:35 ` [Bug c++/32697] " schwab at suse dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dries dot Decock at excentis dot com @ 2007-07-09 13:20 UTC (permalink / raw)
  To: gcc-bugs

Hi,

I'm using SWIG to combine Java and C++ code. At some point, SWIG generates a
method like this :

1SWIGEXPORT jlong JNICALL Java_com_excentis_products_X_XUpcast(JNIEnv *jenv,
jclass jcls, jlong jarg1) {
    jlong baseptr = 0;
    (void)jenv;
    (void)jcls;
    *(Flow **)&baseptr = *(TcpFlow **)&jarg1;
    return baseptr;
}

The problem is that the assignment is not executed and the return value is
always zero, when using -O2 optimization. When I disable O2, or add a debug
statement, the value is ok.

I don't like the generated code, but it should work fine.


-- 
           Summary: O2 optimizes away assignment
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Dries dot Decock at excentis dot com
 GCC build triplet: i686-pc-linux
  GCC host triplet: i686-pc-linux
GCC target triplet: i686-pc-linux i686-mingw32


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


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

* [Bug c++/32697] O2 optimizes away assignment
  2007-07-09 13:20 [Bug c++/32697] New: O2 optimizes away assignment Dries dot Decock at excentis dot com
@ 2007-07-09 13:35 ` schwab at suse dot de
  2007-07-09 13:56 ` sorenj at us dot ibm dot com
  2007-07-09 14:07 ` Dries dot Decock at excentis dot com
  2 siblings, 0 replies; 4+ messages in thread
From: schwab at suse dot de @ 2007-07-09 13:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2007-07-09 13:35 -------
Report this to the SWIG maintainers.  This is violating the C/C++ aliasing
rules.

*** This bug has been marked as a duplicate of 21920 ***


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |normal
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

* [Bug c++/32697] O2 optimizes away assignment
  2007-07-09 13:20 [Bug c++/32697] New: O2 optimizes away assignment Dries dot Decock at excentis dot com
  2007-07-09 13:35 ` [Bug c++/32697] " schwab at suse dot de
@ 2007-07-09 13:56 ` sorenj at us dot ibm dot com
  2007-07-09 14:07 ` Dries dot Decock at excentis dot com
  2 siblings, 0 replies; 4+ messages in thread
From: sorenj at us dot ibm dot com @ 2007-07-09 13:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from sorenj at us dot ibm dot com  2007-07-09 13:55 -------
Please refer to
https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1560993&group_id=1645

Long story short - as it stands today: C++ standards team won't change the spec
to allow type punning, gcc team won't "fix" code generation if it involves type
punning, swig team won't rewrite the code generators to generate ANSI spec
compliant code.

(The only way to do this by current ANSI spec rules is to memcpy the contents
of the pointers themselves from a pointer of one type to a pointer of another
type.)

Your only solution at this time is to use -fno-strict-aliasing when compiling
swig wrapper code.  This has been a major headache mainly for package
maintainers.


-- 


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


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

* [Bug c++/32697] O2 optimizes away assignment
  2007-07-09 13:20 [Bug c++/32697] New: O2 optimizes away assignment Dries dot Decock at excentis dot com
  2007-07-09 13:35 ` [Bug c++/32697] " schwab at suse dot de
  2007-07-09 13:56 ` sorenj at us dot ibm dot com
@ 2007-07-09 14:07 ` Dries dot Decock at excentis dot com
  2 siblings, 0 replies; 4+ messages in thread
From: Dries dot Decock at excentis dot com @ 2007-07-09 14:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from Dries dot Decock at excentis dot com  2007-07-09 14:07 -------
Thanks for the reply. 

I will use the -fno-strict-aliasing for now, and hope that the SWIG maintainers
will fix this problem in the near future.

Thanks again.


-- 


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


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

end of thread, other threads:[~2007-07-09 14:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-09 13:20 [Bug c++/32697] New: O2 optimizes away assignment Dries dot Decock at excentis dot com
2007-07-09 13:35 ` [Bug c++/32697] " schwab at suse dot de
2007-07-09 13:56 ` sorenj at us dot ibm dot com
2007-07-09 14:07 ` Dries dot Decock at excentis 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).