[Bug c++/92475] New: incorrect code with optimization

2019-11-12 Thread gunther.vo...@ssw-trading.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92475

Bug ID: 92475
   Summary: incorrect code with optimization
   Product: gcc
   Version: 8.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gunther.vo...@ssw-trading.com
  Target Milestone: ---

Created attachment 47219
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47219&action=edit
preprocessed source

In the following code, the branch for length==0 (including the string constant
"AAA") is optimized away. Observed with GCC 8.3.0/1. With GCC 9.2.1 and GCC
7.4.0, the generated code is correct.

#include 

size_t
f(char* s)
{
ssize_t i;

for (i = 7; i >= 0; i--) {
if (s[i] != ' ') {
if (i < 7) {
s[i + 1] = '\0';
}
break;
}
}

return static_cast(i + 1);
}

void h(const char*);

void
g(char* s)
{
size_t length = f(s);
std::string(s, length); // bug disappears when this line is removed
h(length ? "BBB" : "AAA");
}

[Bug c++/92475] incorrect code with optimization

2019-11-12 Thread gunther.vo...@ssw-trading.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92475

--- Comment #1 from Gunther Vogel  ---
Created attachment 47220
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47220&action=edit
output of gcc -v -save-temps -W -Wall -O2 -S bug.cc

[Bug c++/92475] incorrect code with optimization

2019-11-12 Thread gunther.vo...@ssw-trading.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92475

--- Comment #2 from Gunther Vogel  ---
Created attachment 47221
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47221&action=edit
assembly - no "AAA" in here