[Bug sanitizer/108995] New: Missed signed integer overflow checks in UBsan?

2023-03-02 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108995

Bug ID: 108995
   Summary: Missed signed integer overflow checks in UBsan?
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

$ cat abc.c
int printf(const char *, ...);
int a;
const int b = 44514;
int *c = &a;
void main(void) {
  *c = 65526 * b / 6;
  printf("%d\n", a);
}

Ubsan did not emit any message. However, the outputs are different.

$ gcc-trunk -O3 -fsanitize=undefined abc.c ; ./a.out
-229690488

$ gcc-trunk  -fsanitize=undefined abc.c ; ./a.out
486137394

[Bug sanitizer/108880] New: slow compilation with "-fsanitize=undefined"

2023-02-21 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108880

Bug ID: 108880
   Summary: slow compilation with "-fsanitize=undefined"
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

gcc-10 works fine.

$ time gcc-10 -fsanitize=undefined  abc.c

real0m0.081s


$ time gcc-11 -fsanitize=undefined  abc.c

real0m7.045s

$ time gcc-trunk -fsanitize=undefined  abc.c

real0m10.346s

$ gcc-trunk -v
gcc version 13.0.1 20230218 (experimental) [master r13-6132-g32b5875c911] (GCC)


$ cat abc.c
long a;
short b, e;
char c;
int d, f, g;
void h() {
  int i;
  f &= i ^= (((g &= 0 / d / d % 8 << 0 << 2) % a >> e) / c >> b) / 1 % 8 << 3;
}
void main() {}

[Bug sanitizer/108845] Unnecessary signed integer overflow checks

2023-02-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108845

--- Comment #4 from Qirun Zhang  ---
(In reply to Qirun Zhang from comment #3)
> (In reply to Jakub Jelinek from comment #2)
> > I'm not convinced it is a good idea.
> > Sure, in the above case it is obvious it will never trigger, but if we say
> > use ranger to decide if the operation can or can't overflow, then VRP is in
> > many cases based on assumptions which only hold for valid code, but
> > sanitizers actually want to diagnose invalid code.
> 
> 
> Thanks!
> 
> Here is another (similar) example.  Earlier versions of GCC will not inject
> UBSAN_CHECK_ADD. However, the latest version of GCC will.
> 
> the code example:
> ==
> void main() {
>   int a = 0;
>   for (; a != 2; a++)
> ;
> }
> ==
> 
> Compile with "gcc-11 -fsanitize=signed-integer-overflow -O3 
> -fdump-tree-optimized", we got no UBSAN checks:
> 
> ==
> void main ()
> {
>   int a;
> 
>[local count: 118111600]:
> 
>[local count: 955630225]:
>   # a_6 = PHI <1(3), 0(2)>
>   a_3 = a_6 + 1;
>   if (a_3 != 2)
> goto ; [87.64%]
>   else
> goto ; [12.36%]
> 
>[local count: 118111600]:
>   return;
> 
> }
> ==
> 
> Compile with "gcc-trunk -fsanitize=signed-integer-overflow -O3 
> -fdump-tree-optimized", we got one:
> 
> ==
> void main ()
> {
>   int a;
> 
>[local count: 118111600]:
> 
>[local count: 955630225]:
>   # a_5 = PHI 
>   a_3 = .UBSAN_CHECK_ADD (a_5, 1);
>   if (a_3 != 2)
> goto ; [89.00%]
>   else
> goto ; [11.00%]
> 
>[local count: 118111600]:
>   return;
> 
> }
> ==
> 
> $ gcc-trunk -v
> gcc version 13.0.1 20230218 (experimental) [master r13-6132-g32b5875c911]
> (GCC)

I did a bisect. For the testcase provided in comment #3, the behavior was
introduced in the following commit:


commit 502ffb1f389011b28ee51815242c7397790802d5
Author: Andrew MacLeod 
Date:   Tue Nov 2 21:26:44 2021 -0400

Switch vrp2 to ranger.

This patch flips the default for the VRP2 pass to execute ranger vrp rather
than the assert_expr version of VRP.

* params.opt (param_vrp2_mode): Make ranger the default for VRP2.

[Bug sanitizer/108845] Unnecessary signed integer overflow checks

2023-02-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108845

--- Comment #3 from Qirun Zhang  ---
(In reply to Jakub Jelinek from comment #2)
> I'm not convinced it is a good idea.
> Sure, in the above case it is obvious it will never trigger, but if we say
> use ranger to decide if the operation can or can't overflow, then VRP is in
> many cases based on assumptions which only hold for valid code, but
> sanitizers actually want to diagnose invalid code.


Thanks!

Here is another (similar) example.  Earlier versions of GCC will not inject
UBSAN_CHECK_ADD. However, the latest version of GCC will.

the code example:
==
void main() {
  int a = 0;
  for (; a != 2; a++)
;
}
==

Compile with "gcc-11 -fsanitize=signed-integer-overflow -O3 
-fdump-tree-optimized", we got no UBSAN checks:

==
void main ()
{
  int a;

   [local count: 118111600]:

   [local count: 955630225]:
  # a_6 = PHI <1(3), 0(2)>
  a_3 = a_6 + 1;
  if (a_3 != 2)
goto ; [87.64%]
  else
goto ; [12.36%]

   [local count: 118111600]:
  return;

}
==

Compile with "gcc-trunk -fsanitize=signed-integer-overflow -O3 
-fdump-tree-optimized", we got one:

==
void main ()
{
  int a;

   [local count: 118111600]:

   [local count: 955630225]:
  # a_5 = PHI 
  a_3 = .UBSAN_CHECK_ADD (a_5, 1);
  if (a_3 != 2)
goto ; [89.00%]
  else
goto ; [11.00%]

   [local count: 118111600]:
  return;

}
==

$ gcc-trunk -v
gcc version 13.0.1 20230218 (experimental) [master r13-6132-g32b5875c911] (GCC)

[Bug sanitizer/108845] New: Unnecessary signed integer overflow checks

2023-02-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108845

Bug ID: 108845
   Summary: Unnecessary signed integer overflow checks
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

When compiled with "gcc -fsanitize=signed-integer-overflow -O3" (reproducible
on the latest trunk version), Gcc will produce ".UBSAN_CHECK_SUB" checks for
the following code.

===
void printf();
void main() {
  int a;
  for (a = 0; a != -3; a--)
printf("%d\n", a);
}



I noticed that clang could indeed optimize this program to three printf() calls
with "-fsanitize=signed-integer-overflow -O3". Therefore, no overflow checks
are needed.

Is this behavior in GCC expected? Thanks!

[Bug tree-optimization/102149] wrong code at -O3 on x86_64-linux-gnu

2021-08-31 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102149

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:89f33f44addbf9853bc3e6677d

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

2021-08-31 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102149

Bug ID: 102149
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

Seems to be a recent regression.


$ gcc-trunk -v
gcc version 12.0.0 20210831 (experimental) [master revision
5e57bacf6f3:a82c79a304b:de7a795c321e76826d123c92b99e73e144666b60] (GCC)


$ gcc-trunk abc.c ; ./a.out
1

$ gcc-trunk abc.c ; ./a.out
0

$ cat abc.c
int a[8];
int *b = &a[6];
char c;
int main() {
  int d = 7;
  for (; d >= 0; d--) {
*b = 1;
c = a[d] >> 3;
a[d] = c;
  }
  printf("%d\n", a[6]);
}

[Bug tree-optimization/101972] wrong code at -O2 on x86_64-linux-gnu

2021-08-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101972

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:a81e2c6240655f60a49c16e0d8bbfd2ba40bba51

[Bug tree-optimization/101972] New: wrong code at -O2 on x86_64-linux-gnu

2021-08-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101972

Bug ID: 101972
   Summary: wrong code at -O2 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in gcc-9. gcc-8 works fine.


$ gcc-trunk -O2 abc.c ; ./a.out
0

$ gcc-trunk abc.c ; ./a.out
30

$ gcc-8 -O2 abc.c ; ./a.out
30

$ cat abc.c
int a, b, c, d, f;
static short e = 63891;
char g = 30;
unsigned h(i, j) { return i << j; }
int *l(int *);
void m() {
  a = 0;
  for (; a >= 0; a--) {
int *k = &b;
*k = e < 0;
  }
  c = b;
  l(&c);
}
int *l(int *i) {
  d = 2;
  for (; d <= 6; d++) {
if (h(d, *i) <= d)
  ;
else
  continue;
g = 0;
return &f;
  }
}
int main() {
  m();
  printf("%d\n", g);
}

[Bug tree-optimization/101885] wrong code at -O3 on x86_64-linux-gnu

2021-08-12 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101885

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:529ea7d9596b26ba103578eeab448e9862a2d2c5

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

2021-08-12 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101885

Bug ID: 101885
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears a regression in gcc-10. gcc-9 works fine.


$ gcc-trunk -v
gcc version 12.0.0 20210812 (experimental) [master revision
01f8a8b48e5:0eb7800d242:04b4f3152593f85b05974528d1607619dd77d702] (GCC)


$ gcc-trunk abc.c ; ./a.out
0

$ gcc-trunk -O3 abc.c ; ./a.out
3


$ cat abc.c
int a = 3, c;
short b = 5, d, f;
volatile short e;
int main() {
  f = 29;
  for (; f != 33; f++) {
int g = a;
if (b)
  if (a) {
a = b = 0;
for (; b <= 8; b++)
  ;
  }
e;
e;
c = 0;
for (; c != 14; ++c)
  e;
  }
  b = d;
  printf("", 8);
  printf("%d\n", a);
}

[Bug tree-optimization/101615] wrong code at -O3 on x86_64-linux-gnu

2021-07-24 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101615

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:6df6055d5c666e669890ff8

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

2021-07-24 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101615

Bug ID: 101615
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression.

$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210724 (experimental) [master revision
e314cfc371d:5eb84b79079:ead235f60139edc6eb408d8d083cbb15e417b447] (GCC)

$ gcc-trunk abc.c ; ./a.out
5
7
11
3
3
3



$ gcc-trunk -O3 abc.c ; ./a.out
5
7
3
3
3
11

$ cat abc.c
int a[50] = {5, 5, 8};
short b;
int c, d;
int main() {
  int e;
  for (; b <= 4; b++)
for (; c <= 4; c++) {
  *a |= 1;
  e = 0;
  for (; e <= 4; e++)
a[e + 1] |= 3;
}
  for (; d < 6; d++)
printf("%d\n", a[d]);
}

[Bug tree-optimization/101501] wrong code at -O3 on x86_64-linux-gnu

2021-07-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101501

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:287522613d661b4c5ba8403b051eb470c1674cba

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

2021-07-18 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101501

Bug ID: 101501
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression. Gcc-10 works fine.

$ gcc-trunk -v
gcc version 12.0.0 20210718 (experimental) [master revision
0103d18dfc9:a1cef02c5e3:853921378bfa149353b4e1c7dde5c02f80072ad7] (GCC)


$ gcc-trunk abc.c ; ./a.out
-1

$ gcc-trunk -O3 abc.c ; ./a.out
40


$ cat abc.c
char a = 55;
int main() {
  int b;
  char c;
d:
  c = a-- * 52;
  b = 3L * c;
  if (b)
goto d;
  printf("%d\n", a);
}

[Bug tree-optimization/101445] wrong code at -O3 on x86_64-linux-gnu

2021-07-13 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101445

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:f75211822f8d84bb706421d3692e

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

2021-07-13 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101445

Bug ID: 101445
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression. Note that -O2 works fine.

$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210713 (experimental) [master revision
7670b6633e5:d2f95d2ac56:1583b8bff0be7e41aa721dde79f90ca0763bd4e2] (GCC)


$ gcc-trunk abc.c ; ./a.out
0
0
0
0
0
0
0



$ gcc-trunk -O3 abc.c ; ./a.out
0
0
3
0
0
0
0



$ cat abc.c
int a[35] = {1, 1, 3};
char b = 4;
int c, d;
int main() {
  char e;
  for (; b >= 0; b--) {
e = 3;
for (; e >= 0; e--)
  a[b * 5 + e] = a[b * 5 + e + 1];
  }
  for (; c < 5; c++)
;
  for (; d < 7; d++)
printf("%d\n", a[c * d]);
}

[Bug tree-optimization/101173] wrong code at -O3 on x86_64-linux-gnu

2021-06-22 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101173

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:fbdec14e80e9399cd301ed3

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

2021-06-22 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101173

Bug ID: 101173
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-8 to the trunk. Gcc-7.5.0 works.

$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210622 (experimental) [master revision
f0e40ea0640:393ac5ed7d8:7822285515cd4dab86f722a9f4969b6952904a37] (GCC)



$ gcc-trunk abc.c ; ./a.out > 1.txt
$ gcc-trunk -O3 abc.c ; ./a.out > 2.txt

$ diff 1.txt 2.txt
11c11
< 0
---
> 8

$ cat abc.c
int a[6][9];
char b, c;
short d;
int e, f;
int main() {
  a[1][3] = 8;
  b = 1;
  for (; b <= 5; b++) {
d = 0;
for (; d <= 5; d++) {
  c = 0;
  for (; c <= 5; c++)
a[b][c] = a[b][c + 2] & 216;
}
  }
  for (; e < 6; e++) {
f = 0;
for (; f < 9; f++)
  printf("%d\n", a[e][f]);
  }
}

[Bug tree-optimization/101105] wrong code at -O3 on x86_64-linux-gnu

2021-06-16 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101105

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:f75211822f8d84bb706421

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

2021-06-16 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101105

Bug ID: 101105
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in 11.

$ gcc-trunk -v
Configured with: ../gcc/configure --prefix=/nethome/qzhang414/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210616 (experimental) [master revision
041f7417707:a530c589490:3155d51bfd1de8b6c4645dcb2292248a8d7cc3c9] (GCC)



$ gcc-trunk abc.c ; ./a.out
2

$ gcc-trunk -O3 abc.c ; ./a.out
Segmentation fault


$ cat abc.c
short a;
int b[5][4] = {2, 2};
long *c;
int d;
short(e)(f) { return f == 0 || a && f == 1 ? 0 : a; }
int main() {
  int g, h;
  g = 3;
  for (; g >= 0; g--) {
h = 3;
for (; h >= 0; h--)
  b[g][h] = b[0][1] && e(1);
  }
  d = b[0][1];
  if (d)
*c = 4073709551611;
  printf("%d\n", 2);
}

[Bug tree-optimization/101025] [11 Regression] wrong code at -O3 on x86_64-linux-gnu

2021-06-11 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101025

--- Comment #8 from Qirun Zhang  ---
(In reply to Richard Biener from comment #7)
> Fixed on trunk sofar.  Keep more testcases coming ;)  (I have a hunch this
> code has more issues...)

Thanks, Richard. Will do.

[Bug tree-optimization/101031] wrong code at -O2 on x86_64-linux-gnu

2021-06-11 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101031

Qirun Zhang  changed:

   What|Removed |Added

 CC||rguenther at suse dot de

--- Comment #1 from Qirun Zhang  ---
My bisection points to g:d1d01a66012a93cc8cb7dafbe1b5ec453e

[Bug tree-optimization/101031] New: wrong code at -O2 on x86_64-linux-gnu

2021-06-11 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101031

Bug ID: 101031
   Summary: wrong code at -O2 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression.


$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210611 (experimental) [master revision
336c41dbcb2:00da4bcb67d:36943c6bdd3d3b535b24872bbd802d91ef0c6299] (GCC)


$ gcc-trunk abc.c ; ./a.out
0

$ gcc-trunk -O2 abc.c ; ./a.out
1


$ cat abc.c
int a;
char b, e;
static char *c = &b;
static long d;
void f(void);
void h() {
  int g = 0;
  for (; g < 2; ++g) {
d = *c;
*c = 1;
b = 0;
  }
  f();
}
void f() {
  if (d++)
c = &e;
  for (; a;)
;
}
int main() {
  h();
  printf("%d\n", b);
}

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

2021-06-10 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101025

Bug ID: 101025
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression.

Bisection points to g:128f43cf679e51564202b41f23fae4146347f93d



$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210610 (experimental) [master revision
5ad76ad7f5b:c64ab1c4fe0:cce1697e6fe0134616ebc8f7040d99e66c12241a] (GCC)


$ gcc-trunk abc.c ; ./a.out
0

$ gcc-trunk -O3 abc.c ; ./a.out
4

$ cat abc.c
int a[10];
int b, d, g;
volatile char c;
short e;
volatile int f;
int main() {
  for (; d <= 9; d++) {
b = e = 0;
for (; e < 10; e++)
  a[e] = 4;
for (; b <= 9; b++)
  if (g)
f = 0;
  else
a[b] = c;
  }
  printf("%d\n", a[1]);
}

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

2021-06-09 Thread qrzhang at gatech dot edu via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101001

Bug ID: 101001
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-8 to the trunk. Gcc-7 works fine.



$ gcc-trunk -v
gcc version 12.0.0 20210609 (experimental) [master revision
174e75a2107:3b61ba37fe1:5bfcfe3087eb05b76395c9efbfc1abbf3f9e1a03] (GCC)


$ gcc-trunk abc.c ; ./a.out
0


$ gcc-trunk -O3 abc.c ; ./a.out
Segmentation fault


$ cat abc.c
int a;
volatile char b;
int main() {
  char c;
  int d, f = 5;
  short e;
  e = 0;
  for (; e != -15; e--) {
d = 0;
for (; d > -16; d = d - 4) {
  f || b;
  c = 0;
  for (; c != 2; c = c - 3)
f = 0;
}
  }
  printf("%X\n", a);
}

[Bug tree-optimization/95172] New: wrong code at -O1 on x86_64-linux-gnu

2020-05-16 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95172

Bug ID: 95172
   Summary: wrong code at -O1 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

Recent regression. Bisection points to g:b6ff3ddecfa93d53867afaaa078f85f


$ gcc-trunk -v
gcc version 11.0.0 20200516 (experimental) [master revision
53b4d52f114:91c1d944166:f5b461d453043c6b6dda50db0439e4c78b241f03] (GCC)

$ gcc-trunk -O1 abc.c ; ./a.out
1

$ gcc-trunk  abc.c ; ./a.out
0

$ cat abc.c
int a, d;
int *b = &a;
short c;
int main() {
  for (; c <= 4; c--) {
for (; d;)
  ;
a = 1;
*b = 0;
  }
  printf("%d\n", a);
}

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

2020-05-10 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95045

Bug ID: 95045
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

Recent regression. Bisection points to g:283cb9ea6293e813e4


$ gcc-trunk -v
gcc version 11.0.0 20200510 (experimental) [master revision
4ae915cdbf0:8eedda9eef3:ef6394205d7bcab00dca01182d708ad5a6360a7b] (GCC)


$ gcc-trunk abc.c ; ./a.out
4


$ gcc-trunk -O3  abc.c ; ./a.out
0


$ cat abc.c
int a, c, f;
long b;
char d;
int e[3];
int g[9][3][2];
int main() {
  {
  h:
for (f = 0; f <= 5; f++) {
  b = 3;
  for (; b >= 0; b--) {
e[2] = d = 0;
for (; d <= 3; d++) {
  g[8][2][0] = e[1] = c = 0;
  for (; c <= 1; c++)
e[c + 1] = g[d + 5][2][c] = 4;
}
if (a)
  goto h;
  }
}
  }
  printf("%d\n", e[2]);
}

[Bug tree-optimization/94724] New: wrong code at -O0 on x86_64-linux-gnu

2020-04-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94724

Bug ID: 94724
   Summary: wrong code at -O0 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It happens at -O0. gcc-9 works fine.
Bisection points to g:ca6c722561ce9b9dc7b59cfd9d2


The correct output is 1.


$ gcc-trunk -v
gcc version 10.0.1 20200422 (experimental) [master revision
38644f81bab:facc719c537:56b15072aa41633235be57851ab342114e0bacba] (GCC)


$ gcc-9 abc.c ; ./a.out
1

$ gcc-trunk abc.c ; ./a.out
0

$ cat abc.c
short a, b;
int main() {
  (0, (0, (a = 0 >= 0, b))) != 53601;
  printf("%d\n", a);
}

[Bug tree-optimization/94567] New: wrong code at -O2 and -O3 on x86_64-linux-gnu

2020-04-11 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94567

Bug ID: 94567
   Summary: wrong code at -O2 and -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It's a recent regression. Bisection points to g:529ea7d9596b26ba103578eeab


$ gcc-trunk -v
gcc version 10.0.1 20200411 (experimental) [master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566] (GCC)


$ gcc-trunk abc.c ; ./a.out
4

$ gcc-trunk -O2 abc.c ; ./a.out
0


$ cat abc.c
volatile int a = 1, b;
short c, d = 4, e = 53736, f = 2, g;
int(h)(int i, int j) { return i && j ? 0 : i + j; }
int main() {
  for (; a; a = 0) {
unsigned short k = e;
g = k >> 3;
if (h(g < (f || c), b))
  d = 0;
  }
  printf("%X\n", d);
}

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

2020-03-10 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94125

Bug ID: 94125
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in 9. Gcc-8.3 works fine.

Bisection points to g:8f70fdc31a7b0099e7322d0aba94830fb08f4c88

$ gcc-trunk -v
gcc version 10.0.1 20200310 (experimental) [master revision
cc5c935937d:88ecfc48953:3654d49d0ff651b2a78401bc2430428711e7d2eb] (GCC)


$ gcc-trunk abc.c ; ./a.out
0
0
0
0
0
0
0
0


$ gcc-trunk -O3 abc.c ; ./a.out
0
0
0
4
0
0
0
0


$ gcc-8 -O3 abc.c ; ./a.out
0
0
0
0
0
0
0
0


$ cat abc.c
int printf(const char *, ...);
int *a;
char b, f;
static char c;
short d[1][8][1];
int **e = &a;
short *g = &d[0][3][0];
unsigned char **h;
int i;
int main() {
  unsigned char *j = &b;
  int k[] = {0, 0, 0, 4, 0, 0};
  if (e) {
unsigned char **l = &j;
c = 2;
for (; c >= 0; c--) {
  **l = f;
  *g = k[c + 3];
  k[c + 1] = 0;
}
  } else {
unsigned char **m = &j;
for (;;)
  h = m;
  }
  for (; i < 8; i++)
printf("%d\n", d[0][i][0]);
}

[Bug debug/94018] New: gcc generates wrong debug information at -Og

2020-03-03 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94018

Bug ID: 94018
   Summary: gcc generates wrong debug information at -Og
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression. Gcc-9 works fine. It happens at -Og only.

Bisection points to g:ec8ac265ff21fb379ac072848561a91e4990c47f


$ gcc-trunk -v
gcc version 10.0.1 20200303 (experimental) [master revision
3d6fd7ce6dc:a5d64750934:b07e4e7c7520ca3e798f514dec0711eea2c027be] (GCC)


#expected output.

$ gcc-trunk -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40048f: file abc.c, line 5.

Breakpoint 1, main () at abc.c:5
5   b = (l = a) || 1; //optimize_me_not()
$1 = 2
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 25509) killed]


#wrong output
$ gcc-trunk -g -Og abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400484: file abc.c, line 5.

Breakpoint 1, main () at abc.c:5
5   b = (l = a) || 1; //optimize_me_not()
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 20078) killed]



$ cat abc.c
static int a, b, c;
int main() {
  int l = 2;
  for (; c < 2; c++)
b = (l = a) || 1; //optimize_me_not()
  a = 0;
}


$ cat cmds
b abc.c:5
r
p l
kill
q

[Bug debug/94005] New: gcc generates wrong debug information at -Og

2020-03-02 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94005

Bug ID: 94005
   Summary: gcc generates wrong debug information at -Og
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in gcc-9.

bisection points to g:36f6476b80ca559ff0fc436d2ab84130b


The value of l at line 11 is 153. At -Og it generates l=0. O3 and O2 works
fine.


$ gcc-trunk -v
gcc version 10.0.1 20200302 (experimental) [master revision
778a77357ca:87d8bb8fb8c:917e56a94f9d3189d7fa9d1944b7513258195887] (GCC)

#correct value:

$ gcc-trunk -g  abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004ec: file abc.c, line 11.

Breakpoint 1, i () at abc.c:11
11l = e; //   optimize_me_not()
$1 = 153
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 24999) killed]


#incorrect value:

$ gcc-trunk -g -Og abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400495: file abc.c, line 11.

Breakpoint 1, i () at abc.c:11
11l = e; //   optimize_me_not()
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 32681) killed]

$ cat abc.c
int a, b = -7L;
short d;
static int e;
char f;
char g() {}
int h(c) {}
void i() {
  int l;
  (a && g()) > (e && h(d = 5));
  f = l = b & 159;
  l = e; //   b here
}
int main() { i(); }


$ cat cmds
b abc.c:11
r
p l
kill
q

[Bug debug/93954] gcc generates wrong debug information at -O3

2020-02-26 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93954

--- Comment #2 from Qirun Zhang  ---
(In reply to Andrew Pinski from comment #1)
> >Bisection points to g:bd2b9f1e2d67ec8e88c977154ecfee
> 
> My bet is if you put a break point at "i--;" you would get the incorrect
> answer before that patch.
> Since the function just has one instruction at -O3, there is not an
> instruction to place both lines there.

Break at "i--;" (at line 3) does give the same incorrect result.

However, before that patch, gcc works fine. I tested
g:6d3aa24cd6535dcfc9f0701579eca53aa1917


It gives me:
$ bin/bin/gcc -g -O3 abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4003a0: file abc.c, line 3.

Breakpoint 1, main () at abc.c:4
4 ;// b here
$1 = 2580636199
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 19052) killed]

[Bug debug/93954] New: gcc generates wrong debug information at -O3

2020-02-26 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93954

Bug ID: 93954
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in gcc-8. The code is pretty self-explanatory.

Bisection points to g:bd2b9f1e2d67ec8e88c977154ecfee



$ gcc-trunk -v
gcc version 10.0.1 20200226 (experimental) [master revision
4d213bf6011:5d3c19b2ec6:ce25177f505ea75b3c0833c3f3f0072b97ee1b44] (GCC)


#It incorrectly prints i = 2580636200

$ gcc-trunk -g-O3 abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4003a0: file abc.c, line 4.

Breakpoint 1, main () at abc.c:4
4 ;// b here
$1 = 2580636200
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 17508) killed]


$ cat abc.c
int main() {
  unsigned i = 2580636200;
  i--;
  ;// b here
}


$ cat cmds
b abc.c:4
r
p i
kill
q

[Bug debug/93941] New: gcc generates wrong debug information at -O2

2020-02-25 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93941

Bug ID: 93941
   Summary: gcc generates wrong debug information at -O2
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a recent regression.
My bisect points to g:82e8e335f917b9ce40801838c  (needs double check).



$ gcc-trunk -v
gcc version 10.0.1 20200225 (experimental) [master revision
2473c81cb2d:31b6c240eeb:81c833b311b16cfd87a947374d5ffbbd48facd03] (GCC)


## correct output
$ gcc abc.c ; ./a.out
10


## wrong value (i=1) at -O2
$ gcc-trunk -g -O2 abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400451: file abc.c, line 15.

Breakpoint 1, main () at abc.c:15
15printf("%d\n", i);
$1 = 1
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 2788) killed]



$ cat abc.c
volatile int a;
char b[10][10][1];
int c;
int main() {
  int i, d;
  i = 0;
  for (; i < 10; i++) {
c = 0;
for (; c < 10; c++) {
  d = 0;
  for (; d < 1; d++)
a = b[i][c][d];
}
  }
  printf("%d\n", i);
}

$ cat cmds
b abc.c:15
r
p i
kill
q

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

2020-02-19 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93843

Bug ID: 93843
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

A recent regression. Gcc-9 works fine.

Bisection points to g:6271dd984d7f920d4fb17ad37af6a1f8e6b796dc

$ gcc-trunk -v
gcc version 10.0.1 20200219 (experimental) [master revision
665c5bad168:533e82edecf:51faf07cef9293af544bfacc7d0b320ab90d7d60] (GCC)


$ gcc-trunk -O3 abc.c ; ./a.out
4
0

$ gcc-9 -O3 abc.c ; ./a.out
4
4

$ gcc-trunk  abc.c ; ./a.out
4
4

$ cat abc.c
int printf(const char *, ...);
char a, e;
struct {
  short b;
  short c;
} d;
int f;
int main() {
  short *g = &d.c, *h = &d.b;
  e = 4 - a;
  *h = *g = e;
  for (; f < 2; f++)
printf("%d\n", d.c);
}

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

2020-02-18 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93820

Bug ID: 93820
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in 9.x. Gcc-8.3 works fine.

Bisection points to:  g:be43a8877e2f2f4590ba667b27a24a0cfdf8141d



$ gcc-trunk -v
gcc version 10.0.1 20200218 (experimental) [master revision
da67227bfc4:72b83cccb06:d4c10c9f4bff616e7ed07e92504fe31a700e2af1] (GCC)

$ gcc-trunk -O3 abc.c ; ./a.out
1
$ gcc-trunk abc.c ; ./a.out
0


$ cat abc.c
int printf(const char *, ...);
int a[10];
int b, d, h;
int *c = &b, *g;
short e;
int **f;
int ***i = &f;
void k() {
  e = 5;
  for (; e; e--) {
a[e + 4] = *c;
a[e + 2] = 0 != &d;
  }
  char j;
  b = 0;
  for (; b <= 5; b++) {
j = 0;
for (; j <= 5; j++)
  a[j + 3] = 0;
  }
  for (;;) {
*i = &g;
*f = &h;
if (**i)
  break;
int l = 9;
for (; l; l--)
  a[l] = 0;
  }
}
int main() {
  k();
  printf("%d\n", a[4]);
}

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

2020-02-16 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93767

Bug ID: 93767
   Summary: wrong code at -O3 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It appears to be a regression in 8.X. Gcc-7.4 works fine.

Bisection points to:  g:a57776a11369621f9e9e8a8a3db6cb406c8bf27b


$ gcc-trunk -v
gcc version 10.0.1 20200216 (experimental) [master revision
93b8cfce27a:6bc9d585053:9a3d019a74d8d49fb6e6d75a00bd79fdb936a2e1] (GCC)


$ gcc-trunk abc.c ; ./a.out
1


$ gcc-trunk -O3 abc.c ; ./a.out
0


$ gcc-8 -O3 abc.c ; ./a.out
0

$ cat abc.c
int printf(const char *, ...);
int a[10];
short b;
int main() {
  b = 6;
  for (; b >= 3; b--) {
a[b] = 0 <= 0;
a[b + 2] = a[3];
  }
  printf("%d\n", a[5]);
}

[Bug tree-optimization/93586] [10 Regression] wrong code at -O1 on x86_64-linux-gnu

2020-02-04 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93586

--- Comment #2 from Qirun Zhang  ---
(In reply to Andrew Pinski from comment #1)
> (In reply to Qirun Zhang from comment #0)
> > commit ede31f6ffe73357705e95016046e77c7e3d6ad13
> > Author: Jan Hubicka 
> > Date:   Tue Oct 1 21:46:09 2019 +0200
> 
> g:ede31f6ffe73357705e95016046e77c7e3d6ad13

Thanks for the tip, Andrew.
First report after the git migration

[Bug tree-optimization/93586] New: wrong code at -O1 on x86_64-linux-gnu

2020-02-04 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93586

Bug ID: 93586
   Summary: wrong code at -O1 on x86_64-linux-gnu
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

The master branch version of gcc miscompiles the code at -O1 and above.

It seems to be a recent regression. gcc-9 works fine.

Bisection points to:

commit ede31f6ffe73357705e95016046e77c7e3d6ad13
Author: Jan Hubicka 
Date:   Tue Oct 1 21:46:09 2019 +0200

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/10.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200204 (experimental) [master revision
5f0653a8b75:037d7906159:5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60] (GCC)


$ gcc-trunk abc.c && ./a.out
0

$ gcc-9 -O1 abc.c && ./a.out
0

$ gcc-trunk -O1 abc.c && ./a.out
-1


$ cat abc.c
int printf(const char *, ...);
short a;
long b;
int main() {
  char c[][10][1] = {7, 0, 5, 5};
  for (; b <= 3; b++) {
a = 0;
for (; a >= 0; a--)
  if (c[a][b][a])
break;
  }
  printf("%d\n", a);
}

[Bug debug/92468] gcc generates wrong debug information at -O2 and -O3

2019-11-11 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92468

Qirun Zhang  changed:

   What|Removed |Added

 CC||aoliva at gcc dot gnu.org

--- Comment #1 from Qirun Zhang  ---
Bisect points to r255569.

Author: aoliva 
Date:   Tue Dec 12 02:16:31 2017 +

[SFN] Introduce -gstatement-frontiers option, enable debug markers

Introduce a command line option to enable statement frontiers, enabled
by default in optimized builds with DWARF2+ debug information.

This patch depends on an earlier patch that completed the
infrastructure for debug markers, and on another patch that turns -g
into a negatable option prefix.

for  gcc/ChangeLog

* common.opt (gstatement-frontiers): New, setting
debug_nonbind_markers_p.
* rtl.h (MAY_HAVE_DEBUG_MARKER_INSNS): Activate.
* toplev.c (process_options): Autodetect value for debug statement
frontiers option.
* tree.h (MAY_HAVE_DEBUG_MARKER_STMTS): Activate.
* doc/invoke.texi (gstatement-frontiers, gno-statement-frontiers): New.

[Bug debug/92468] New: gcc generates wrong debug information at -O2 and -O3

2019-11-11 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92468

Bug ID: 92468
   Summary: gcc generates wrong debug information at -O2 and -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects the trunk and both 8 and 9 releases. Gcc-7 works fine.
The expected output is k=0 or opt-out. With O2 and O3, gdb outputs k=1.

$ gcc-trunk -v
gcc version 10.0.0 2019 (experimental) [trunk revision 278048] (GCC)

#expected output
$ gcc-trunk -g abc.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x40054c: file abc.c, line 20.

Breakpoint 1, main () at abc.c:20
20  if (g) printf("index = %d%d%d\n", b, f, k);  //   
optimize_me_not()
$1 = 0

#wrong output
$ gcc-trunk -g abc.c -O3
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4003c0: file abc.c, line 20.

Breakpoint 1, main () at abc.c:20
20  if (g) printf("index = %d%d%d\n", b, f, k);  //   
optimize_me_not()
$1 = 1




$ cat abc.c
int a,  b ;
short c[5][16] ;
void
d (e) {
 a =
  a ^ e;
}
int main ()
{
int f, k,  g = 0;
for (; b < 5; b++)
{
f = 0;
for (; f < 4; f++)
{
k = 0;
for (; k < 4; k++)
{
  d (c[b][f] & c[b][f*4+k] & 5);
if (g) printf("index = %d%d%d\n", b, f, k);  //   
optimize_me_not()
}
}
}
}



$ cat cmds
b abc.c:20
r
p k
kill
q

[Bug debug/92444] gcc generates wrong debug information at -O2 and -O3

2019-11-10 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92444

Qirun Zhang  changed:

   What|Removed |Added

 CC||hubicka at gcc dot gnu.org

--- Comment #1 from Qirun Zhang  ---
Bisect points to r277424.

commit 096bdef978db42b89b3c173f61c8c102cd6bf470
Author: hubicka 
Date:   Thu Oct 24 22:19:09 2019 +

* cgraphunit.c (symbol_table::process_new_functions): Call
ipa_free_size_summary.
* ipa-cp.c (ipcp_cloning_candidate_p): Update.
(devirtualization_time_bonus): Update.
(ipcp_propagate_stage): Update.
* ipa-fnsummary.c (ipa_size_summaries): New.
(ipa_fn_summary_alloc): Alloc size summary.
(dump_ipa_call_summary): Update.
(ipa_dump_fn_summary): Update.
(analyze_function_body): Update.
(compute_fn_summary): Likewise.
(ipa_get_stack_frame_offset): New function.
(inline_update_callee_summaries): Do not update frame offsets.
(ipa_merge_fn_summary_after_inlining): Update frame offsets here;
remove call and function summary.
(ipa_update_overall_fn_summary): Update.
(inline_read_section): Update.
(ipa_fn_summary_write): Update.
(ipa_free_fn_summary): Do not remove summaries.
(ipa_free_size_summary): New.
(release summary pass): Also run at WPA.
* ipa-fnsummary.h (ipa_size_summary): Declare.
(ipa_fn_summary): Remove size, self_size, stack_frame_offset,
estimated_self_stack_size.
(ipa_size_summary_t): New type.
(ipa_size_summaries): Declare.
(ipa_free_size_summary): Declare.
(ipa_get_stack_frame_offset): Declare.
* ipa-icf.c (sem_function::merge): Update.
* ipa-inline-analysis.c (estimate_size_after_inlining): Update.
(estimate_growth): Update.
(growth_likely_positive): Update.
(clone_inlined_nodes): Update.
(inline_call): Update.
* ipa-inline.c (caller_growth_limits): Update.

<...>

[Bug debug/92444] New: gcc generates wrong debug information at -O2 and -O3

2019-11-10 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92444

Bug ID: 92444
   Summary: gcc generates wrong debug information at -O2 and -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It seems to be a recent regression. gcc-9 works fine.
The expected output is 1. With "-O2" and "-O3", gdb outputs 8.

$ gcc-trunk -v
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191110 (experimental) [trunk revision 278017] (GCC)


#Expected output
$ gcc-trunk -g abc.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400592: file abc.c, line 46.

Breakpoint 1, o () at abc.c:46
46  }
$1 = 1

#Wrong output at O2 and O3
$ gcc-trunk -g abc.c -O2
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4005ac: file abc.c, line 45.

Breakpoint 1, o () at abc.c:45
45}; // optimize_me_not()
$1 = 8



$ cat abc.c
int a[1];
char b;
char *c = &b;
int d, h, l, m, ag, ah;
int *e = &d;
short f, g;
unsigned j;
long n;
char aa[10];
static unsigned char o(void);
static int *p(int *);
static int y() {
  int q = 6, r = 0;
  int *s;
  short *t, *u = &t;
  l = p(&q);
  o();
  if (n) {
int v = 0, w;
int x[] = {&v, &r};
b = *s;
w = &u;
  }
}
unsigned char o() {
  int l_1339[3];
  int *ab = &l_1339[2];
  int k;
  m = 0;
  for (; m < 3; m++)
l_1339[m] = 8;
  p(l_1339);
  for (; j <= 7; j++) {
for (;; f--)
  if (*a)
break;
char *ac;
char *ad[30];
char *ae = ad;
char *f = &ae;
k = 0;
for (; k < 3; k++)
  ad[k] = ∾
*ab = 0 != &g;
  }; // optimize_me_not()
}
int *p(int *z) {
  long af = 5;
  for (; af < 30; af = af + 6)
h = *z;
  int i = 0;
  for (; i < 10; i++)
aa[i] = *a = *c ^ 2;
  *e = ag;
  return ah;
}
int main() { y(); }



$ cat cmds
b abc.c:45
r
p l_1339[2]
kill
q

[Bug debug/92387] gcc generates wrong debug information at -O1

2019-11-09 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92387

Qirun Zhang  changed:

   What|Removed |Added

 CC||hubicka at gcc dot gnu.org

--- Comment #2 from Qirun Zhang  ---
Bisect points to r273479.


Author: hubicka 
Date:   Sun Jul 14 11:57:10 2019 +

* ipa-fnsummary.c (ipa_dump_hints): Do not dump array_index.
(ipa_fn_summary::~ipa_fn_summary): Do not destroy array_index.
(ipa_fn_summary_t::duplicate): Do not duplicate array_index.
(array_index_predicate): Remove.
(analyze_function_body): Account cost for variable ofsetted array
indexing.
(estimate_node_size_and_time): Do not compute array index hint.
(ipa_merge_fn_summary_after_inlining): Do not merge array index hint.
(inline_read_section): Do not read array index hint.
(ipa_fn_summary_write): Do not write array index hint.
* doc/invoke.texi (ipa-cp-array-index-hint-bonus): Remove.
* ipa-cp.c (hint_time_bonus): Remove.
* ipa-fnsummary.h (ipa_hints_vals): Remove array_index.
(ipa_fnsummary): Remove array_index.
* ipa-inline.c (want_inline_small_function_p): Do not use
array_index.
(edge_badness): Likewise.
* params.def (PARAM_IPA_CP_ARRAY_INDEX_HINT_BONUS): Remove.

[Bug debug/92417] gcc generates wrong debug information at -O2

2019-11-09 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92417

Qirun Zhang  changed:

   What|Removed |Added

 CC||hubicka at gcc dot gnu.org

--- Comment #1 from Qirun Zhang  ---
Bisect points to r276427.


Author: hubicka 
Date:   Tue Oct 1 19:46:09 2019 +

* tree-ssa-alias.c (nonoverlapping_component_refs_since_match_p):
Rename to ...
(nonoverlapping_refs_since_match_p): ... this; handle also
ARRAY_REFs.
(alias_stats): Update stats.
(dump_alias_stats): Likewise.
(cheap_array_ref_low_bound): New function.
(aliasing_matching_component_refs_p): Add partial_overlap
argument;
pass it to nonoverlapping_refs_since_match_p.
(aliasing_component_refs_walk): Update call of
aliasing_matching_component_refs_p
(nonoverlapping_array_refs_p): New function.
(decl_refs_may_alias_p, indirect_ref_may_alias_decl_p,
indirect_refs_may_alias_p): Update calls of
nonoverlapping_refs_since_match_p.

* gcc.dg/tree-ssa/alias-access-path-10.c: New testcase.
* gcc.dg/tree-ssa/alias-access-path-11.c: New testcase.

[Bug debug/92417] New: gcc generates wrong debug information at -O2

2019-11-07 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92417

Bug ID: 92417
   Summary: gcc generates wrong debug information at -O2
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It happens at O2 only. "-O1" and "-O3" works fine. It's a recent regression
since "gcc-9 -O2" also works.



The expected value of l_1162[0][0][0] should be 61344 or opt-out. However, with
"-O2", gdb outputs "l_1162[0][0][0]=3".



$ gcc-trunk -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191107 (experimental) [trunk revision 277920] (GCC)

#expected output
$ gcc-trunk -O1 -g abc.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400576: file abc.c, line 23.

Breakpoint 1, n () at abc.c:23
23  if (b)  // optimize_me_not()
$1 = 61344

#wrong output at O2
$ gcc-trunk -O2 -g abc.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400616: file abc.c, line 23.

Breakpoint 1, n () at abc.c:23
23  if (b)  // optimize_me_not()
$1 = 3



$ cat abc.c
int a, d, e, f, h, l;
short b, g, i, m;
char c;
void n() {
  char o;
  int p = 0, j, k;
  int q[70] = {0};
  for (; i <= 1; i++) {
unsigned short l_1162[6][2][2];
l = 0;
for (; l < 6; l++) {
  j = 0;
  for (; j < 2; j++) {
k = 0;
for (; k < 2; k++)
  l_1162[l][j][k] = 61344;
  }
}
for (; f <= 1; f++)
  if (d)
for (; p >= 0; p--)
  d = q[f];
if (b)  // optimize_me_not()
  h = l_1162[4][1][0];
for (; e; e++)
  g = l_1162[5][0][1] <= o;
c = a ? c : 0;
q[1] = m;
  }
}
int main() {
  n();
  printf("%X\n");
}



$ cat cmds
b abc.c:23
r
p l_1162[0][0][0]
kill
q

[Bug debug/92387] New: gcc generates wrong debug information at -O1

2019-11-05 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92387

Bug ID: 92387
   Summary: gcc generates wrong debug information at -O1
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It seems to be a recent regression. gcc-9 works fine.

The expected value of i should be 0 or opt-out. However, with "-O1", gdb
outputs "i=1".


$ gcc-trunk -v
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191105 (experimental) [trunk revision 277821] (GCC)


#expected output
$ gcc-trunk -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400540: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12  if (d) printf("index = %d\n", i); // stop here.
$1 = 0


#wrong output at -O1
$ gcc-trunk -O1 -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004a1: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12  if (d) printf("index = %d\n", i); // stop here.
$1 = 1


$ cat abc.c
static int a[6];
int b ;
static void c () {
  b =   5 ^   a[b  & 5];
}
int main () {
  int i,  d = 0;
  c ();
  i = 0;
  for (; i < 8; i++) {
c ();
if (d) printf("index = %d\n", i); // stop here.
  }
}



$ cat cmds
b abc.c:12
r
p i
kill
q

[Bug debug/90946] New: gcc generates wrong debug information at -O3

2019-06-19 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90946

Bug ID: 90946
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects the trunk at "-O3". The expected output is "105487". However, at
-O3, it prints "40369".

Bisect points to r270902. 



$ gcc-trunk -v
gcc version 10.0.0 20190619 (experimental) [trunk revision 272472] (GCC)
$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

#Correct output#
$ gcc-trunk  -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40052d: file abc.c, line 30.

Breakpoint 1, g (j=1) at abc.c:30
30  optimize_me_not();
$1 = 105487


#Wrong output#
$ gcc-trunk  -g abc.c outer.c -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400396: file abc.c, line 30.

Breakpoint 1, g (j=1) at abc.c:30
30  optimize_me_not();
$1 = 40369




$ cat abc.c
static short a = 8;
int b, f, h;
int *c;
volatile int d;
int e(j) {}
static char g(j) {
  unsigned short k;
  int l_756 = 40369, i = 0;
  int *l = &l_756;
  for (; i < 4; i++)
f = 4071609;
  if (f) {
int m[1];
if (j)
  ;
else {
  int **n = &c;
  *n = e(&l_756);
  **n = h;
  **n |= 0;
}
  } else {
k = b;
*c = k;
h &= 8;
  }
  d;
  if (a) {
*l = 105487;
optimize_me_not();
return 8;
  }
  int o = &l;
}
int main() { g(1); }

$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 30
r
p l_756
kill
q

[Bug debug/90716] New: gcc generates wrong debug information at -O2

2019-06-02 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90716

Bug ID: 90716
   Summary: gcc generates wrong debug information at -O2
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

This is a recent regression. Gcc-8 works fine. Bisect points to r271553.

The expected value of "j" should be 8. With optimization, it prints "0".


$ gcc-trunk -v
gcc version 10.0.0 20190602 (experimental) [trunk revision 271843] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


#Correct output#
$ gcc-trunk -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40049d: file abc.c, line 10.

Breakpoint 1, main () at abc.c:10
10optimize_me_not();
$1 = 8


#Wrong output at O2#
$ gcc-trunk -g abc.c outer.c -O2
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400396: file abc.c, line 10.

Breakpoint 1, main () at abc.c:10
10optimize_me_not();
$1 = 0






$ cat abc.c
int a[7][8];
int main() {
  int b, j;
  b = 0;
  for (; b < 7; b++) {
j = 0;
for (; j < 8; j++)
  a[b][j] = 0;
  }
  optimize_me_not();
}
$ cat cmds
b 10
r
p j
kill
q
$ cat outer.c
void optimize_me_not() {}

[Bug debug/90336] New: gcc generates wrong debug information at -O1 to -O3

2019-05-03 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90336

Bug ID: 90336
   Summary: gcc generates wrong debug information at -O1 to -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

This is a recent regression. Gcc-8 works fine. Bisect points to r260253.

The expected value of "l_90" should be 852. With optimization, it prints "-1".

$ gcc-trunk -v
Thread model: posix
gcc version 10.0.0 20190503 (experimental) [trunk revision 270847] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


#Expected output#
$ gcc-trunk -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004ad: file abc.c, line 11.

Breakpoint 1, d (e=852) at abc.c:11
11optimize_me_not();
$1 = 852


#Wrong output at -O3#
$ gcc-trunk -g abc.c outer.c -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400497: file abc.c, line 11.

Breakpoint 1, d (e=e@entry=852) at abc.c:11
11optimize_me_not();
$1 = -1



$ cat abc.c
int a;
long b;
short c;
int d(e) {
  int l_90 = -1L;
  a &&b != (c = 0);
  int *f, *g = &l_90, *i = &l_90;
  *g = e;
  int **h = &f;
  *h = i;
  optimize_me_not();
  if (b)
return a;
}
int main() { d(852); }

$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 11
r
p l_90
kill
q

[Bug debug/90131] New: wrong debug info at -O3

2019-04-17 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90131

Bug ID: 90131
   Summary: wrong debug info at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

This issue is similar to bug 90074 --- same flag, same gcc versions. The
bisection also points to r255267. It appears that the issue remains after the
patch. 


$ gcc-trunk -v
gcc version 9.0.1 20190417 (experimental) [trunk revision 270407] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


#Wrong result#
$ gcc-trunk -g abc.c outer.c -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40040f: file abc.c, line 16.

Breakpoint 1, main () at abc.c:16
16optimize_me_not();
$1 = 9


#Correct result#
$ gcc-trunk -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004c8: file abc.c, line 16.

Breakpoint 1, main () at abc.c:16
16optimize_me_not();
$1 = 0



$ cat abc.c
volatile long a;
int b[9][1];
static short c[2][1] = {3};
int main() {
  int i, d, e;
  i = 0;
  for (; i < 9; i++)
a = b[i][0];
  i = 0;
  for (; i < 2; i++) {
d = 0;
for (; d < 1; d++) {
  e = 0;
  for (; e < 1; e++)
a = c[i][e];
  optimize_me_not();
}
  }
}

$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 16
r
p i
kill
q

[Bug debug/90074] New: wrong debug info at -O3

2019-04-12 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90074

Bug ID: 90074
   Summary: wrong debug info at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It's a latent issue which affects 4.8-6, and 8-trunk. Gcc-7 works fine.
It happens at -O3 only. Bisect between gcc-7 and gcc-8 points to r255267.

$ gcc-trunk -v
gcc version 9.0.1 20190412 (experimental) [trunk revision 270309] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

## wrong result ##
$ gcc-trunk abc.c outer.c -g -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400394: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12optimize_me_not();
$1 = 0


## correct result ##
$ gcc-trunk abc.c outer.c -g
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40049f: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12optimize_me_not();
$1 = 7


$ cat abc.c
char a;
short b[7][1];
int main() {
  int i, c;
  a = 0;
  i = 0;
  for (; i < 7; i++) {
c = 0;
for (; c < 1; c++)
  b[i][c] = 0;
  }
  optimize_me_not();
}

$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 12
r
p i
kill
q

[Bug debug/90017] gcc generates wrong debug information at -O3

2019-04-11 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90017

--- Comment #3 from Qirun Zhang  ---
(In reply to Alexandre Oliva from comment #2)
> This odd behavior is an artifact of the way GCC lays out the basic blocks,
> and how GDB interprets the line number program.
> 
> The blocks containing the conditional calls to optimize_me_not in line 15
> are moved to the end of the function, in reverse order, while the rest of
> the inner loop, with code from lines 12 to 14, remains in sequential order.
> 
> What GDB sees then is a long chunk of code all at line 15, the first of
> which corresponds to the iteration l=8.  l=7 is later, with another line
> number mark, then l=6 and so on, but without intervening line number
> changes, it takes it all as a single line.  GDB pays no attention to the
> is_stmt=1 markers at each and every one of them, let alone to the different
> view numbers.
> 
> So, yeah, definitely consumer issue.

Hi Alex,

Are you suggesting that it's a gdb bug? Perhaps, I can report it to gdb
instead? Thanks.

[Bug debug/90017] New: gcc generates wrong debug information at -O3

2019-04-08 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90017

Bug ID: 90017
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It seems to be a recent regression, starting at r269302.
It only affects "-O3" and trunk.
The correct value is "l=0". With -O3, it generates l=8.


$ gcc-trunk -v
gcc version 9.0.1 20190408 (experimental) [trunk revision 270202] (GCC)

#correct output#
$ gcc-trunk -g abc.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004a5: file abc.c, line 15.

Breakpoint 1, main () at abc.c:15
15optimize_me_not();
$1 = 0

#wrong output#
$ gcc-trunk -g abc.c -O3
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400470: file abc.c, line 15.

Breakpoint 1, main () at abc.c:15
15optimize_me_not();
$1 = 8







$ cat abc.c
__attribute__((noipa))  optimize_me_not(){
   __asm__ volatile ("" : : : "memory");
 }

int a, b;
int c[][2] = {{2}, {5}, 2};
int main() {
  {
int l;
for (; b <= 1; b++) {
  l = 0;
  for (; l <= 8; l++) {
a ^= c[b + 1][b];
if (a)
  optimize_me_not();
  }
}
  }
}


$ cat cmds
b 15
r
p l
k
q

[Bug debug/89905] New: gcc generates wrong debug information at -Og

2019-04-01 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89905

Bug ID: 89905
   Summary: gcc generates wrong debug information at -Og
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-8 to trunk. Gcc-7 works fine.

Bisection points to r247596.

The correct value is "i=830100328". However, with "-Og", gdb outputs
"i=830100327".

$ gcc-trunk -v
gcc version 9.0.1 20190401 (experimental) [trunk revision 270054] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


#correct output#
$ gcc-trunk -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40057a: file abc.c, line 22.

Breakpoint 1, i () at abc.c:22
22  optimize_me_not();
$1 = 830100328


#incorrect output#
$ gcc-trunk -g abc.c outer.c -Og
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4004f3: file abc.c, line 22.

Breakpoint 1, i () at abc.c:22
22  optimize_me_not();
$1 = 830100327




$ cat abc.c
char c, d = 22, f;
short e, g;
int h;
char(a)() {}
char(b)() { return 0; }
void i() {
  char j;
  for (; h < 1;) {
short k[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
int l, i = 830100327;
short m[3] = {0, 0, 0};
for (; h < 7; h++)
  for (; d >= 33;) {
++k[8];
f = (c || a()) && g;
  }
i++;
j = b() || m[2];
l = 0;
for (; l <= 6; l = d)
  e = k[8];
optimize_me_not();
  }
}
int main() { i(); }


$ cat cmds
b 22
r
p i
kill
q


$ cat outer.c
void optimize_me_not() {}

[Bug debug/89792] gcc generates wrong debug information at -O3

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89792

Qirun Zhang  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #3 from Qirun Zhang  ---
Fixed in r269961.

[Bug debug/89791] gcc generates wrong debug information at -O3

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89791

Qirun Zhang  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #3 from Qirun Zhang  ---
Fixed in r269961.

[Bug debug/88882] gcc generates wrong debug information at -O1

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2

--- Comment #2 from Qirun Zhang  ---
Bisection points to r216247.

[Bug rtl-optimization/88730] [8 Regression] gcc generates wrong debug information at -Og

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88730

--- Comment #4 from Qirun Zhang  ---
Bisection points to r254888.

[Bug rtl-optimization/89528] Wrong debug info generated at -Og [gcc-trunk]

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89528

Qirun Zhang  changed:

   What|Removed |Added

 CC||qrzhang at gatech dot edu

--- Comment #2 from Qirun Zhang  ---
Bisection points to r217125.

[Bug debug/89529] Wrong debug info generated at -Og [gcc-trunk]

2019-03-31 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89529

Qirun Zhang  changed:

   What|Removed |Added

 CC||qrzhang at gatech dot edu

--- Comment #3 from Qirun Zhang  ---
Bisection points to r235905

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-25 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #9 from Qirun Zhang  ---
(In reply to Richard Biener from comment #8)
> Patch posted here: https://gcc.gnu.org/ml/gcc-patches/2019-03/msg01192.html
> 
> Some of your bugs might turn out as duplicates if they are fixed by that
> patch.

Thanks, Richard. When will the patch be landed? It helps a lot to reduce
duplicates.

[Bug debug/89801] New: gcc generates wrong debug information at -O2

2019-03-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89801

Bug ID: 89801
   Summary: gcc generates wrong debug information at -O2
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-6 to gcc-trunk. gcc-5 works fine.

Bisect points to r222305.


$ gcc-trunk -v
gcc version 9.0.1 20190322 (experimental) [trunk revision 269869] (GCC)

$ gdb -v
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1


# Correct ouutput #
$ gcc-trunk  -g abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400486: file abc.c, line 9.

Breakpoint 1, d () at abc.c:9
9 c = 3;
$1 = 1


# Incorrect output at O2 #
$ gcc-trunk  -g abc.c outer.c -O2
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400380: file abc.c, line 9.

Breakpoint 1, main () at abc.c:18
18for (; i < 5; i++)
$1 = 0





$ cat abc.c
long a, b;
static int c, f;
static long d() {
  int *e = &c;
  int i = 0;
  for (; i < 1; i++)
;
  *e ^= b;
  c = 3;
  for (; 0;)
optimize_me_not();
  ;
}
int main() {
  int i;
  d();
  i = 0;
  for (; i < 5; i++)
for (; f; f++)
  ;
  a = c;
}


$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 9
r
p i
kill
q

[Bug debug/89792] gcc generates wrong debug information at -O3

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89792

--- Comment #1 from Qirun Zhang  ---
This might be a latent issue.

Attaching my gcc version:

$ gcc-trunk -v
Thread model: posix
gcc version 9.0.1 20190321 (experimental) [trunk revision 269832] (GCC)

$ gcc-7 -v
Thread model: posix
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~16.04~ppa1)

$ gcc-8 -v
gcc version 8.1.0 (Ubuntu 8.1.0-5ubuntu1~16.04)

[Bug debug/89792] New: gcc generates wrong debug information at -O3

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89792

Bug ID: 89792
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-8 and gcc-trunk. gcc-7 works fine.

The testcase looks similar to Bug 89463. But they affect different gcc versions
and bisect points to different revisions. It would be helpful to have them
fixed.

For this bug, bisect points to r255569.



$ cat abc.c
volatile int a, b;
static int c;
int main() {
  int i;
  b = 0;
  i = 0;
  for (; i < 3; i++)
a = c;
  i = 0;
  for (; i < 5; i++)
;
  optimize_me_not();
}

$ cat outer.c
void optimize_me_not() {}

$ cat cmds
b 12
r
p i
kill
q



#Correct output#
$ gcc-trunk -g  abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400496: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12optimize_me_not();
$1 = 5

#Wrong output#
$ gcc-trunk -g -O3 abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x4003ae: file abc.c, line 12.

Breakpoint 1, main () at abc.c:12
12optimize_me_not();
$1 = 0

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #6 from Qirun Zhang  ---
As mentioned in my earlier comment, the revision should be between gcc-5 and
gcc-6.

Bisect points to r239357.


commit ec969ce4161538b561592a032eca6dcfaf513596
Author: rguenth 
Date:   Thu Aug 11 09:02:04 2016 +

2016-08-11  Richard Biener  

PR tree-optimization/72772
* cfgloopmanip.c (create_preheader): Use split_edge if there
is a single loop entry, avoiding degenerate PHIs.

* gcc.dg/graphite/pr35356-1.c: Adjust.
* gcc.dg/tree-ssa/pr59597.c: Likewise.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239357
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #5 from Qirun Zhang  ---
(In reply to Qirun Zhang from comment #4)
> Bisect points to r151362.
> 
> commit ff79704e04af919c4fe501c7dceca8b21cced614
> Author: aoliva 
> Date:   Thu Sep 3 05:24:57 2009 +
> 
> * toplev.c (process_options): Enable var-tracking-assignments
> by default if var-tracking is enabled.
> 
> 
> git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
> 138bc75d-0d04-0410-961f-82ee72b054a4

Sorry... Please discard this comment. This was meant for another bug. Let me
post the bisect result in the following comment..

[Bug debug/89454] gcc generates wrong debug information at -Og

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89454

--- Comment #2 from Qirun Zhang  ---
(In reply to Qirun Zhang from comment #1)
> Bisect points to r151362.
> 
> commit ff79704e04af919c4fe501c7dceca8b21cced614
> Author: aoliva 
> Date:   Thu Sep 3 05:24:57 2009 +
> 
> * toplev.c (process_options): Enable var-tracking-assignments
> by default if var-tracking is enabled.
> 
> 
> git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
> 138bc75d-0d04-0410-961f-82ee72b054a4

Bisected the result with "-O3" since gcc-4.4 does not support "-Og".

[Bug debug/89454] gcc generates wrong debug information at -Og

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89454

--- Comment #1 from Qirun Zhang  ---
Bisect points to r151362.

commit ff79704e04af919c4fe501c7dceca8b21cced614
Author: aoliva 
Date:   Thu Sep 3 05:24:57 2009 +

* toplev.c (process_options): Enable var-tracking-assignments
by default if var-tracking is enabled.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89791] New: gcc generates wrong debug information at -O3

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89791

Bug ID: 89791
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It affects gcc-4.6 to gcc-trunk. The expected output is "i=7" or . With "-O3", it outputs "i=0".

I am using two files since "noipa" attribute directive is not supported in
early gcc versions.

Bisect points to r154402.

commit 43e54ec3e93dd2ef495375ead1f1eac467a727d1
Author: aoliva 
Date:   Sat Nov 21 05:06:24 2009 +

* tree-ssa.c (find_released_ssa_name): Handle NULL wi.
(insert_debug_temp_for_var_def): Handle degenerate PHI nodes.
(insert_debug_temps_for_defs): Handle PHI nodes.
* tree-ssa-dom.c (degenerate_phi_result): Don't crash on released
SSA names.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154402
138bc75d-0d04-0410-961f-82ee72b054a4


$ gcc-trunk -v
gcc version 9.0.1 20190321 (experimental) [trunk revision 269832] (GCC)


$ cat abc.c
int main() {
  int i = 0;
  for (; i < 7; i++)
;
optimize_me_not();
}


$ cat outer.c
void optimize_me_not() {}

# correct output #
$ gcc-trunk -g  abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40046d: file abc.c, line 5.

Breakpoint 1, main () at abc.c:5
5   optimize_me_not();
$1 = 7

# Wrong output #
$ gcc-trunk -g  abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400380: file abc.c, line 5.

Breakpoint 1, main () at abc.c:5
5   optimize_me_not();
$1 = 0

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-03-21 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #4 from Qirun Zhang  ---
Bisect points to r151362.

commit ff79704e04af919c4fe501c7dceca8b21cced614
Author: aoliva 
Date:   Thu Sep 3 05:24:57 2009 +

* toplev.c (process_options): Enable var-tracking-assignments
by default if var-tracking is enabled.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151362
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89530] Wrong debug informations for C array generated at -Og [gcc-trunk]

2019-03-20 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89530

Qirun Zhang  changed:

   What|Removed |Added

 CC||qrzhang at gatech dot edu

--- Comment #8 from Qirun Zhang  ---
bisect points to revision r217125.


commit 058a1b7aa18100b0cabbfa6c4b1fb6c97b8131a2
Author: ienkovich 
Date:   Wed Nov 5 12:42:03 2014 +

gcc/

2014-11-05  Ilya Enkovich  

* ipa-chkp.c: New.
* ipa-chkp.h: New.
* tree-chkp.c: New.
* tree-chkp.h: New.
* tree-chkp-opt.c: New.
* rtl-chkp.c: New.
* rtl-chkp.h: New.
* Makefile.in (OBJS): Add ipa-chkp.o, rtl-chkp.o, tree-chkp.o
<...>
2014-11-05  Ilya Enkovich  

* gcc.target/i386/chkp-builtins-1.c: New.
* gcc.target/i386/chkp-builtins-2.c: New.
* gcc.target/i386/chkp-builtins-3.c: New.
* gcc.target/i386/chkp-builtins-4.c: New.
* gcc.target/i386/chkp-remove-bndint-1.c: New.
* gcc.target/i386/chkp-remove-bndint-2.c: New.
* gcc.target/i386/chkp-const-check-1.c: New.
* gcc.target/i386/chkp-const-check-2.c: New.
* gcc.target/i386/chkp-lifetime-1.c: New.
* gcc.dg/pr37858.c: Replace early_local_cleanups pass name
with build_ssa_passes.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217125
138bc75d-0d04-0410-961f-82ee72b054a4

[Bug debug/89463] debug information for iteractor of an empty loop is gone (at -O3)

2019-02-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

--- Comment #2 from Qirun Zhang  ---
(In reply to Andrew Pinski from comment #1)
> What is happening is the empty loop is being removed and not replaced with a
> debug statement say i is 6 afterwards.  I don't know if this is a good idea
> to put a debug statement here or not.

Agreed.
Nevertheless, it should not print a wrong value.
The expected behavior is "" like  what gcc-6.5.0 does as
follows:


$ gcc-6 -O3 out.c abc.c -g
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x547: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 17644) killed]

[Bug debug/89463] New: gcc generates wrong debug information at -O3

2019-02-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89463

Bug ID: 89463
   Summary: gcc generates wrong debug information at -O3
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It bug affects the latest trunk.
It also affects gcc-8 and gcc-7.
gcc-6 works fine.

With "-O3", it incorrectly prints "i=0".



$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.1 20190222 (experimental) [trunk revision 269113] (GCC)



$ cat abc.c
int a;
int main() {
  int i;
  for (; a < 10; a++)
i = 0;
  for (; i < 6; i++)
;
  optimize_me_not();
}

$ cat outer.c
optimize_me_not() {}


$ cat cmds
b 8
r
p i
kill
q



$ gcc-trunk -g abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4004b9: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 6
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 29883) killed]






$ gcc-trunk -g abc.c outer.c -O3
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4003b7: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 31868) killed]

[Bug debug/89454] New: gcc generates wrong debug information at -Og

2019-02-22 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89454

Bug ID: 89454
   Summary: gcc generates wrong debug information at -Og
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It bug affects the latest trunk.
It also affects gcc-8 to gcc-4.8.

With "-Og", it incorrectly prints "l=0".


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.1 20190222 (experimental) [trunk revision 269113] (GCC)


$ cat abc.c
int a;
int main() {
  char l = 0;
  if (a)
;
  else
l = 10 || 0;
  optimize_me_not();
}

$ cat cmds
b 8
r
p l
kill
q

$ cat outer.c
optimize_me_not() {}


$ gcc-trunk -g  abc.c outer.c
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x40049c: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 1 '\001'
Kill the program being debugged? (y or n) [answered Y; input not from terminal]




$ gcc-trunk -g  abc.c outer.c -Og
$ gdb -x cmds -batch a.out
Breakpoint 1 at 0x400486: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
$1 = 0 '\000'
Kill the program being debugged? (y or n) [answered Y; input not from terminal]

[Bug debug/88882] New: gcc generates wrong debug information at -O1

2019-01-16 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2

Bug ID: 2
   Summary: gcc generates wrong debug information at -O1
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

It incorrectly prints "l = 0" at -O1. CC'ing alex..



$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.0 20181224 (experimental) [trunk revision 267411] (GCC)
$ gdb-trunk -v
GNU gdb (GDB) 8.2.50.20181223-git




It prints "l = 2" without optimization.

$ gcc-trunk -g  abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x40048e: file abc.c, line 9.

Breakpoint 1, main () at abc.c:9
9   optimize_me_not();
$1 = 2
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 11426) killed]


It incorrectly prints "l = 0" at -O1.

$ gcc-trunk -g  abc.c outer.c -O1
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400489: file abc.c, line 9.

Breakpoint 1, main () at abc.c:9
9   optimize_me_not();
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 11440) killed]


$ cat abc.c
int a;
int b;
int c;
int main() {
  for (; b;)
;
  int l = 2;
  for (; c < 2; c++)
optimize_me_not();
  l = a;
}
$ cat outer.c
optimize_me_not() {}
$ cat cmds
b 9
r
p l
k
q

[Bug debug/88730] gcc generates wrong debug information at -Og

2019-01-06 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88730

--- Comment #1 from Qirun Zhang  ---
It appears to be a regression in 8.X.

[Bug debug/88730] New: gcc generates wrong debug information at -Og

2019-01-06 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88730

Bug ID: 88730
   Summary: gcc generates wrong debug information at -Og
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

Unlike PR88686, it happens at -Og.

The correct value of j should be 5. At "-Og", gdb prints "j = 2" incorrectly.


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.0 20190106 (experimental) [trunk revision 267609] (GCC)




$ gcc-trunk -g abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400507: file abc.c, line 11.
0

Breakpoint 1, main () at abc.c:11
11optimize_me_not();
$1 = 5



$ gcc-trunk -g -Og abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x4004e4: file abc.c, line 11.
0

Breakpoint 1, main () at abc.c:11
11optimize_me_not();
$1 = 2





=== files to reproduce 
$ cat abc.c
int a;
int main() {
  int b, j;
  b = 0;
  for (; b < 1; b++) {
j = 0;
for (; j < 5; j++)
  ;
  }
  printf("%X\n", a);
  optimize_me_not();
}

$ cat outer.c
optimize_me_not(){}

$ cat cmds
b 11
r
p j
kill
q

[Bug debug/88686] gcc generates wrong debug information at -O1

2019-01-03 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88686

--- Comment #1 from Qirun Zhang  ---
The output should be "j=0". However, it incorrectly prints "j=1" at -O1.

[Bug debug/88686] New: gcc generates wrong debug information at -O1

2019-01-03 Thread qrzhang at gatech dot edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88686

Bug ID: 88686
   Summary: gcc generates wrong debug information at -O1
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: qrzhang at gatech dot edu
  Target Milestone: ---

I have reported this bug at gdb
bugzilla(https://sourceware.org/bugzilla/show_bug.cgi?id=24032). However, it
appears to be a gcc bug. I can reproduce the bug with "gcc version 9.0.0
20190103 (experimental) [trunk revision 267553] (GCC)". The gdb version does
not matter. I can reproduce it with gdb 7.7.

Below is my original report:


=8<=
$ gdb-trunk --version
GNU gdb (GDB) 8.2.50.20181223-git

*It correctly prints the value without optimization*
$ gcc-trunk -g  abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400485: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
9 c = 0;
$1 = 0
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 2315) killed]



*It incorrectly prints "j=1" at -O1*
$ gcc-trunk -g -O1  abc.c outer.c
$ gdb-trunk -x cmds -batch a.out
Breakpoint 1 at 0x400491: file abc.c, line 8.

Breakpoint 1, main () at abc.c:8
8 optimize_me_not();
10for (; c < 6; c++)
$1 = 1
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 2331) killed]


*Files used to reproduce*
$ cat abc.c
volatile int a, b;
int c;
int main() {
  int j;
  for (; b < 10; b++) {
j = 0;
for (; j < 2; j++) {
  optimize_me_not();
  c = 0;
  for (; c < 6; c++)
a = b + c;
}
  }
}
$ cat outer.c
optimize_me_not() {}
$ cat cmds
b 8
r
n
p j
k
q
=8<=