public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109342] New: [13 Regression] Wrong code with -O2
@ 2023-03-30  7:12 vsevolod.livinskiy at gmail dot com
  2023-03-30  7:26 ` [Bug tree-optimization/109342] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vsevolod.livinskiy at gmail dot com @ 2023-03-30  7:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109342
           Summary: [13 Regression] Wrong code with -O2
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskiy at gmail dot com
  Target Milestone: ---

Link to the Compiler Explorer: https://godbolt.org/z/zKqcna3vn

Reproducer:
#include <stdio.h>

unsigned long long int var_4 = 42;
unsigned long long int var_14 = 10;
unsigned char var_16 = 1;
unsigned short var_18 = 0;
short var_75;

inline const int &foo(const int &b, const int &c) { return b < c ? c : b; }
inline unsigned long long &bar(unsigned long long &b, unsigned long long &c) {
  return !c ? c : b;
}

void test(unsigned long long var_4, unsigned long long var_14,
          unsigned char var_16, unsigned short var_18) __attribute__((noipa));
void test(unsigned long long var_4, unsigned long long var_14,
          unsigned char var_16, unsigned short var_18) {
  for (bool h = 0; h < (bool)foo(var_16 ? -7 : 4, var_4 ? var_4 : var_18);
       h = 2)
    var_75 = bar(var_4, var_14);
}

int main() {
  test(var_4, var_14, var_16, var_18);
  printf("%hd\n", var_75);
  if (var_75 != 42)
    __builtin_abort();
}

Error:
>$ g++ -O0 small.cpp && ./a.out 
42
>$ g++ -O2 small.cpp && ./a.out 
0
Aborted (core dumped)

gcc version 13.0.1 20230329 (3be4e43a6a0f429648ea188c8e110b74268fed27)

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

end of thread, other threads:[~2023-03-30 11:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30  7:12 [Bug tree-optimization/109342] New: [13 Regression] Wrong code with -O2 vsevolod.livinskiy at gmail dot com
2023-03-30  7:26 ` [Bug tree-optimization/109342] " rguenth at gcc dot gnu.org
2023-03-30  7:41 ` [Bug tree-optimization/109342] [13 Regression] Wrong code with -O2 since r13-5348-gc29d85359add80 marxin at gcc dot gnu.org
2023-03-30  7:45 ` rguenth at gcc dot gnu.org
2023-03-30 11:02 ` cvs-commit at gcc dot gnu.org
2023-03-30 11:02 ` rguenth at gcc dot gnu.org

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).