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 c++/62285] New: const reference binding to temporary when using -fPIC


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62285

            Bug ID: 62285
           Summary: const reference binding to temporary when using -fPIC
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rpzatkoff at gmail dot com

I found an issue with a simple program when using a const reference in C++.

I have compiled this with various versions of g++ with different flags and get
different results in many of them.

I am running on an Intel Xeon processor 

------------------------------
#include <iostream>

int64_t foo()
{
  return 5;
}


int main( int, char** )
{
  int64_t biggerNum = 5000;
  const int64_t& minimum = std::min( foo(), biggerNum );

  std::cout << minimum << std::endl;

  return 0;
}
------------------------------

The -fPIC flag changes the results of the program and in different
optimizations will produce 5000 or 0 instead of 5.  gcc-4.9.1 is the latest I
have reproduced the problem - and it does not appear to affect clang.

------------
*** GCC 4.4.7 ***

-g3 -O0 -std=c++0x
gcc-4.4.7 -g3 -O0 -std=c++0x
5
-g3 -O1 -std=c++0x
gcc-4.4.7 -g3 -O1 -std=c++0x
5
-g3 -O2 -std=c++0x
gcc-4.4.7 -g3 -O2 -std=c++0x
5
-g3 -O3 -std=c++0x
gcc-4.4.7 -g3 -O3 -std=c++0x
5
-g3 -O0 -std=c++0x
gcc-4.4.7 -g3 -O0 -std=c++0x -fPIC
5
-g3 -O1 -std=c++0x
gcc-4.4.7 -g3 -O1 -std=c++0x -fPIC
5
-g3 -O2 -std=c++0x
gcc-4.4.7 -g3 -O2 -std=c++0x -fPIC
5
-g3 -O3 -std=c++0x
gcc-4.4.7 -g3 -O3 -std=c++0x -fPIC
5


*** GCC 4.7.3 ***

-g3 -O0 -std=c++11
gcc-4.7.3 -g3 -O0 -std=c++11
5
-g3 -O1 -std=c++11
gcc-4.7.3 -g3 -O1 -std=c++11
0
-g3 -O2 -std=c++11
gcc-4.7.3 -g3 -O2 -std=c++11
5
-g3 -O3 -std=c++11
gcc-4.7.3 -g3 -O3 -std=c++11
5
-g3 -O0 -std=c++11
gcc-4.7.3 -g3 -O0 -std=c++11 -fPIC
5
-g3 -O1 -std=c++11
gcc-4.7.3 -g3 -O1 -std=c++11 -fPIC
0
-g3 -O2 -std=c++11
gcc-4.7.3 -g3 -O2 -std=c++11 -fPIC
5000
-g3 -O3 -std=c++11
gcc-4.7.3 -g3 -O3 -std=c++11 -fPIC
5000


*** GCC 4.8.2 ***

-g3 -O0 -std=c++11
gcc-4.8.2 -g3 -O0 -std=c++11
5
-g3 -O1 -std=c++11
gcc-4.8.2 -g3 -O1 -std=c++11
5
-g3 -O2 -std=c++11
gcc-4.8.2 -g3 -O2 -std=c++11
5
-g3 -O3 -std=c++11
gcc-4.8.2 -g3 -O3 -std=c++11
5
-g3 -O0 -std=c++11
gcc-4.8.2 -g3 -O0 -std=c++11 -fPIC
5
-g3 -O1 -std=c++11
gcc-4.8.2 -g3 -O1 -std=c++11 -fPIC
0
-g3 -O2 -std=c++11
gcc-4.8.2 -g3 -O2 -std=c++11 -fPIC
5000
-g3 -O3 -std=c++11
gcc-4.8.2 -g3 -O3 -std=c++11 -fPIC
5000


*** GCC 4.9.0 ***

-g3 -O0 -std=c++11
gcc-4.9.0 -g3 -O0 -std=c++11
5
-g3 -O1 -std=c++11
gcc-4.9.0 -g3 -O1 -std=c++11
5
-g3 -O2 -std=c++11
gcc-4.9.0 -g3 -O2 -std=c++11
5
-g3 -O3 -std=c++11
gcc-4.9.0 -g3 -O3 -std=c++11
5
-g3 -O0 -std=c++11
gcc-4.9.0 -g3 -O0 -std=c++11 -fPIC
5
-g3 -O1 -std=c++11
gcc-4.9.0 -g3 -O1 -std=c++11 -fPIC
0
-g3 -O2 -std=c++11
gcc-4.9.0 -g3 -O2 -std=c++11 -fPIC
5000
-g3 -O3 -std=c++11
gcc-4.9.0 -g3 -O3 -std=c++11 -fPIC
5000


*** GCC 4.9.1 ***

-g3 -O0 -std=c++11
gcc-4.9.1 -g3 -O0 -std=c++11
5
-g3 -O1 -std=c++11
gcc-4.9.1 -g3 -O1 -std=c++11
5
-g3 -O2 -std=c++11
gcc-4.9.1 -g3 -O2 -std=c++11
5
-g3 -O3 -std=c++11
gcc-4.9.1 -g3 -O3 -std=c++11
5
-g3 -O0 -std=c++11
gcc-4.9.1 -g3 -O0 -std=c++11 -fPIC
5
-g3 -O1 -std=c++11
gcc-4.9.1 -g3 -O1 -std=c++11 -fPIC
0
-g3 -O2 -std=c++11
gcc-4.9.1 -g3 -O2 -std=c++11 -fPIC
5000
-g3 -O3 -std=c++11
gcc-4.9.1 -g3 -O3 -std=c++11 -fPIC
5000


*** Clang 3.4 ***

-g3 -O0 -std=c++11
clang-3.4 -g3 -O0 -std=c++11
5
-g3 -O1 -std=c++11
clang-3.4 -g3 -O1 -std=c++11
5
-g3 -O2 -std=c++11
clang-3.4 -g3 -O2 -std=c++11
5
-g3 -O3 -std=c++11
clang-3.4 -g3 -O3 -std=c++11
5
-g3 -O0 -std=c++11
clang-3.4 -g3 -O0 -std=c++11 -fPIC
5
-g3 -O1 -std=c++11
clang-3.4 -g3 -O1 -std=c++11 -fPIC
5
-g3 -O2 -std=c++11
clang-3.4 -g3 -O2 -std=c++11 -fPIC
5
-g3 -O3 -std=c++11
clang-3.4 -g3 -O3 -std=c++11 -fPIC
5
-------


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