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

            Bug ID: 81606
           Summary: A small program works as expected with -O0 but fails
                    with -O1 on all tested gcc versions
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jerome.pioux at atos dot net
  Target Milestone: ---

Created attachment 41859
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41859&action=edit
Two .ii files (compiled with -O0 and -O1)

Intel(R) Xeon(R) CPU E7- 487
Centos 7.3 x86_64
gcc (GCC) 7.1.0

The program originally failed using gcc 4.8.5 20150623 (CentOS 7 default).

I built gcc 7.1.0 from source to verify that the problem still existed using a
later gcc version.

There is a difference though. On 4.8.5, the program only worked using -O0 and
failed with -O1 ,-O2 or -O3.

On 7.1.0, the program only failed with -O1.

Program compilation (no warnings):
g++ gccproblem.cpp -o gccproblem -O[0-3] -save-temps

Note that gcc seems to be trying to use the character "B" in the string
"NC0404B" below when it makes the comparison if ("A" >= "B")

Note also that the problem only occurs when the "B" in NC0404B and the "B" in
the IF statement are the same, AND the "B" has to be the LAST character in the
string "NC0404B".

There is no problem when the "B" is elsewhere in the string, that is, not the
last character.

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
int main (int argc, char *argv[]) {
std::string dummy="NC0404B";

if ("A" >= "B") {
  std::cout << "FAILS." << std::endl;
}
else {
  std::cout << "PASSES." << std::endl;
}
return (0);
};

Reply via email to