This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/12079] New: Regression from gcc 3.2.2: incorrect code generation when -O3 optimization is used


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Regression from gcc 3.2.2: incorrect code generation
                    when -O3 optimization is used
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amelkor at mail dot ru
                CC: gcc-bugs at gcc dot gnu dot org

Configuration:
andr@asp:~/test/gcc331\%uname -a
Linux asp 2.4.18-27.7.x #1 Fri Mar 14 06:44:53 EST 2003 i686 unknown

andr@asp:~/test/gcc331\%gcc -v
Reading specs from /home/dev/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
Configured with: /home/dev/src/gcc-3.3.1/configure --prefix=/home/dev
--enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.3.1
--------

Consider program with three simple files Test.h, Test.cpp and main.cpp:
File Test.h :
---
#ifndef ___TEST_
#define ___TEST_

class Test
{
    static const char* str;

public:

    static const char* get();

};

#endif
-----

File Test.cpp :
---
#include "Test.h"

const char* Test::str = "SomeString";

const char* Test::get()
{
    return str;
}
----

File main.cpp :
---
#include "Test.h"
#include <iostream>

int main(  int, char** )
{
  const char* x = Test::get();

  std::cout << x << "\n";
  return 0;
}
-----

Compile class Test from Test.cpp into shared library with -O3 optimization:

andr@asp:~/test/gcc331\%g++ -g -O3 -fPIC -shared Test.cpp -o test.so
andr@asp:~/test/gcc331\%

Then compile code from the file main.cpp that will use it:

andr@asp:~/test/gcc331\%g++ -g main.cpp test.so -o main
andr@asp:~/test/gcc331\%

Now run it:
andr@asp:~/test/gcc331\%./main
Segmentation fault (core dumped)
andr@asp:~/test/gcc331\%

Recompile shared library with -O2 optimization and run test again:

andr@asp:~/test/gcc331\%g++ -g -O2 -fPIC -shared Test.cpp -o test.so
andr@asp:~/test/gcc331\%./main
SomeString
andr@asp:~/test/gcc331\%

It works fine in this case !
With gcc 3.2.2 it works fine in both cases with -O2 and -O3 options.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]