[Bug tree-optimization/113898] [14 regression] ICE in copy_reference_ops_from_ref, at tree-ssa-sccvn.cc:1156 since r14-8929-g938a419182f

2024-02-16 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113898

Shaohua Li  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |---

--- Comment #5 from Shaohua Li  ---
Looks like the fix is not complete

Compiler explorer: https://godbolt.org/z/z3YKznMzE

% cat reduced.c
long a, b, c;
int d;
long e[2][1];
int f() {
  if (c == a)
c = b;
}
void g() {
  int h, i = 0;
  for (; f() + d + i; i++)
e[h][i] = 4;
}
void main() {}
%
% gcc -O3 reduced.c
during GIMPLE pass: fre
reduced.c: In function 'g':
reduced.c:8:6: internal compiler error: in copy_reference_ops_from_ref, at
tree-ssa-sccvn.cc:1177
8 | void g() {
  |  ^
0x233ba2c internal_error(char const*, ...)
???:0
0x96c20f fancy_abort(char const*, int, char const*)
???:0
0x12991ba vn_reference_lookup(tree_node*, tree_node*, vn_lookup_kind,
vn_reference_s**, bool, tree_node**, tree_node*, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1
%

[Bug tree-optimization/113898] New: ICE in copy_reference_ops_from_ref, at tree-ssa-sccvn.cc:1156

2024-02-13 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113898

Bug ID: 113898
   Summary: ICE in copy_reference_ops_from_ref, at
tree-ssa-sccvn.cc:1156
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -Os crashed on the test case.

Bisected to r14-8929-g938a419182f


%cat reduced.c
int a, d;
unsigned **b;
long c, f;
long e[2][1];
void g() {
  int h = 0;
  for (; h < 2; h++) {
e[h][d + **b + a] = c;
if (f)
  for (;;)
;
  }
}
void main() {}
%
%gcc -Os reduced.c
int a, d;
unsigned **b;
long c, f;
long e[2][1];
void g() {
  int h = 0;
  for (; h < 2; h++) {
e[h][d + **b + a] = c;
if (f)
  for (;;)
;
  }
}
void main() {}
%

[Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87

2024-02-04 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113756

Bug ID: 113756
   Summary: Wrong code at -O2 on x86_64-linux-gnu since
r14-2780-g39f117d6c87
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -O2 produced the wrong code.

Bisected to r14-2780-g39f117d6c87

Compiler explorer: https://godbolt.org/z/qWd4196h6

% cat reduced.c
int printf(const char *, ...);
int d, e, i, k, l = -8;
char h, j;
int m(int n, int o, int p3) {
  int a = o - p3, b = n - p3, c = a + b, f = -b, g = c < 0 ? -c : c;
  return a <= f && a <= g ? o : p3;
}
void q(int *n, unsigned short o) {
  unsigned p = 8896;
  for (; e >= 0; e--)
p = 5377;
  for (; h <= 0; h++)
for (; j <= 0; j++) {
  *n = 1611581749;
  i = m(34, p - 5294, *n - 1611581687);
  k = i + p + 65535 + o + *n - 1611718251;
  printf("%d\n", k);
}
}
int main() {
  q(, l);
}
%
% gcc -O0 reduced.c &&./a.out
0
% gcc -O2 reduced.c &&./a.out
21
%

[Bug tree-optimization/113725] New: ICE during GIMPLE pass: cunroll

2024-02-02 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113725

Bug ID: 113725
   Summary: ICE during GIMPLE pass: cunroll
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O3 crashed on the test case.

Bisected to r14-8683-gb84f8a5e0a7

Compiler explorer: https://godbolt.org/z/qsPvvPx6q

%cat reduced.c
char a;
int b, c, d, e;
int f() {}
void g() {
  for (;;) {
b = 1;
for (; b >= 0; b--) {
  int *h = 
  for (; d; d++)
a && (*h = 8);
  c = e;
}
for (; f() <= 2;)
  ;
  }
}
int main() {}
%
%gcc -O3 reduced.c
during GIMPLE pass: cunroll
reduced.c: In function ‘g’:
reduced.c:4:6: internal compiler error: Segmentation fault
4 | void g() {
  |  ^
0x7f07fa09208f ???
   
/build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7f07fa073082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
%

[Bug tree-optimization/112831] New: ICE: tree check: expected class 'type', have 'exceptional' (error_mark) in type_has_mode_precision_p, at tree.h:6767

2023-12-03 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112831

Bug ID: 112831
   Summary: ICE: tree check: expected class 'type', have
'exceptional' (error_mark) in
type_has_mode_precision_p, at tree.h:6767
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: fweimer at redhat dot com
  Target Milestone: ---

gcc at -Os crashes on the test case.

Bisected to r14-6034-g4ee2aca7ca0

Compiler explorer: https://godbolt.org/z/6We5qxMbr

% cat a.c
int a, b;
char c;
int d() {}
void e() {
  for (; c; c++) {
b = 0;
for (; b <= 7; b++)
  ;
for (; (short)(d() + b) + a; a++)
  ;
  }
}
int main() {}
%
% gcc -Os a.c
during GIMPLE pass: sccp
a.c: In function ‘e’:
a.c:4:6: internal compiler error: tree check: expected class ‘type’, have
‘exceptional’ (error_mark) in type_has_mode_precision_p, at tree.h:6767
4 | void e() {
  |  ^
0x7f47566c3082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
%

[Bug tree-optimization/112721] New: [14 Regression] Wrong code at -O1/s on x86_64-linux-gnu since r14-5831-gaae723d360c

2023-11-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112721

Bug ID: 112721
   Summary: [14 Regression] Wrong code at -O1/s on
x86_64-linux-gnu since r14-5831-gaae723d360c
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: mjambor at suse dot cz
  Target Milestone: ---

gcc at -O1/s produces the wrong code.

Bisected to r14-5831-gaae723d360c

Compiler explorer: https://godbolt.org/z/671M9YPPj

$ cat a.c
int printf(const char *, ...);
struct a {
  int b;
};
int c, e;
long d;
unsigned *f(unsigned *g) {
  for (; c;)
e = d;
  return g;
}
int main() {
  int *h;
  struct a i = {8};
  int *j = 
  h = f(j);
  *h = 0;
  printf("%d\n", i.b);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -O1 a.c && ./a.out
8
$

[Bug tree-optimization/111671] [14 Regression] ICE in get_default_value, at tree-ssa-ccp.cc:312 since r14-2965-gc83528d2367

2023-11-11 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111671

--- Comment #3 from Shaohua Li  ---
Yes, I cannot reproduce it anymore. Any idea about which commit fixed it?

[Bug tree-optimization/110769] [14 Regression] ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023 since r14-2674-gd0de3bf9175

2023-11-03 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110769

--- Comment #5 from Shaohua Li  ---
(In reply to Shaohua Li from comment #3)
> I tried to bisect it and it was bisected to r14-2674-gd0de3bf9175, which is
> different from the bisection point in bug110641

I probably bisected to the wrong commit. I bisected it again and it should be
r14-2675-gef28aadad6e

[Bug tree-optimization/112346] [13 Regression] Wrong code produced with -O2

2023-11-02 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112346

Shaohua Li  changed:

   What|Removed |Added

 CC||shaohua.li at inf dot ethz.ch

--- Comment #2 from Shaohua Li  ---
(In reply to Fedor Chelnokov from comment #0)
> This program
> 
> #include 
> 
> char *SkipAName(char *s) {
>   if (('A' <= *s && *s <= 'Z') || ('a' <= *s && *s <= 'z') ) {
> while (isalnum(*s)) {
>   s++;
> }
>   }
>   return s;
> }
> 
> int TestName(char *name) {
>   while (*name)
> name++;
>   return 0;
> }
> 
> int StrICmp(char *s1, char *s2) {
>   while (*s1 && *s1 == *s2) {
> s1++;
> s2++;
>   }
>   return *s1 - *s2;
> }
> 
> int DoTable(char *s) {
> char *name, c;
> name = s;
> s = SkipAName(s);
> c = *s;
> *s = 0;
> TestName(name);
> *s = c;
> if (*s == '(')
>   return 3;
> if (*s != ',')
>   return 2;
> *s = 0;
> return StrICmp(name, "sparse");
> }
> 
> int main() {
>   char buf[] = "sparse,C(1)";
>   return DoTable(buf);
> }
> 
> shall return 0, but in GCC 13 with -O2 it returns 44. Online demo:
> https://gcc.godbolt.org/z/c6W33T1zK
> 
> Related discussion: https://stackoverflow.com/q/77407156/7325599

Hi, it seems that this test case is reduced from a real project. Could you tell
me which project it is from?

[Bug tree-optimization/112310] New: [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since r14-1161-g5476de2618f

2023-10-31 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112310

Bug ID: 112310
   Summary: [14 Regression] Wrong code at -O2/3 on
x86_64-linux-gnu since r14-1161-g5476de2618f
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3 produces the wrong code.

Bisected to r14-1161-g5476de2618f

Compiler explorer: https://godbolt.org/z/Kb4qMKE9K

$ cat a.c
int printf(const char *, ...);
short a, b;
static int c, d, e, f = -7;
char g;
int *h = 
int **i = 
int j;
short(k)(int l) { return l >= 2 ? 0 : l; }
int(m)(int l, int n) { return l < -2147483647 / n ? l : l * n; }
void o() {  }
int main() {
  {
int p;
for (; g <= 3; g++) {
  for (; c; c++)
;
  a = 2;
  for (; a <= 7; a++) {
short *r = 
p = m(*h, 2022160547);
unsigned q = 2022160547;
e = p * q;
*r ^= e;
j = k(c + 3);
**i = 0;
  }
  *i = 
}
  }
  printf("%d\n", b);
}
$
$ gcc -O0 a.c && ./a.out
-3189
$ gcc -O2 a.c && ./a.out
0
$

[Bug tree-optimization/111950] New: ICE in compute_live_loop_exits, at tree-ssa-loop-manip.cc:250 since r14-4786-gd118738e71c

2023-10-24 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111950

Bug ID: 111950
   Summary: ICE in compute_live_loop_exits, at
tree-ssa-loop-manip.cc:250 since r14-4786-gd118738e71c
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O3 crashes on the test case.

Bisected to r14-4786-gd118738e71c

Compiler explorer: https://godbolt.org/z/Pe5cPqo7s

$ cat a.c
int a, b, d;
int c[4];
unsigned e;
void f() {
  char g;
  for (; d; d++) {
g = 1;
for (; g >= 0; g--) {
  e = b >= 2 || a >> b ?: a;
  c[g] = e;
}
  }
}
int main() {}
$
$ gcc -O3 a.c
during GIMPLE pass: vect
a.c: In function ‘f’:
a.c:4:6: internal compiler error: in compute_live_loop_exits, at
tree-ssa-loop-manip.cc:250
4 | void f() {
  |  ^
0x7f4266496082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug tree-optimization/111917] New: ICE in as_a, at is-a.h:255 since GCC-8

2023-10-22 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111917

Bug ID: 111917
   Summary: ICE in as_a, at is-a.h:255 since GCC-8
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O3 crashed.

I didn't bisect this case because it affected even gcc-8.

Compiler explorer: https://godbolt.org/z/7Mz9G6Kro

$ cat a.c
long a() {
  long b, c;
  for (; b; b++)
c <<= 1;
  return c;
}
static int d() {
e:
f:
  for (; a();)
;
  goto f;
  return 0;
}
int main() { d(); }
$
$ gcc -O3 a.c
during GIMPLE pass: unswitch
a.c: In function 'int main()':
a,c:15:5: internal compiler error: in as_a, at is-a.h:255
   15 | int main() { d(); }
  | ^~~~
0x26259de internal_error(char const*, ...)
???:0
0xaf830e fancy_abort(char const*, int, char const*)
???:0
0x15b8af2 number_of_iterations_exit(loop*, edge_def*, tree_niter_desc*, bool,
bool, basic_block_def**)
???:0
0x14fca28 number_of_latch_executions(loop*)
???:0
0x15ba69d estimate_numbers_of_iterations(loop*)
???:0
0x15bc037 estimated_loop_iterations(loop*,
generic_wide_int >*)
???:0
0x15bc067 estimated_loop_iterations_int(loop*)
???:0
0x15cf559 tree_ssa_unswitch_loops(function*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug tree-optimization/111869] New: ICE: verify_ssa failed since r14-4710-g60c231cb658

2023-10-18 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111869

Bug ID: 111869
   Summary: ICE: verify_ssa failed since r14-4710-g60c231cb658
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: tamar.christina at arm dot com
  Target Milestone: ---

gcc at -O3 crashed.

Bisected to r14-4710-g60c231cb658

$ cat a.c
int a;
unsigned b() {
  long c;
  unsigned d = 1;
  char *e = "";
  c = 0;
  for (; c < a; c++)
e[0]++;
  c = 0;
  for (; c < a; c++)
if (c)
  d = 0;
  return d;
}
int main() {}
$
$ gcc -O3 a.c
a.c: In function ‘b’:
a.c:2:10: error: PHI node with wrong VUSE on edge from BB 14
2 | unsigned b() {
  |  ^
.MEM_39 = PHI <.MEM_1(14), .MEM_1(13)>
expected .MEM_29
a.c:2:10: error: PHI node with wrong VUSE on edge from BB 13
.MEM_39 = PHI <.MEM_1(14), .MEM_1(13)>
expected .MEM_29
during GIMPLE pass: vect
a.c:2:10: internal compiler error: verify_ssa failed
0x7f10859fa082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions
$

[Bug tree-optimization/111839] New: Wrong code at -O3 on x86_64-linux-gnu since r12-2097-g9f34b780b0

2023-10-16 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111839

Bug ID: 111839
   Summary: Wrong code at -O3 on x86_64-linux-gnu since
r12-2097-g9f34b780b0
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Bisected to r12-2097-g9f34b780b0

Compiler explorer: https://godbolt.org/z/Ea1hGGnob

$ cat a.c
int printf(const char *, ...);
long a;
int b, c, e, g, i;
long *d, *h;
char f = -26;
int main() {
  long j;
  c = 0;
  for (; c != 7; ++c) {
long k=0;
long l = k;
long **m = 
for (; f + i!=0; i++)
  h = 
g = h != (*m = );
int *n = 
*n = g;
for (; e;)
  for (; a; a = a + 1)
;
  }
  printf("%d\n", b);
}
$
$ gcc -fsanitize=address,undefined a.c && ./a.out
1
$ gcc -O3 a.c && ./a.out
0
$

[Bug tree-optimization/111764] New: Wrong code at -O3 on x86_64-linux-gnu since r11-5965-g04bff1bbfc1

2023-10-10 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111764

Bug ID: 111764
   Summary: Wrong code at -O3 on x86_64-linux-gnu since
r11-5965-g04bff1bbfc1
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Bisected to r11-5965-g04bff1bbfc1

Compiler explorer: https://godbolt.org/z/7vaqadYfP

$ cat a.c
int printf(const char *, ...);
char a;
short b, c;
static short *d = , *e = 
short(f)(short g, short h) { return g * h; }
int main() {
  *e = 2;
  a = 1;
  for (; a <= 9; a++) {
short *i = 
*i = *d = f(*e, *e);
  }
  printf("%d\n", c);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -O3 a.c && ./a.out
4
%

[Bug tree-optimization/111671] New: ICE in get_default_value, at tree-ssa-ccp.cc:312

2023-10-03 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111671

Bug ID: 111671
   Summary: ICE in get_default_value, at tree-ssa-ccp.cc:312
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -O2/3 crashes.

Bisected to r14-2965-gc83528d2367

Compiler explorer: https://godbolt.org/z/MEnY9sYh5

$ cat a.c
int a, b, c, d;
int e() {
  if (a)
return 0;
  return -1;
}
static unsigned f(short);
void h() {
  int g = 59258;
  b = -50;
  g |= e() + b;
  f(g);
}
unsigned f(short i) {
  int *j[15], *k[15] = {};
  j[0] = 0;
  {
long l[4];
long m = *l, *n[] = {};
for (; c; c++)
  d = i;
int** o[] = {k, j};
  }
}
int main() {}
$
$ gcc -O2 a.c
during GIMPLE pass: ccp
a.c: In function ‘f.isra’:
a.c:14:10: internal compiler error: in get_default_value, at
tree-ssa-ccp.cc:312
   14 | unsigned f(short i) {
  |  ^
0x7ff11cd60082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug tree-optimization/111648] New: Wrong code at -O2/3 on x86_64-linux-gnu since r14-3243-ga7dba4a1c05

2023-09-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111648

Bug ID: 111648
   Summary: Wrong code at -O2/3 on x86_64-linux-gnu since
r14-3243-ga7dba4a1c05
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: prathamesh3492 at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3 produced the wrong code

Bisected to r14-3243-ga7dba4a1c05

Compiler explorer: https://godbolt.org/z/1bvWTrEK1

$ cat a.c
int printf(const char *, ...);
int a;
int *b = 
static int **c = 
static int d;
short e;
char f;
int main() {
  f = -21;
  for (; f < -5; f++) {
e = f ^ 3;
d = *b;
**c = e;
  }
  printf("%d\n", d);
}
$
$ gcc -O0 a.c && ./a.out
-6
$ gcc -O2 a.c && ./a.out
2
$

[Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932

2023-09-28 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111631

Bug ID: 111631
   Summary: Wrong code at -Os on x86_64-linux-gnu since
r14-3217-g4d6132e5932
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r14-3217-g4d6132e5932

Compiler explorer: https://godbolt.org/z/Yj9bq1ecs

$ cat a.c
int printf(const char *, ...);
short a, f, i;
static const int *e;
short *g;
long h;
int main() {
  {
unsigned j = i;
a = 1;
for (; a; a++) {
  {
long b = j, d = h;
int c = 0;
while (d--)
  *(char *)b++ = c;
  }
  if (e)
break;
}
j && (*g)--;
const int **k = 
*k = 0;
  }
  printf("%d\n", f);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
Segmentation fault
$ gcc -fsanitize=address,undefined a.c && ./a.out
0
$

[Bug tree-optimization/111614] New: [14 Regression] ICE at -O2: verify_gimple failed since r14-2282-gf703d2fd3f0

2023-09-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111614

Bug ID: 111614
   Summary: [14 Regression] ICE at -O2: verify_gimple failed since
r14-2282-gf703d2fd3f0
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2 crashes.

Bisected to r14-2282-gf703d2fd3f0

Compiler explorer: https://godbolt.org/z/xG5Tosvnc

$ cat a.c
int a, b, c, d, e;
static void f() {
  int *g = 
  b = 1;
  for (; b >= 0; b--) {
c = 0;
for (; c <= 1; c++)
  e = 0;
for (; e <= 1; e++) {
  int h, i = h = 13;
  for (; h; h--)
i = i << a;
  d &= i + c + 9 + *g;
}
  }
}
int main() {
  f();
  for (;;)
;
}
$
$ gcc -O3 a.c
a.c: In function ‘main’:
a.c:17:5: error: type mismatch in binary expression
   17 | int main() {
  | ^~~~
vector(2) int

vector(2) int

vector(2) unsigned int

_15 = vect__15.28_19 & _11;
during GIMPLE pass: reassoc
a.c:17:5: internal compiler error: verify_gimple failed
0x7f6a86416082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug middle-end/109967] [11/12/13/14 Regression] Wrong code at -O2 on x86_64-linux-gnu

2023-09-25 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109967

--- Comment #7 from Shaohua Li  ---
This test case does not reproduce anymore on the current trunk. Maybe one of
the recent fixes fixed the underlying issue as well.

[Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507

2023-09-25 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111583

Bug ID: 111583
   Summary: [13/14 Regression] Wrong code at -Os on
x86_64-linux-gnu since r13-3281-g6cc3394507
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Keywords: wrong-code
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: amacleod at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r13-3281-g6cc3394507

Compiler explorer: https://godbolt.org/z/8GM9YvMKb

$ cat a.c
int printf(const char *, ...);
int b, c, d;
char e;
short f;
const unsigned short **g;
char h(char k) {
  if (k)
return '0';
  return 0;
}
int l() {
  b = 0;
  return 1;
}
static short m(unsigned k) {
  const unsigned short *n[65];
  g = [4];
  k || l();
  long a = k;
  char i = 0;
  unsigned long j = k;
  while (j--)
*(char *)a++ = i;
  c = h(d);
  f = k;
  return 0;
}
int main() {
  long o = (e < 0) << 5;
  m(o);
  printf("%d\n", f);
}
$
$ gcc -O0 -fsanitize=address,undefined a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
32
$

[Bug tree-optimization/111572] New: Wrong code at -O2 on x86_64-linux-gnu since r14-301-gf2d6beb7a4d

2023-09-24 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111572

Bug ID: 111572
   Summary: Wrong code at -O2 on x86_64-linux-gnu since
r14-301-gf2d6beb7a4d
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: jh at suse dot cz
  Target Milestone: ---

gcc at -O2 produces the wrong code.

Bisected to r14-301-gf2d6beb7a4d

Compiler explorer: https://godbolt.org/z/reETd3ee4

$ cat a.c
int printf(const char *, ...);
int a, b = -8, e, f, h;
char c, d, g;
static int i(long k) {
  e = 8;
  for (; e; e = f) {
d = 6;
for (; d<7; d++) {
  unsigned char j = 0;
  for (; (unsigned char)(1 + k) + j <= 3; j++)
printf("%u\n", (unsigned char)(1 + k) + j);
}
for (; g; g++)
  ;
  }
  return 0;
}
int main() {
  h = 26 & b;
  i((short)(h - 65557) + 65535);
}
$
$ gcc -O0 a.c && ./a.out
3
$ gcc -O2 a.c && ./a.out
3
3
3
3
(Truncated)
$

[Bug tree-optimization/111571] New: [13/14 Regression] ICE in modify_call, at ipa-param-manipulation.cc:656

2023-09-24 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111571

Bug ID: 111571
   Summary: [13/14 Regression] ICE in modify_call, at
ipa-param-manipulation.cc:656
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: mjambor at suse dot cz
  Target Milestone: ---

gcc at -O2 crashes on the following testcase.

Bisected to r13-4685-g4834e9360f7

Compiler explorer: https://godbolt.org/z/3b9ra7Kf8

$ cat a.c
struct a {
  int b;
};
struct c {
  long d;
  struct a e;
  long f;
};
int g, h, i;
int j() {return 0;}
static void k(struct a l, int p) {
  if (h)
g = 0;
  for (; g; g = j())
if (l.b)
  break;
}
static void m(struct c l) {
  k(l.e, l.f);
  for (;; --i)
;
}
int main() {
  struct c n = {10, 9};
  m(n);
}
$
$ gcc -O2 a.c
during IPA pass: inline
a.c: In function ‘main’:
a.c:25:9: internal compiler error: in modify_call, at
ipa-param-manipulation.cc:655
   25 | m(n);
  | ^~~~
0x7f9be5bb7082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug tree-optimization/111519] New: [13/14 Regression] Wrong code at -O3 on x86_64-linux-gnu since r13-455-g1fe04c497d

2023-09-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111519

Bug ID: 111519
   Summary: [13/14 Regression] Wrong code at -O3 on
x86_64-linux-gnu since r13-455-g1fe04c497d
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: roger at nextmovesoftware dot com
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Bisected to r13-455-g1fe04c497d

Compiler explorer: https://godbolt.org/z/ozEaKa1rY

$ cat a.c
int printf(const char *, ...);
int a, o;
char b, f, i;
long c;
static signed char d;
static char g;
unsigned *h;
signed char *e = 
static signed char **j = 
static long k[2];
unsigned **l = 
short m;
int main(int q, char *r[]) {
  int p = 0;
  if (q == 0)
p = 1;
  signed char *n = 
  *n = 0;
  for (; c;)
for (; i; i--)
  ;
  g = 0;
  for (; g <= 1; g++) {
*n = **j;
k[g] = 0 != 
*e = l && k[0];
  }
  if (p)
printf();
  for (; o < 4; o++) {
a = d;
if (p)
  printf();
  }
  printf("%d\n", a);
}
$
$ gcc -O2 a.c && ./a.out
1
$ gcc -O3 a.c && ./a.out
0
$

[Bug tree-optimization/111514] [14 Regression] ICE: in lower_bound, at value-range.h:1078 since r14-3644-g1aceceb1e2

2023-09-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111514

--- Comment #2 from Shaohua Li  ---
(In reply to Andrew Pinski from comment #1)
> I suspect r14-4192-g4d80863d7f93c0a839d1fe5 fixed this ...

I checked the commit r14-4192-g4d80863d7f93c0a839d1fe5, and it indeed fixed the
issue.

[Bug tree-optimization/111514] New: [14 Regression] ICE: in lower_bound, at value-range.h:1078 since r14-3644-g1aceceb1e2

2023-09-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111514

Bug ID: 111514
   Summary: [14 Regression] ICE: in lower_bound, at
value-range.h:1078 since r14-3644-g1aceceb1e2
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: guojiufu at gcc dot gnu.org
  Target Milestone: ---

gcc at -O3 crashes on the following testcase.

Bisected to r14-3644-g1aceceb1e2

Compiler explorer: https://godbolt.org/z/65G54cY8Y

$ cat a.c
unsigned a;
int b, f, g, h;
int e[1];
void j() {
  int k;
  b = 0;
  for (; k;)
if (f)
  if (h)
b ^= 0 <= 0;
}
void i() {
  j();
  for (; a; ++a) {
{
  int c = b, d;
  if (b >= 'z' && d)
c = 5;
  g = c;
}
*e = g;
  }
}

int main() {}
$
$ gcc -O3 a.c
during GIMPLE pass: vrp
a.c: In function ‘i’:
a.c:12:6: internal compiler error: in lower_bound, at value-range.h:1078
   12 | void i() {
  |  ^
0x7fa1dcb81082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug tree-optimization/111472] Wrong code at -Os on x86_64-linux-gnu since r11-4563-gd0d8b5d836

2023-09-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111472

--- Comment #2 from Shaohua Li  ---
(In reply to Xi Ruoyao from comment #1)
> Another ivopts issue.
> 
> Note that if something is different with different -O levels it's almost
> never a "c" bug.  The "c" in component only covers C frontend which only
> contains very straightforward optimizations.

Thanks for the explanation!

[Bug c/111472] New: Wrong code at -Os on x86_64-linux-gnu since

2023-09-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111472

Bug ID: 111472
   Summary: Wrong code at -Os on x86_64-linux-gnu since
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: amacleod at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r11-4563-gd0d8b5d836

Compiler explorer: https://godbolt.org/z/EPznGbaje

With -fwrapv the issue goes away.

$ cat a.c
int printf(const char *, ...);
int a, b, e, f;
short c = -1, i;
char g;
int h[4][1] = {8, 5, 8, 5};
int main() {
  int *j = , *k = 
  unsigned short d = c;
  i = d >> b;
  *j = i;
  g = 0;
  for (; g <= 3; g++)
*k = h[(unsigned char)(1 + e) + g][0];
  printf("%d\n", f);
}
$
$ gcc -O0 a.c && ./a.out
5
$ gcc -Os a.c && ./a.out
Segmentation fault
$
$ gcc -fsanitize=undefined a.c && ./a.out
5
$

[Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45

2023-09-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469

Bug ID: 111469
   Summary: Wrong code at -Os on x86_64-linux-gnu since
r14-573-g69f1a8af45
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: pinskia at gcc dot gnu.org
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r14-573-g69f1a8af45

Compiler explorer: https://godbolt.org/z/fheon13dP

$ cat a.c
int printf(const char *, ...);
int a;
long b, c, e, f;
char *g;
unsigned short h = 5;
static unsigned short *i = 
unsigned j;
long k(long m, long n) {
  if (n)
e = m;
  c = e;
  return e;
}
char o() {
  char l;
  while (f)
;
  l = *g;
  return l;
}
int main() {
  int p;
  int q;
  for (; j - 9 >= 29; j = k(-95, *i) + 127) {
*i || o();
long d = h;
p = d == 0 ? 0 : b % d;
q = p;
int *r[1] = {};
  }
  printf("%d\n", a);
}
$
$ gcc a.c && ./a.out
0
$ gcc a.c -Os && ./a.out
segmentation fault
$

[Bug tree-optimization/111445] New: Wrong code at -Os on x86_64-linux-gnu since r12-1077-g57bf3751511

2023-09-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111445

Bug ID: 111445
   Summary: Wrong code at -Os on x86_64-linux-gnu since
r12-1077-g57bf3751511
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code

Bisected to r12-1077-g57bf3751511

Compiler explorer: https://godbolt.org/z/1Ej5jxYPa

$ cat a.c
int printf(const char *, ...);
short a, b;
unsigned char c = 255;
int main() {
  int d;
  unsigned char e;
  d = 0;
  for (; a >= 0; a--) {
int *f = 
*f = c;
  }
  e = 0;
  for (; (unsigned char)(d - 255) + e <= 1; e++)
printf("%d\n", b);
}
$
$ gcc -O0 a.c && ./a.out
0
0
$ gcc -Os a.c && ./a.out
$

[Bug tree-optimization/111444] New: Wrong code at -O2/3/s on x86_64-gnu since r14-3226-gd073e2d75d9

2023-09-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111444

Bug ID: 111444
   Summary: Wrong code at -O2/3/s on x86_64-gnu since
r14-3226-gd073e2d75d9
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: mjambor at suse dot cz
  Target Milestone: ---

gcc at -O2/3/s produced the wrong code.

Bisected to r14-3226-gd073e2d75d9

Compiler explorer: https://godbolt.org/z/xWj9z8foe

$ cat a.c
int printf(const char *, ...);
int a = 3, d, e;
int *b = 
char c;
short f;
const int **g;
static long h(int **i, int **j) {
  const int *k[46];
  const int **l = [5];
  *j = 
  g = l;
  for (; d; d = d + 1)
;
  **i = 0;
  return f;
}
int main() {
  int *m = 
  h(, );
  c = *b;
  printf("%d\n", c);
}
$
$ gcc -O0 a.c && ./a.out
3
$ gcc -O2 a.c && ./a.out
0
$

[Bug c/111443] New: ICE : Segmentation fault signal terminated program since r14-4038-gb975c0dc3be

2023-09-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111443

Bug ID: 111443
   Summary: ICE : Segmentation fault signal terminated program
since r14-4038-gb975c0dc3be
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: pinskia at gcc dot gnu.org
  Target Milestone: ---

gcc crashes at -O2.

Bisected to r14-4038-gb975c0dc3be

Compiler explorer: https://godbolt.org/z/zd6WfK5xT


$ cat a.c
int a, c, d;
char b;
void e() {
  char f;
  int g[] = {3};
  char *h;
  if (g[0])
for (; f; f--)
  ;
  c = 0;
  for (;;) {
*h = 0;
b = f - *h;
d = f * a;
  }
}
int main() {}
$
$ gcc -O2 a.c
gcc: internal compiler error: Segmentation fault signal terminated program cc1
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
See  for instructions.
$

[Bug tree-optimization/111422] New: Wrong code at -O3 on x86_64-linux-gnu

2023-09-15 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111422

Bug ID: 111422
   Summary: Wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Compiler explorer: https://godbolt.org/z/3b4v478TG

$ cat a.c
int printf(const char *, ...);
int a, b;
int *c = 
unsigned d;
char e;
int f=1;
int i(int k, char *l) {
  if (k < 6)
return a;
  l[0] = l[1] = l[k - 1] = 8;
  return 0;
}
int m(int k) {
  char g[11];
  int h = i(k, g);
  return h;
}
int main() {
  for (; b < 8; b = b + 1)
;
  int j;
  int *n[8];
  j = 0;
  for (;18446744073709551608U + m(*c) + *c + j < 2; j++){
n[j] = 
  }
  for (; e <= 4; e++)
d = *n[0] == f;
  printf("%d\n", d);
}
$
$ gcc -O0 a.c && ./a.out
1
$ gcc -O3 a.c && ./a.out
Segmentation fault
$ gcc -O3 -fwrapv a.c && ./a.out 
Segmentation fault
$ gcc -fsanitize=address,undefined a.c && ./a.out
1
$

[Bug tree-optimization/111414] New: ICE in verify_gimple failed since r14-3719-gb34f3736356

2023-09-14 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111414

Bug ID: 111414
   Summary: ICE in verify_gimple failed since
r14-3719-gb34f3736356
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O3 crashes on the following testcase.

Bisected to r14-3719-gb34f3736356

Compiler explorer: https://godbolt.org/z/xeh66znqd

$ cat a.c
int a, b, c, d, e, f, g;
int h(int i) { return b >= 2 ?: i >> b; }
void j() {
  int k;
  int *l = 
  for (; d; d++) {
g = h(0 != j);
f = g >> a;
k = f << 7;
e = k > 5 ? k : 0;
*l ^= e;
  }
}
int main() {}
$
$ gcc -O2 a.c
a.c: In function 'j':
a.c:3:6: error: non-vector operands in vector comparison
3 | void j() {
  |  ^
int
int
mask__21.44_181 = a.4_1 == 0;
during GIMPLE pass: vect
a,c:3:6: internal compiler error: verify_gimple failed
0x2206f8e internal_error(char const*, ...)
???:0
0x1129df9 verify_gimple_in_cfg(function*, bool, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1

[Bug tree-optimization/111408] New: [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since r14-2866-ge68a31549d9

2023-09-13 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111408

Bug ID: 111408
   Summary: [14 Regression] Wrong code at -O2/3 on
x86_64-linux-gnu since r14-2866-ge68a31549d9
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O2/s produced the wrong code.

Bisected to r14-2866-ge68a31549d9

Compiler explorer: https://godbolt.org/z/secjqP8ao

$ cat a.c
int printf(const char *, ...);
int a, b, c, d;
short e;
int f() {
  c = a % (sizeof(int) * 8);
  if (b & 1 << c)
return -1;
  return 0;
}
int main() {
  for (; e != 1; e++) {
int g = f();
if (g + d - 9 + d)
  continue;
for (;;)
  __builtin_abort();
  }
}
$
$ gcc -O0 a.c && ./a.out
$
$ gcc -O2 a.c && ./a.out
[2]1281121 abort  ./a.out
$

[Bug tree-optimization/111389] New: ICE in check_loop_closed_ssa_def, at tree-ssa-loop-manip.cc:647

2023-09-12 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111389

Bug ID: 111389
   Summary: ICE in check_loop_closed_ssa_def, at
tree-ssa-loop-manip.cc:647
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: hubicka at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2 crashes on the following testcase.

Bisected to r14-301-gf2d6beb7a4d

Compiler explorer: https://godbolt.org/z/o98qrd5nr

$cat a.c
int *a;
char b;
int d;
int e(int f) {
  int c = 0;
  for (; f > 1; c++)
f >>= 1;
  return c;
}
void g() {
  for (;;) {
for (; d; d++)
  ;
b = 0;
for (; e(92) - 6 + b; b = b + 8)
  *a = 0;
  }
}
int main() {}
$ gcc -O0 a.c && ./a.out
$ gcc -O2 a.c
during GIMPLE pass: ch_vect
a.c: In function ‘g’:
a.c:10:6: internal compiler error: in check_loop_closed_ssa_def, at
tree-ssa-loop-manip.cc:645
   10 | void g() {
  |  ^
0x7f8ffe5f1082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions
$

[Bug c/111383] New: Wrong code at -Os on x86_64-linux-gnu since r12-5138-ge82c382971

2023-09-12 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111383

Bug ID: 111383
   Summary: Wrong code at -Os on x86_64-linux-gnu since
r12-5138-ge82c382971
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r12-5138-ge82c382971

Compiler explorer: https://godbolt.org/z/eYY31rn4d

$ cat a.c
int printf(const char *, ...);
int a, d = 1625015426;
char e;
short b;
short *f = , *g = 
void h(char *k) {
  char c = *k;
  for (; c;)
;
}
int main() {
  *g = 25330;
  int i, j;
  i = 0;
  for (; *f + d - 1625040257 < 7;)
;
  for (; i < 4; i++) {
j = 0;
for (; (d - 1625015511) + (d - 1625015341) + j < 1; j++)
  h();
  }
  printf("%d\n", a);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
(Timeout)
$
$ gcc -fsanitize=address,undefined a.c && ./a.out
0
$

[Bug c/111365] New: Wrong code at -O3 since r13-1268-g8c99e307b20

2023-09-11 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111365

Bug ID: 111365
   Summary: Wrong code at -O3 since r13-1268-g8c99e307b20
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -O3 produced the wrong code.

Bisected to r13-1268-g8c99e307b20

Compiler explorer: https://godbolt.org/z/5rb3sTG3E

$ cat a.c
int printf(const char *, ...);
int a, c, d, e = -1233286202, f = -1233286202;
short b, g, j;
int k(int l) {
  if (l <= 0 ||  + l > )
return -1;
  return 0;
}
int m(int l) {
  int h = k(l);
  return h;
}
int main() {
  int i = 0;
  for (;
   (m(f + 1233286202) + e + (f + 1233286202) + 1233220671) + 65532U + i <
9;
   i++)
g = 6;
  printf("%d\n", g);
}
$
$ gcc -O0 a.c && ./a.out
6
$ gcc -O3 a.c && ./a.out
0
$ gcc -fsanitize=address,undefined a.c && ./a.out
6
$

[Bug tree-optimization/111336] [14 Regression] Wrong code at -O2/3 since r14-2472-g14b10ff30ad

2023-09-08 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111336

Shaohua Li  changed:

   What|Removed |Added

 CC||yinyuefengyi at gmail dot com

--- Comment #2 from Shaohua Li  ---
I have another similar test case that even affects GCC-12 (bisected to
r12-6087-g51a24e4a984)

Compiler explorer: https://godbolt.org/z/d6hjfGqzj

I reported another bug111331, which also looks similar but has different
bisection point.

$ cat a.c
int printf(const char *, ...);
int a, b;
long c = 3521733542;
int d[2];
int e(int f, int g) {
  if (f == 0)
return 0;
  if (f > 200)
return 0;
  if (g)
return 5000 * f;
  return 0;
}
int main() {
  int h = 0;
  for (;e((int)c + 773233762, c + 773233760) + (int)c + 773228714 + h < 2; h++)
d[h] = b;
  printf("%d\n", a);
}
$

[Bug c/111336] New: Wrong code at -O2/3 since r14-2472-g14b10ff30ad

2023-09-08 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111336

Bug ID: 111336
   Summary: Wrong code at -O2/3 since r14-2472-g14b10ff30ad
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: hubicka at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3 produced the wrong code on the following testcase.

Bisected to r14-2472-g14b10ff30ad

Compiler explorer: https://godbolt.org/z/njdcv5aK8

$ cat a.c
int printf(const char *, ...);
int a, b;
long c = 3521733542;
int d[2];
int e(int f, int g) {
  if (f == 0)
return 0;
  if (f > 200)
return 0;
  if (g)
return 5 * f;
  return 0;
}
int main() {
  int h = 0;
  for (; e((int)c + 773233762, c + 60) + 773163185 + h < 2; h++)
d[h] = b;
  printf("%X\n", a);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -O2 a.c && ./a.out
Segmentation fault
$

[Bug c/111331] New: Wrong code at -O1 on x86_64-linux-gnu since

2023-09-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111331

Bug ID: 111331
   Summary: Wrong code at -O1 on x86_64-linux-gnu since
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O1 produced the wrong code.

Bisected to r9-3606-g1cab645d3e3

Compiler explorer: https://godbolt.org/z/5YEv44PTa

$ cat a.c
int printf(const char *, ...);
int a;
int b;
int c(int d, int e, int f) {
  if (d < e)
return e;
  if (d > f)
return f;
  return d;
}
int main() {
  int g = -1;
  a = c(b + 30, 29, g + 29);
  printf("%d\n", a);
}
$
$ gcc -O0 a.c && ./a.out
28
$ gcc -O1 a.c && ./a.out
29
$

[Bug c/111328] New: ICE: verify_flow_info failed since r14-3459-g0c78240fd7d

2023-09-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111328

Bug ID: 111328
   Summary: ICE: verify_flow_info failed since
r14-3459-g0c78240fd7d
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: jh at suse dot cz
  Target Milestone: ---

gcc at -O3 crashes on the following testcase.

Bisected to r14-3459-g0c78240fd7d

Compiler explorer: https://godbolt.org/z/G3rPdq6db


$ cat a.c
int a, b, c, d;
short e;
int f(g, h) { return h == 0 || g == 83647 && h == 1 ?: g / h; }
char *i(char *g) {
  if (a)
do
  if (*g++ == 0)
return 0;
while (a);
  return g;
}
int j() {
  char k = 0, l = *i() = l;
  for (; b; b++) {
c = 1;
for (; d + c >= 0; c--)
  ;
  }
  for (;;)
if (f(e))
  break;
}
int main() {}
$ gcc -O2 a.c
: In function 'f':
:3:5: warning: type of 'g' defaults to 'int' [-Wimplicit-int]
3 | int f(g, h) { return h == 0 || g == 83647 && h == 1 ?: g / h; }
  | ^
:3:5: warning: type of 'h' defaults to 'int' [-Wimplicit-int]
: In function 'j':
:12:5: error: count of bb 32 not initialized
   12 | int j() {
  | ^
:12:5: error: count of bb 33 not initialized
:12:5: error: count of bb 34 not initialized
:12:5: error: count of bb 35 not initialized
:12:5: error: count of bb 37 not initialized
during GIMPLE pass: vect
:12:5: internal compiler error: verify_flow_info failed
0x21d80ae internal_error(char const*, ...)
???:0
0xb8c64f verify_flow_info()
???:0
0x112933f cleanup_tree_cfg(unsigned int)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1
$

[Bug c/111319] Wrong code at -O2 on x86_64-linux-gnu

2023-09-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111319

--- Comment #4 from Shaohua Li  ---
(In reply to Xi Ruoyao from comment #3)
> Please try not to create more reports with "not sure if there is UB" esp.
> this UB should be obvious, and it's also detectable with
> -fsanitize=undefined:
> 
> t.c:13:7: runtime error: load of address 0x7ffd53183020 with insufficient
> space for an object of type 'int'
> 0x7ffd53183020: note: pointer points here
>  2a 56 00 00  01 00 00 00 00 00 00 00  00 14 1a ed ca 50 d4 0e  00 00 00 00
> 00 00 00 00  98 31 18 53
>   ^

UBSan only detects it at -O2 level and I used `-O0
-fsanitize=address,undefined` to detect if there is any report.

https://godbolt.org/z/zvcG8znvT

[Bug c/111319] New: Wrong code at -O2 on x86_64-linux-gnu

2023-09-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111319

Bug ID: 111319
   Summary: Wrong code at -O2 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

The executable produced by gcc -O2 would crash. Not sure if there is UB in the
code or not as `h` has not been dereferenced after `h--`.

Compiler explorer: https://godbolt.org/z/avPze

$ cat a.c
int printf(const char *, ...);
int a, b = 5, c, d;
int e[2] = {0, 0};
int i() {
  int f = 0;
  int g[2] = {1, f};
  int *h = g;
  h--;
  if (!b)
while (h >=  == 1)
  h--;
  h++;
  d = *h;
  return d;
}
int main() {
  if (e[i()])
e[0] = 0;
  printf("%d\n", a);
}
$
$ gcc -O2 a.c && ./a.out
Segmentation fault
$

[Bug c/111303] ICE: in type, at value-range.h:869

2023-09-06 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111303

Shaohua Li  changed:

   What|Removed |Added

 CC||guojiufu at gcc dot gnu.org

--- Comment #1 from Shaohua Li  ---
Bisected to r14-3644-g1aceceb1e2

[Bug c/111303] New: ICE: in type, at value-range.h:869

2023-09-06 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111303

Bug ID: 111303
   Summary: ICE: in type, at value-range.h:869
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O2 crashes on the following test case.

Compiler explorer: https://godbolt.org/z/qK6dMTK14

$ cat a.c
unsigned char a;
int b(int c) {
  if (c >= 5000)
return c / 5;
}
void d() { b(a - 5); }
int main() {}
$
$ gcc -O2 a.c
during GIMPLE pass: evrp
: In function 'd':
:7:1: internal compiler error: in type, at value-range.h:869
7 | int main() {}
  | ^~~
0x21af71e internal_error(char const*, ...)
???:0
0x9dd814 fancy_abort(char const*, int, char const*)
???:0
0x16cada5 gimple_simplify_TRUNC_DIV_EXPR(gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), code_helper, tree_node*, tree_node*, tree_node*)
???:0
0x180c22a gimple_match_op::resimplify(gimple**, tree_node* (*)(tree_node*))
???:0
0x180c880 gimple_simplify(gimple*, gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), tree_node* (*)(tree_node*))
???:0
0x1f41940 gimple_ranger::fold_stmt(gimple_stmt_iterator*, tree_node*
(*)(tree_node*))
???:0
0x13c5478 rvrp_folder::fold_stmt(gimple_stmt_iterator*)
???:0
0x12a653e substitute_and_fold_dom_walker::before_dom_children(basic_block_def*)
???:0
0x1f09107 dom_walker::walk(basic_block_def*)
???:0
0x12a568b substitute_and_fold_engine::substitute_and_fold(basic_block_def*)
???:0
0x13c4f9c execute_ranger_vrp(function*, bool, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1
$

[Bug c/111256] New: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8

2023-08-31 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111256

Bug ID: 111256
   Summary: Wrong code at -O2/3/s since r10-1615-g75efe9cb1f8
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3/s produces the wrong code.

Bisected to r10-1615-g75efe9cb1f8

Compiler explorer: https://godbolt.org/z/WPzEMoW6e

$ cat a.c
int printf(const char *, ...);
int a, d, e, g;
long b, h;
long i() {
  b++;
  return b;
}
int l(int m[], int p[]) {
  if (d)
for (; e; e++) {
  m[4] = m[0] = m[1] ^ m[2] ^ m[5];
  m[7] = m[3] ^ m[6];
  m += 4;
}
  m[6] = m[0] ^ 1;
  m[7] = m[1] ^ m[2] ^ m[7];
  m[9] = m[3] ^ m[8];
  return 1;
}
int fn3() {
  int j[] = {0, 7, 0, 0, 5, 0, 0, 8, 0, 0};
  int k[17];
  int c = l(j, k);
  return c;
}
int main() {
  for (; h <= 3; h = fn3() + h) {
long n[2];
for (; i() < 2;)
  n[g] = 508;
for (; (int)n[0] < 2;) {
  char o[] = {3, 4, 6, 3, 0, 0, 5, 6, 6, 1, 7, 0, 0, 0, 0, 0};
  char *f = o;
  for (; *f; ++f)
;
}
  }
  printf("%X\n", a);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -O2 a.c
% ./a.out
(Timeout)

[Bug tree-optimization/111233] [14 Regression] Wrong code at -O3 on x86_64-linux-gnu since r14-2852-gf5fb9ff2396

2023-08-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111233

--- Comment #2 from Shaohua Li  ---
(In reply to Xi Ruoyao from comment #1)
> (In reply to Shaohua Li from comment #0)
> 
> >   printf("%d\n", a);g
> 
> I assume the "g" is a typo?

Oh, that's indeed a typo. Sorry for that.

[Bug c/111233] New: Wrong code at -O3 on x86_64-linux-gnu since r14-2852-gf5fb9ff2396

2023-08-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111233

Bug ID: 111233
   Summary: Wrong code at -O3 on x86_64-linux-gnu since
r14-2852-gf5fb9ff2396
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: hubicka at gcc dot gnu.org, jh at suse dot cz
  Target Milestone: ---

gcc at -O3 produces the wrong code.

Bisected to r14-2852-gf5fb9ff2396

Compiler explorer: https://godbolt.org/z/vrEMjKr9f

$ cat a.c
int printf(const char *, ...);
int a, c, f;
char b, g;
int *d = 
long e;
int main() {
  for (; e != 25; e++) {
f = -17;
for (; f <= 0; f = f + 7) {
  g = f ? 0 : b;
  a = *d;
}
  }
  printf("%d\n", a);g
}
$
$ gcc -O2 a.c && ./a.out
0
$ gcc -O3 a.c
$ ./a.out
(Timeout)
$

[Bug c/111210] Wrong code at -Os on x86_64-linux-gnu since r12-4849-gf19791565d7

2023-08-28 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111210

--- Comment #5 from Shaohua Li  ---
Thanks for all your comments!

[Bug c/111210] Wrong code at -Os on x86_64-linux-gnu since r12-4849-gf19791565d7

2023-08-28 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111210

--- Comment #2 from Shaohua Li  ---
(In reply to Alexander Monakov from comment #1)
> 'c' is called with 'd' pointing to 'long e[2]', so
> 
>   return *(int *)(d + 1);
> 
> is an aliasing violation (dereferencing a pointer to an incompatible type).

Thanks for the quick diagnosis. I tried to enable -Wall -Wextra -pedantic but
got no warning about the test case. Could you share how you diagnose this
issue?

[Bug c/111210] New: Wrong code at -Os on x86_64-linux-gnu since r12-4849-gf19791565d7

2023-08-28 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111210

Bug ID: 111210
   Summary: Wrong code at -Os on x86_64-linux-gnu since
r12-4849-gf19791565d7
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -Os produces the wrong code.

Bisected to r12-4849-gf19791565d7

Compiler explorer: https://godbolt.org/z/fjcEvKdYT

$ cat a.c
int printf(const char *, ...);
int a;
int *b = 
int c(long *d) {
  if (*d)
return *(int *)0;
  return *(int *)(d + 1);
}
int main() {
  long e[] = {0, 100};
  int f = c(e);
  *b = f;
  printf("%d\n", a);
}
$
$ gcc -O3 a.c && ./a.out
100
$ gcc -Os a.c && ./a.out
0
$

[Bug c/111137] New: Wrong code at -O2/3 since r12-1000-g6924b5e6bd3

2023-08-24 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37

Bug ID: 37
   Summary: Wrong code at -O2/3 since r12-1000-g6924b5e6bd3
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -O2/3 produces the wrong code.

Bisected to r12-1000-g6924b5e6bd3

Compiler explorer: https://godbolt.org/z/9fo5dxxhf

$ cat a.c
int printf(const char *, ...);
char a;
int b[3][8];
int c, e = 1, f, g;
short d;
int main() {
  for (; e >= 0; e--) {
d = 1;
for (; d >= 0; d--) {
  c = 0;
  for (; c <= 1; c++) {
b[0][d * 2 + c + 1] = 0;
g = a <= '7';
b[g - 1 + d][c] ^= 1;
  }
}
  }
  printf("%d\n", b[0][1]);
}
$
$ gcc -O0 a.c && ./a.out
1
$ gcc -O2 a.c && ./a.out
0
$

[Bug c/111128] New: ICE: tree check: expected class 'type', have 'exceptional' (error_mark) in useless_type_conversion_p, at gimple-expr.cc:85

2023-08-24 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28

Bug ID: 28
   Summary: ICE: tree check: expected class 'type', have
'exceptional' (error_mark) in
useless_type_conversion_p, at gimple-expr.cc:85
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O2/3 crashes on the following test case.

Bisected to r14-2987-g1a599caab8

Compiler explorer: https://godbolt.org/z/dxT134o4d

$ cat a.c
int a, b, c, e, g;
short *d;
unsigned char f;
int h() {
  f &= g;
  for (; b; b++) {
a = 2;
for (; a; a--)
  c = 0;
if (c)
  continue;
e = (unsigned short)*d >> f;
  }
}
int main() {}
$
$ gcc -O2 a.c 
during GIMPLE pass: vect
a.c: In function ‘h’:
a.c:4:5: internal compiler error: tree check: expected class ‘type’, have
‘exceptional’ (error_mark) in useless_type_conversion_p, at gimple-expr.cc:85
4 | int h() {
  | ^
0x2185dae internal_error(char const*, ...)
???:0
0x89cd86 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
???:0
0x1109f71 verify_gimple_in_cfg(function*, bool, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions
$

[Bug c/111043] New: ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1068

2023-08-16 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111043

Bug ID: 111043
   Summary: ICE in adjust_loop_info_after_peeling, at
tree-ssa-loop-ivcanon.cc:1068
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
CC: jh at suse dot cz
  Target Milestone: ---

gcc crashes at -O2 on the following test case.

Bisected to r14-2675-gef28aadad6e, could be similar to bug 110769 and bug
110641, but the bisection points are different.

Compiler explorer: https://godbolt.org/z/Ghza4o7d4

$ cat a.c
int a, b, c, d;
short e;
int f() {
  a = 1;
  while (a) {
c = b % a;
b = a;
a = c;
  }
  return b;
}
int g() {
  d = 0;
  for (; d <= 1; d++)
e = 0;
  for (; f() + d - 3 + e; e = e + 8)
;
}
int main() {}
$
$ gcc-r14-2675-gef28aadad6e  -O2 a.c
during GIMPLE pass: ch_vect
a.c: In function ‘g’:
a.c:12:5: internal compiler error: in adjust_loop_info_after_peeling, at
tree-ssa-loop-ivcanon.cc:1068
   12 | int g() {
  | ^
0x21789ce internal_error(char const*, ...)
???:0
0x9d3f84 fancy_abort(char const*, int, char const*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug c/111000] New: Wrong code at -O3 on x86_64-linux-gnu since r14-2944-g3d48c11ad08

2023-08-12 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111000

Bug ID: 111000
   Summary: Wrong code at -O3 on x86_64-linux-gnu since
r14-2944-g3d48c11ad08
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O3 produces the wrong code.

Bisected to r14-2944-g3d48c11ad08

Compiler explorer: https://godbolt.org/z/b67W17Gvb

$ cat a.c
int printf(const char *, ...);
long a = 68;
int b, d, e;
int main() {
  for (; d <= 6; d++) {
b = 0;
for (; b <= 6; b++) {
  int c = a;
  e = c >= 32 || d > 647 >> c ? d : 0;
}
  }
  printf("%d\n", e);
}
$
$ gcc -O0 a.c &&./a.out
6
$ gcc -O3 a.c && ./a.out
4
$

[Bug c/110929] New: ICE: verify_ssa failed since r14-2946-g46c8c225455

2023-08-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110929

Bug ID: 110929
   Summary: ICE: verify_ssa failed since r14-2946-g46c8c225455
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

A recent regression since r14-2946-g46c8c225455

$ cat a.c
int a, b, c, d, f, g, h, i;
static int e = 1;
int l();
int j() {
  l();
  for (; b;)
if (e)
  break;
  g = d;
  f = d && c;
  if (f)
;
  else {
  k:
h ^= 0;
for (;;)
  if (b)
goto k;
  }
}
int l() {
  int *m = 
  d && (*m = i);
}
int main() {}
$
$ gcc-r14-2946-g46c8c225455 -O2 a.c
: In function 'j':
:4:5: error: stmt with wrong VUSE
4 | int j() {
  | ^
# VUSE <.MEM_7(D)>
pretmp_6 = b;
expected .MEM_26
during GIMPLE pass: sink
:4:5: internal compiler error: verify_ssa failed
0x21705ce internal_error(char const*, ...)
???:0
0x132320e verify_ssa(bool, bool)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$

[Bug c/110887] New: ICE: gcc: internal compiler error: Segmentation fault signal terminated program cc1 since r14-2925-g2bae476b511

2023-08-03 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110887

Bug ID: 110887
   Summary: ICE: gcc: internal compiler error: Segmentation fault
signal terminated program cc1 since
r14-2925-g2bae476b511
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O2 crashes on the test case.

Bisected to r14-2925-g2bae476b511

$ cat a.c
int printf(const char *, ...);
short a;
char b;
long c;
int d;
int main() {
  int e = 0;
  for (; e <= 9; e++) {
d &= 1;
if (a)
  c = d ^= 1;
b ^= --d;
  }
  printf("%d\n", b);
}
$
$ gcc-2bae476b511dc441bf61da8a49cca655575e7dd6 -O2 a.c
gcc: internal compiler error: Segmentation fault signal terminated program cc1
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
See  for instructions.
$

[Bug ipa/110753] [14 Regression] ICE in meet_with_1, at ipa-cp.cc:1057

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110753

--- Comment #2 from Shaohua Li  ---
Bisect to r14-2379-gc496d15954c, which was committed by @al...@redhat.com

[Bug middle-end/110233] [12/13/14 Regression] Wrong code at -Os on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110233

--- Comment #11 from Shaohua Li  ---
(In reply to Sam James from comment #10)
> (In reply to Sam James from comment #9)
> > (In reply to Shaohua Li from comment #8)
> > > I tried to bisect it and I bisected it to r12-4871-g502ffb1f389
> > 
> > Could you try bisect further back with -param=vrp2-mode=vrp, or does it work
> > fine with that?
> 
> sorry: =ranger

Could you make it clear which parameters I should try? Thanks.

[Bug tree-optimization/110769] [14 Regression] ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110769

--- Comment #3 from Shaohua Li  ---
I tried to bisect it and it was bisected to r14-2674-gd0de3bf9175, which is
different from the bisection point in bug110641

[Bug middle-end/110702] [12/13/14 Regression] Wrong code at -O1 on x86_64-linux-gnu (regression since GCC-12.2)

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110702

--- Comment #3 from Shaohua Li  ---
Bisect to r13-550-gebce0e9bd8d

[Bug tree-optimization/110641] [14 Regression] ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110641

--- Comment #2 from Shaohua Li  ---
Bisect to r14-2230-g7e904d6c7f2

[Bug tree-optimization/110640] [13/14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since GCC-13

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110640

--- Comment #5 from Shaohua Li  ---
Bisect to r12-1653-gcb448ade74d

[Bug tree-optimization/110582] [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110582

--- Comment #5 from Shaohua Li  ---
Bisect to r14-1179-g1cd5bc387c4

[Bug tree-optimization/110243] [13/14 Regression] Wrong code at -O3 on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110243

--- Comment #6 from Shaohua Li  ---
I tried to bisect it and it was bisected to r13-3875-g9e11ceef165

[Bug middle-end/110233] [12/13/14 Regression] Wrong code at -Os on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110233

--- Comment #8 from Shaohua Li  ---
I tried to bisect it and I bisected it to r12-4871-g502ffb1f389

[Bug middle-end/110141] Wrong code at -O2 on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110141

--- Comment #2 from Shaohua Li  ---
I tried to bisect this case and I bisected it to r12-4790-g4b3a325f07a

[Bug middle-end/110115] Wrong code at -O1 on x86_64-linux-gnu

2023-07-30 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110115

--- Comment #5 from Shaohua Li  ---
I tried to bisect this case and I bisected it to r0-2686-gd119f34c952

[Bug middle-end/109967] [11/12/13/14 Regression] Wrong code at -O2 on x86_64-linux-gnu

2023-07-28 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109967

--- Comment #6 from Shaohua Li  ---
Bisected to r9-2635-g78ea9abc201

[Bug target/107172] [13 Regression] wrong code with "-O1 -ftree-vrp" on x86_64-linux-gnu since r13-1268-g8c99e307b20c502e

2023-07-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107172

--- Comment #52 from Shaohua Li  ---
*** Bug 107257 has been marked as a duplicate of this bug. ***

[Bug target/107257] [13 Regression] Wrong code at -O2 on x86_64-linux-gnu since r13-857-gf1652e3343b1ec47

2023-07-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107257

Shaohua Li  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|WAITING |RESOLVED

--- Comment #9 from Shaohua Li  ---
Sorry, this is indeed a dup.

*** This bug has been marked as a duplicate of bug 107172 ***

[Bug target/107257] [13 Regression] Wrong code at -O2 on x86_64-linux-gnu since r13-857-gf1652e3343b1ec47

2023-07-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107257

Shaohua Li  changed:

   What|Removed |Added

 Resolution|DUPLICATE   |---
 Status|RESOLVED|WAITING

--- Comment #8 from Shaohua Li  ---
This bug is not a dup of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107172,
which has been fixed but the trunk is still faulty on this test case.

[Bug c/110769] New: ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023

2023-07-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110769

Bug ID: 110769
   Summary: ICE in adjust_loop_info_after_peeling, at
tree-ssa-loop-ivcanon.cc:1023
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

Looks like a recent regression.

Compiler explorer: https://godbolt.org/z/eMh54dYKz

$ cat a.c
int a;
int b(unsigned d) {
  int c = 0;
  for (; d; c++)
d >>= 1;
  return c;
}
int main() {
  a = 0;
  for (; b(31) + a > 21; a = a + (unsigned)8)
;
  for (;;)
;
}
$
$ gcc-tk -O3 a.c
during GIMPLE pass: ch_vect
crash_0_reduced.c: In function ‘main’:
crash_0_reduced.c:8:5: internal compiler error: in
adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023
8 | int main() {
  | ^~~~
0x216183e internal_error(char const*, ...)
???:0
0x9d1376 fancy_abort(char const*, int, char const*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8cbdb2e4d64461d8a19e033bd33b585187059d8a/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8cbdb2e4d64461d8a19e033bd33b585187059d8a
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230721 (experimental) (GCC) 
$

[Bug c/110753] New: ICE in meet_with_1, at ipa-cp.cc:1057

2023-07-20 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110753

Bug ID: 110753
   Summary: ICE in meet_with_1, at ipa-cp.cc:1057
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a recent regression. 

Compiler explorer: https://godbolt.org/z/sGjbfYj16

$ cat a.c
int a, b, c;
int d(long e, long f) { return f == 0 || e && f == 1 ?: f; }
int g() {}
static int h(long e) {
  b = e + 4294967295;
  a = d(b || d(e, 8), g());
}
int i() {
  c = i;
  h(c);
}
int main() {}
$
$ gcc-tk -O3 a.c
: In function 'i':
:9:5: warning: assignment to 'int' from 'int (*)()' makes integer from
pointer without a cast [-Wint-conversion]
9 |   c = i;
  | ^
during IPA pass: cp
: At top level:
:12:1: internal compiler error: in meet_with_1, at ipa-cp.cc:1057
   12 | int main() {}
  | ^~~
0x215ca2e internal_error(char const*, ...)
???:0
0x9cfbf0 fancy_abort(char const*, int, char const*)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
Compiler returned: 1
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC) 
$

[Bug c/110738] GCC trunk failed to do some optimizations since GCC-8

2023-07-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110738

--- Comment #3 from Shaohua Li  ---
Would this test case be interesting? If no, I won't report other similar
issues.

https://godbolt.org/z/9xr1rv37s

[Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8

2023-07-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110738

Bug ID: 110738
   Summary: GCC trunk failed to do some optimizations since GCC-8
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following test case, gcc trunk at -O3 emits a relatively large assembly
code since GCC-8. Clang can remove all the code.

Compiler explorer: https://godbolt.org/z/hzf8Pr484

The test case is adapted from an official GCC test case:
https://github.com/gcc-mirror/gcc/blob/ae862e0e47cb2d62d7c624ab999a3bd8bd2914ef/gcc/testsuite/gcc.dg/strncmp-3.c

I only changed `int neg=0` to `int neg=1`. 

$ gcc-tk -O3 -S -o trunk.s a.c
$ gcc-7.4 -O3 -S -o old.s a.c
$ wc trunk.s old.s
 217  654 5999 trunk.s
  11   19  175 old.s
 228  673 6174 total
$
$ cat a.c
#define AB_D "ab\0d"
#define ABCDEF_H "abcdef\0h"
#define ABCDEFGHIJKLMN_P "abcdefghijklmn\0p"

char ab_d[] = AB_D;
char abcdef_h[] = ABCDEF_H;

extern int strncmp (const char*, const char*, __SIZE_TYPE__);

__attribute__((noipa)) void sink (const void *p, ...) { (void) }

#define strncmp(a, b, n) (sink (a, b), strncmp (a, b, n))

int main (void)
{
  int zero = 0;

  zero += strncmp (ab_d, AB_D,1);
  zero += strncmp (ab_d, AB_D,2);
  zero += strncmp (ab_d, AB_D,3);
  zero += strncmp (ab_d, AB_D,4);
  zero += strncmp (ab_d, AB_D,5);

  zero += strncmp (ab_d, ABCDEF_H,1);
  zero += strncmp (ab_d, ABCDEF_H,2);

  zero += strncmp (abcdef_h, AB_D,2);

  zero += strncmp (abcdef_h, ABCDEF_H,2);
  zero += strncmp (abcdef_h, ABCDEF_H,3);
  zero += strncmp (abcdef_h, ABCDEF_H,4);
  zero += strncmp (abcdef_h, ABCDEF_H,5);
  zero += strncmp (abcdef_h, ABCDEF_H,6);
  zero += strncmp (abcdef_h, ABCDEF_H,7);
  zero += strncmp (abcdef_h, ABCDEF_H,8);
  zero += strncmp (abcdef_h, ABCDEF_H,9);
  if (zero != 0)
__builtin_abort ();
  int neg = 1;
  neg -= strncmp (ab_d, ABCDEF_H,3) <0;
  neg -= strncmp (ab_d, ABCDEF_H,4) <0;
  neg -= strncmp (ab_d, ABCDEF_H,5) <0;
  neg -= strncmp (ab_d, ABCDEF_H,6) <0;
  neg -= strncmp (ab_d, ABCDEF_H,7) <0;
  neg -= strncmp (ab_d, ABCDEF_H,8) <0;
  neg -= strncmp (ab_d, ABCDEF_H,9) <0;
  if (neg !=-7){
__builtin_abort ();
  }
}
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-ec842611618c9f8a50f3326d42c51961de8b28a5/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-ec842611618c9f8a50f3326d42c51961de8b28a5
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230719 (experimental) (GCC) 
$

[Bug c/110732] New: Wrong code at -Os on x86_64-linux-gnu (recent regression)

2023-07-19 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110732

Bug ID: 110732
   Summary: Wrong code at -Os on x86_64-linux-gnu (recent
regression)
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a recent regression. gcc at -Os produces the wrong code.

Compiler explorer: https://godbolt.org/z/WWdxfzPrc

$ cat a.c
int printf(const char *, ...);
int a;
char c[] = {0, 0, -4L};
char d, e;
int main() {
  int f;
  int *g = 
  *g = 1;
  for (; e <= 2; e++)
for (;;) {
  {
{
  int b = c[e];
  f = b < 0 ? b : b >> 6;
}
d = f && a;
  }
  break;
}
  printf("%d\n", d);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -Os a.c && ./a.out
-1
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC) 
$

[Bug c/110702] New: Wrong code at -O1 on x86_64-linux-gnu (regression since GCC-12.2)

2023-07-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110702

Bug ID: 110702
   Summary: Wrong code at -O1 on x86_64-linux-gnu (regression
since GCC-12.2)
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a regression since GCC-12.2.

Compiler explorer: https://godbolt.org/z/655af97j7

$ cat a.c
int printf(const char *, ...);
int a, b, c, d;
long e[9][7][4];
void f() {
  for (; a >= 0; a--) {
b = 0;
for (; b <= 3; b++) {
  c = 0;
  for (; c <= 3; c++) {
int *g = 
*g = e[0][0][b] | e[a][b][a];
  }
}
  }
}
int main() {
  f();
  printf("%d\n", a);
}
$
$ gcc-tk -O0 a.c && ./a.out
-1
$ gcc-tk -O1 a.c && ./a.out
0
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC) 
$

[Bug c/110701] New: Wrong code at -O1/2/3/s on x86_64-linux-gnu

2023-07-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110701

Bug ID: 110701
   Summary: Wrong code at -O1/2/3/s on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a recent regression. gcc at -O1 and above produce the wrong
code.

Compiler explorer: https://godbolt.org/z/6Wczv9dK6

$ cat a.c
int printf(const char *, ...);
int a;
long b;
int *c = 
short(d)(short e, short f) { return e * f; }
int main() {
  *c = d(340, b >= 0) ^ 3;
  printf("%d\n", a);
}
$
$ gcc-tk -O0 a.c && ./a.out
343
$ gcc-tk -O1 a.c && ./a.out
-65193
$ gcc-tk -O2 a.c && ./a.out
-65193
$ gcc-tk -O3 a.c && ./a.out
-65193
$ gcc-tk -Os a.c && ./a.out
-65193
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC)
$

[Bug c/110641] New: ICE in adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023

2023-07-12 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110641

Bug ID: 110641
   Summary: ICE in adjust_loop_info_after_peeling, at
tree-ssa-loop-ivcanon.cc:1023
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a recent regression.

Compiler explorer: https://godbolt.org/z/55EzjdoTK

$ cat a.c
int a, b, c, d, e, g;
int *f;
short **h;
int i() {}
int j() { return a && a <= 'F' || a >= 'a' && a <= 'f'; }
int k() {
  d = 0;
  for (; d < 2; d = i())
e = b = 0;
  for (; e - 71 + b; b++)
;
  for (;; c--) {
g = 0;
for (; j() + c + g >= 0; g--)
  **h = (char)b + b || f;
  }
}
int main() {}
$
$ gcc-tk -O3 a.c
during GIMPLE pass: ch_vect
crash_0_reduced.c: In function ‘k’:
crash_0_reduced.c:6:5: internal compiler error: in
adjust_loop_info_after_peeling, at tree-ssa-loop-ivcanon.cc:1023
6 | int k() {
  | ^
0x7f7b0bec4082 __libc_start_main
../csu/libc-start.c:308
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC)
$

[Bug c/110640] New: Wrong code at -O2/3 on x86_64-linux-gnu since GCC-13

2023-07-12 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110640

Bug ID: 110640
   Summary: Wrong code at -O2/3 on x86_64-linux-gnu since GCC-13
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This looks like a regression since GCC-13. gcc produces wrong code at -O2/3.

Compiler explorer: https://godbolt.org/z/5MWe6eK8M

$ cat a.c
unsigned short a = 65535;
int b, f, g;
int *c = 
long d;
short e;
static int *h(int);
void i() { h(a); }
int *h(int j) {
  unsigned char k;
  for (; e != 8; e = e + 4)
k = 0;
  for (; (unsigned char)(j-181249535) + k <= 1; k++) {
*c = d;
for (; f; f++)
  ;
  }
  return 
}
int main() { i(); }
$
$ gcc-tk -O0 a.c && ./a.out
$
$ gcc-tk -O2 a.c
$ ./a.out
Killed
$ gcc-tk -O3 a.c
$ ./a.out
Killed
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-322d17ae51ea0137167424e0018d7fa355948f9f
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230711 (experimental) (GCC)
$

[Bug c/110582] New: Wrong code at -O2/3 on x86_64-linux-gnu

2023-07-07 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110582

Bug ID: 110582
   Summary: Wrong code at -O2/3 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression. gcc at -O2 and -O3 produce wrong code.

Compiler explorer: https://godbolt.org/z/qWxPW34ch

$ cat a.c
int a, b;
int main() {
  char c = a = 0;
  for (; c != -3; c++) {
int d = 2;
d ^= 2 && a;
b = a == 0 ? d : d / a;
a = b;
  }
  for (; (1 + 95 << 24) + b + 1 + 686658714L + b - 2297271457;)
;
}
$
$ gcc-tk -O0 a.c && ./a.out
$
$ gcc-tk -O2 a.c
$ 
$ ./a.out
Killed
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-55900189ab517906efe08f8d17f3e4a310ee7fff/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-55900189ab517906efe08f8d17f3e4a310ee7fff
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230707 (experimental) (GCC)
$

[Bug c/110376] Wrong code at -O1 on x86_64-linux-gnu

2023-07-04 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110376

--- Comment #3 from Shaohua Li  ---
You post a commit for fixing this bug. Does this mean this report is not a DUP
of 110228?

[Bug c/110491] New: Wrong code at -O2 on x86_64-linux-gnu (a recent regression)

2023-06-29 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110491

Bug ID: 110491
   Summary: Wrong code at -O2 on x86_64-linux-gnu (a recent
regression)
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O2 produced wrong code.

Compiler explorer: https://godbolt.org/z/cbM1q13G7

$ cat a.c
int printf(const char *, ...);
int a, c, d, e;
short b;
void f(int *g) { c &= *g; }
void h(void);
void i() {
  a = 1;
  h();
  f();
}
void h() {
  int *j = 
  *j = 5;
k:
  for (; 4 + b <= 0;)
;
  for (; d;) {
c = e == 0;
goto k;
  }
}
int main() {
  i();
  printf("%d\n", c);
}
$
$ gcc-tk -O0 a.c &&./a.out
1
$ gcc-tk -O2 a.c && ./a.out
-2003318871
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-5f590ee3174cf6058ac882c3a84a96ae639349c8/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-5f590ee3174cf6058ac882c3a84a96ae639349c8
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230629 (experimental) (GCC)
$

[Bug c/110376] New: Wrong code at -O1 on x86_64-linux-gnu

2023-06-23 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110376

Bug ID: 110376
   Summary: Wrong code at -O1 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression bug. gcc at -O1 produces wrong code.

Compiler explorer: https://godbolt.org/z/EnMfs9oxe

$ cat a.c
int f, g, a, c;
char k = 204;
char *l = 
short m, n;
static long b;
unsigned *h = 
unsigned **i = 
int p(char *aa) {
  aa[0] && aa[1] && aa[2];
  return 1;
}
int q(char c) {
  char d[] = {c};
  int e = p(d);
  return e;
}
int r(int j, int h) {
  f = h / 4;
  g = f * 6;
  return g;
}
short s() { return **i; }
void t() {
  for (; r(9, *l) <= 1;) {
int j;
long *o = 
*o = 0 >= 0;
for (; q(0) + a > 1; a++)
  *o = 0 > m;
j = s();
for (; a;)
  n = j;
for (; (char)(1 + k + b) + k; --k)
  ;
  }
}
int main() { t(); }
$
$ gcc-tk -O0 a.c &&./a.out
$
$ gcc-tk -O1 a.c &&./a.out
Killed - processing time exceeded
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-577223aebc7acdd31e62b33c1682fe54a622ae27/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-577223aebc7acdd31e62b33c1682fe54a622ae27
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230621 (experimental) (GCC)
$

[Bug c/110337] New: Wrong code at -O2/s on x86_64-linux-gnu

2023-06-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110337

Bug ID: 110337
   Summary: Wrong code at -O2/s on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression on GCC -O2/s

$ cat a.c
int printf(const char *, ...);
int a, e;
static short b = 3, f;
long c;
char d;
short g() {
  e = a;
  for (; a != 4;)
return 39570 + d + b;
  return 0;
}
int main() {
  int h;
  f = g();
  int i = f;
  h = i < 0 ? i : i >> 14;
  c = b && h;
  printf("%d\n", (int)c);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O2 a.c && ./a.out
-1
$

[Bug c/110298] New: ICE at -Os on x86_64-linux-gnu

2023-06-17 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110298

Bug ID: 110298
   Summary: ICE at -Os on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

ICE at -Os.

$ cat a.c
int a, b, c, d, e;
int f() {
  c = 0;
  for (; c >= 0; c--) {
d = 0;
for (; d <= 0; d++) {
  e = 0;
  for (; d + c + e >= 0; e--)
;
  a = 1;
  b = 0;
  for (; a; ++b)
a *= 2;
  for (; b + d >= 0;)
return 0;
}
  }
}
int main() {}
$
$ gcc-tk -Os a.c
during GIMPLE pass: cunroll
a.c: In function ‘f’:
a.c:2:5: internal compiler error: tree check: expected class ‘type’, have
‘exceptional’ (error_mark) in tree_nop_conversion_p, at tree.cc:11961
2 | int f() {
  | ^
0x20cb70e internal_error(char const*, ...)
???:0
0x87f9b6 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
???:0
0x16e265d generic_simplify_386(unsigned int, tree_node*, tree_node*,
tree_node*, tree_node**, tree_code)
???:0
0x16b8bc8 generic_simplify_GE_EXPR(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
???:0
0xca5f45 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
???:0
0xcc0dc4 fold(tree_node*)
???:0
0x1209be8 simplify_replace_tree(tree_node*, tree_node*, tree_node*, tree_node*
(*)(tree_node*, void*), void*, bool)
???:0
0x120abcb substitute_in_loop_info(loop*, tree_node*, tree_node*)
???:0
0x10c6dc5 replace_uses_by(tree_node*, tree_node*)
???:0
0xb485d3 merge_blocks(basic_block_def*, basic_block_def*)
???:0
0x10d9784 cleanup_tree_cfg(unsigned int)
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230616 (experimental) (GCC)
$

[Bug c/110286] New: Wrong code at -O2 on x86_64-linux-gnu (nondeterministic output)

2023-06-16 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110286

Bug ID: 110286
   Summary: Wrong code at -O2 on x86_64-linux-gnu
(nondeterministic output)
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc trunk at -O2 emits wrong code. If you run the
compiled code multiple times, you will observe different outputs.

$ cat a.c
int printf(const char *, ...);
char a;
int b;
short c;
short(d)(short e) { return e + c; }
int f;
char g;
char g_0;
int h;
void i() {
  for (; h; f++)
switch (g_0)
case '"':
case '\\':
  ++g;
}
short j;
static int aa;
int k;
const int *l;
const int **m = 
short n;
signed o;
int p = 84134051;
unsigned r = 1;
int ag;
static char ah() {
  int ai = 0;
  if (r)
  aj : {
i();
short *ak = 
ag = 78003764;
*m = 
*ak = 1;
for (; *l + p - 162153904 + k; k++)
  for (; p - 168260671 > 3; ai++) {
*ak = o && 5;
if (a) {
  int *al = 
  short *am = 
  *al &= b;
  *am = 0;
}
  }
if (d((*ak)--))
  ;
else if (*l)
  goto aj;
  }
return 0;
}
int main() {
  ah();
  printf("%d\n", n);
}
$
$ gcc-tk -O0 a.c && ./a.out
0
$ gcc-tk -O2 a.c
$ ./a.out
518
$ ./a.out
514
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230616 (experimental) (GCC) 
$

[Bug c/110252] New: Wrong code at -O2/3/s on x86_64-linux-gnu

2023-06-14 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110252

Bug ID: 110252
   Summary: Wrong code at -O2/3/s on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a recent regression. 

Compiler explorer: https://godbolt.org/z/TW97cdYxv

$ cat a.c
int printf(const char *, ...);
int d, f;
const char a = 239;
short e, b, h = 2;
long g;
short *c = 
int *i = 
int(j)(int k, int l) { return k < 0 ? k : k >> l; }
int main() {
  for (;;) {
g = (char)d + a;
b = h && j(g, 6);
*c = b;
*i = e;
break;
  }
  printf("%d\n", f);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O1 a.c && ./a.out
1
$ gcc-tk -O2 a.c && ./a.out
-1
$ gcc-tk -O3 a.c && ./a.out
-1
$ gcc-tk -Os a.c && ./a.out
-1
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230612 (experimental) (GCC) 
$

[Bug c/110251] New: Hang at -O3 on x86_64-linux-gnu

2023-06-14 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110251

Bug ID: 110251
   Summary: Hang at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

Since GCC-13, gcc -O3 would hang on the following testcase.

Compiler Explorer: https://godbolt.org/z/z6zTv889c

$ cat a.c
int a, b;
char c;
int d(int e) {
  if (e >= 'a')
return e;
}
int f(unsigned short e) {
  for (; e; a++)
e &= e - 1;
}
void g() {
  for (; c < 1;)
;
  for (; f(c - 1); b = d(c))
;
}
$
$ gcc-tk -O3 a.c 
Killed - processing time exceeded
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230612 (experimental) (GCC) 
$

[Bug c/110243] New: Wrong code at -O3 on x86_64-linux-gnu

2023-06-13 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110243

Bug ID: 110243
   Summary: Wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

Since GCC-13, gcc at -O3 produces wrong code.

Compiler explorer: https://godbolt.org/z/jnroxhddY

$ cat a.c
#define X 11
char a;
long b = X;
int c[9][1];
unsigned d;
static long *e = , *f = 
int g() {
  if (a && a <= '9')
return '0';
  if (a)
return 10;
  return -1;
}
int main() {
  d = 0;
  for (; (int)*f -(X-1) + d < 9; d++)
c[g() + (int)*f + ((int)*e - X) -(X-1) + d]
 [0] = 0;
}
$
$ gcc-tk -O3 a.c &&./a.out
Segmentation fault
$
$ gcc-tk -O0 a.c &&./a.out
$
$ gcc-tk -fsanitize=address,undefined a.c &&./a.out
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-bf470895905e9152424076d1630a9d2c60de023b
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230612 (experimental) (GCC)
$

[Bug c/110233] New: Wrong code at -Os on x86_64-linux-gnu

2023-06-13 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110233

Bug ID: 110233
   Summary: Wrong code at -Os on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

This seems to be a regression since GCC-12.

Compiler explorer: https://godbolt.org/z/8ab6hz9e1

$ cat a.c
int a, b = 1691021644, c = 1790785003;
short d;
short e() {
  for (; c + 18446744073709551608UL + b - 1691021644 + 18446744073709551608UL -
 1790784987 <=
 2;) {
int *f[2];
int g = 0;
for (; b + (b - 1691021644) - 1691021636 + g < 2; g++)
  f[g] = 
int **h = [1];
d = b;
if (d)
  ;
else
  **h = 0;
return b;
  }
  return 1;
}
int main() { e(); }
$
$ gcc-tk -Os a.c && ./a.out
Segmentation fault
$ gcc-tk -O0 a.c && ./a.out
$
$ gcc-tk -O0 -fsanitize=address,undefined a.c && ./a.out
$

[Bug c/110141] New: Wrong code at -O2 on x86_64-linux-gnu

2023-06-06 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110141

Bug ID: 110141
   Summary: Wrong code at -O2 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc since 12 emits the wrong code at -O2.

Compiler explorer: https://godbolt.org/z/reGo6jqGK

$ cat a.c
int printf(const char *, ...);
int h, i = 1, m;
int *j = , *k = , *l;
short n(short b, short c, int d) {
  short e[] = {71, c, c, 40, 28, 57, 3, 8, 79, 19, c};
  int f = d, a = b;
  short *g = e;
  while (f > 1) {
a += *g++;
f -= 2;
  }
  a += *g -= 255;
  return a;
}
int fn2() {
  h = 0;
  for (;; h = 5) {
int o[4];
m = 0;
for (; m < 4; m++)
  o[n(6, 7, 19) - 70 + m] = 6;
if (h) {
  for (;;) {
int p = 0;
if (*k)
  break;
l = 
  }
  *j = o[0];
  return 0;
}
  }
}
int main() {
  fn2();
  printf("%d\n", i);
}
$
$ gcc-tk -O0 a.c && ./a.out
6
$ gcc-tk -O2 a.c && ./a.out
0
$

[Bug c/110115] New: Wrong code at -O1 on x86_64-linux-gnu

2023-06-04 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110115

Bug ID: 110115
   Summary: Wrong code at -O1 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc at -O1 emits the wrong code. This seems to be a long latent bug.

Compiler explorer: https://godbolt.org/z/3h4TYEYjW

$ cat a.c
int a;
char b;
static int c(char *e, int f) {
  int d = 0;
  for (; d < f; d++)
e[d] = 0;
  return d;
}
int g(char e, int f) {
  char h[20];
  int i = c(h, f);
  return i;
}
int j() {
  switch (a) {
  case 'f':
return 0;
  default:
return ~0;
  }
}
int main() {
  {
char *k[3];
int d = 0;
for (; g(8, 15) - 15 + d < 1; d++)
  k[j()+1] = 
*k[0] = -*k[0];
  }
}
$
$ gcc-tk -O0 a.c && ./a.out
$
$ gcc-tk -O1 a.c && ./a.out
Segmentation fault
$
$ gcc-tk -fsanitize=address,undefined a.c && ./a.out
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8d5f050dabbf6dd3b992c3b46661848dbcf30d9e/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8d5f050dabbf6dd3b992c3b46661848dbcf30d9e
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230523 (experimental) (GCC)
$

[Bug c/109967] New: Wrong code at -O2 on x86_64-linux-gnu

2023-05-25 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109967

Bug ID: 109967
   Summary: Wrong code at -O2 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc trunk at -O2 emits the wrong code. This seems to be
a long latent bug since GCC-7 (I tried gcc-7.4 on compiler explorer, which
still emits the wrong result.)

Compiler explorer: https://godbolt.org/z/YGeWedWq7

$ cat a.c
int printf(const char *, ...);
int a, c;
int main() {
  long f[2];
  int e = 0;
  for (; e < 2; e++) {
{
  char g[20];
  char *b = g;
  int d = 48, e = 0;
  while (d && e < 5)
b[e++] = d /= 10;
  c = e;
}
f[c - 2 + e] = 1;
  }
  a = f[0];
  printf("%d\n", a);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O2 a.c && ./a.out
4
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8d5f050dabbf6dd3b992c3b46661848dbcf30d9e/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-8d5f050dabbf6dd3b992c3b46661848dbcf30d9e
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230523 (experimental) (GCC) 
$

[Bug c/109934] New: Wrong code at -O3 on x86_64-linux-gnu

2023-05-22 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109934

Bug ID: 109934
   Summary: Wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc trunk at -O3 emits wrong code.

Compiler explorer: https://godbolt.org/z/3E8xf69rP

$ cat a.c
int printf(const char *, ...);
short a;
long b = 3, c;
int d(int e) {
  switch (e)
  case 111:
  case 222:
  case 44:
return 0;
  return e;
}
int main() {
  for (; a >= 0; --a)
if (d(c + 23) - 23)
  b = 0;
  printf("%d\n", (int)b);
}
$
$ gcc-tk -O0 a.c && ./a.out
3
$ gcc-tk -O3 a.c && ./a.out
0
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-c09471fbc7588db2480f036aa56a2403d3c03ae5/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-c09471fbc7588db2480f036aa56a2403d3c03ae5
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230521 (experimental) (GCC)
$

[Bug c/109925] New: Wrong code at -O2 on x86_64-linux-gnu since GCC-12

2023-05-21 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109925

Bug ID: 109925
   Summary: Wrong code at -O2 on x86_64-linux-gnu since GCC-12
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc trunk emits wrong code at -O2.

Compiler explorer: https://godbolt.org/z/hcnaxoPaP

$ cat a.c
int printf(const char *, ...);
int a, c, f;
int main() {
  int g[2];
  c = 0;
  for (; c < 2; c++) {
{
  char h[20];
  char *b = h;
  int d = 48, e = 0;
  while (d && e < 5)
b[e++] = d /= 10;
  f = e;
}
g[f - 2 + c] = 0;
  }
  for (;;) {
for (; a <= 4; a++)
  if (g[0])
break;
break;
  }
  printf("%d\n", a);
}
$
$ gcc-tk -O0 a.c && ./a.out
5
$ gcc-tk -O2 a.c && ./a.out
0
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-f211757f6fa9515e3fd1a4f66f1a8b48e500c9de/bin/gcc
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-f211757f6fa9515e3fd1a4f66f1a8b48e500c9de/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-f211757f6fa9515e3fd1a4f66f1a8b48e500c9de
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230521 (experimental) (GCC)
$

[Bug c/109778] New: Wrong code at -O3 on x86_64-linux-gnu since GCC-12.2

2023-05-08 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109778

Bug ID: 109778
   Summary: Wrong code at -O3 on x86_64-linux-gnu since GCC-12.2
   Product: gcc
   Version: 14.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

gcc trunk at -O3 emits wrong code. This seems to be a bug since gcc-12.2

Compiler explorer: https://godbolt.org/z/E5aqnMK6Y


$ cat a.c
int printf(const char *, ...);
int a, b, c, d;
int *e = 
unsigned f(unsigned char g) {
  g = 1 | g << 1;
  g = g >> 4 | g << 4;
  return g;
}
void h(unsigned g) { *e = 8 > f(g + 86) - 86; }
int main() {
  d = a && b;
  h(d + 4);
  printf("%d\n", c);
}
$
$ gcc-tk -O0 a.c && ./a.out
1
$ gcc-tk -O3 a.c && ./a.out
0
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-b7fe38c14e5f1bc32950c7b2ffc8537c7c381af4/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-b7fe38c14e5f1bc32950c7b2ffc8537c7c381af4
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230506 (experimental) (GCC)
$

[Bug sanitizer/108497] UBsan at -O1 failed to report an integer-overflow

2023-04-03 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108497

--- Comment #4 from Li Shaohua  ---
(In reply to Jakub Jelinek from comment #3)
> Not now nor in the near future.  After all, it isn't a regression, so
> couldn't be fixed during stage4 anyway.

This bug affects GCC>=8. GCC<=7 work fine on this case.

  1   2   >