public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/95431] New: inconsistent behaviors at -O2
@ 2020-05-30  3:00 yangyibiao at hust dot edu.cn
  2020-05-30  3:04 ` [Bug debug/95431] " yangyibiao at hust dot edu.cn
  2021-03-07  7:21 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: yangyibiao at hust dot edu.cn @ 2020-05-30  3:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95431
           Summary: inconsistent behaviors at -O2
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Consider test case:
...
$ cat small.c
#include <string.h>

volatile int one = 1;

int main() {
  char a1[] = {(char)one, 2, 3, 4};
  char a2[] = {1, (char)(2*one), 3, 4};
  int res = memcmp (a1, a2, 5 + one);
  return res;
}
...

When stepping using step Line 7 is not hit by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6         char a1[] = {(char)one, 2, 3, 4};
(gdb) step
8         int res = memcmp (a1, a2, 5 + one);
(gdb) 
...

When stepping using stepi, Line 7 is hit after Line 6 by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) si
The program is not being run.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6         char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x0000000000401044      6         char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x000000000040104a      7         char a2[] = {1, (char)(2*one), 3, 4};
(gdb) 



$ gcc --version
gcc (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

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

* [Bug debug/95431] inconsistent behaviors at -O2
  2020-05-30  3:00 [Bug debug/95431] New: inconsistent behaviors at -O2 yangyibiao at hust dot edu.cn
@ 2020-05-30  3:04 ` yangyibiao at hust dot edu.cn
  2021-03-07  7:21 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: yangyibiao at hust dot edu.cn @ 2020-05-30  3:04 UTC (permalink / raw)
  To: gcc-bugs

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

Yibiao Yang <yangyibiao at hust dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yangyibiao at hust dot edu.cn

--- Comment #1 from Yibiao Yang <yangyibiao at hust dot edu.cn> ---
Created attachment 48640
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48640&action=edit
a.out

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

* [Bug debug/95431] inconsistent behaviors at -O2
  2020-05-30  3:00 [Bug debug/95431] New: inconsistent behaviors at -O2 yangyibiao at hust dot edu.cn
  2020-05-30  3:04 ` [Bug debug/95431] " yangyibiao at hust dot edu.cn
@ 2021-03-07  7:21 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-07  7:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks correct at the gimple level:
  [t.c:6:3] # DEBUG BEGIN_STMT
  [t.c:6:16] one.0_1 ={v} one;
  [t.c:6:16] _2 = (char) one.0_1;
  [t.c:6:8] a1[0] = _2;
  [t.c:6:8] MEM <unsigned short> [(char *)&a1 + 1B] = 770;
  [t.c:6:8] a1[3] = 4;

  [t.c:7:3] # DEBUG BEGIN_STMT
  [t.c:7:8] a2[0] = 1;
  [t.c:7:19] one.1_3 ={v} one;
  [t.c:7:19] _4 = (unsigned char) one.1_3;
  [t.c:7:19] _5 = _4 * 2;
  [t.c:7:19] _6 = (char) _5;
  [t.c:7:8] a2[1] = _6;
  [t.c:7:8] MEM <unsigned short> [(char *)&a2 + 2B] = 1027;

  [t.c:8:3] # DEBUG BEGIN_STMT
  [t.c:8:31] one.2_7 ={v} one;
  [t.c:8:31] _8 = one.2_7 + 5;
  [t.c:8:13] _9 = (long unsigned int) _8;
  [t.c:8:13] res_19 = memcmp ([t.c:8:21] &a1, [t.c:8:25] &a2, _9);
  [t.c:8:13] # DEBUG res => res_19
  [t.c:9:3] # DEBUG BEGIN_STMT

Assembly:
        .loc 1 6 3 view .LVU1
        .loc 1 5 12 is_stmt 0 view .LVU2
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        .loc 1 6 16 view .LVU3
        movl    one(%rip), %eax
        .loc 1 7 8 view .LVU4
        movl    $1027, %edx
        movw    %dx, 14(%rsp)
        .loc 1 8 13 view .LVU5
        leaq    12(%rsp), %rsi
        leaq    8(%rsp), %rdi
        .loc 1 6 16 view .LVU6
        movb    %al, 8(%rsp)
        .loc 1 6 8 view .LVU7
        movl    $770, %eax
        movw    %ax, 9(%rsp)
        .loc 1 7 19 view .LVU8
        movl    one(%rip), %eax
        .loc 1 8 31 view .LVU9
        movl    one(%rip), %edx
        .loc 1 6 8 view .LVU10
        movb    $4, 11(%rsp)
        .loc 1 7 3 is_stmt 1 view .LVU11
        .loc 1 8 3 view .LVU12
        .loc 1 7 19 is_stmt 0 view .LVU13
        addl    %eax, %eax
        .loc 1 7 8 view .LVU14
        movb    $1, 12(%rsp)
        .loc 1 8 31 view .LVU15
        addl    $5, %edx
        .loc 1 7 19 view .LVU16
        movb    %al, 13(%rsp)
        .loc 1 8 13 view .LVU17
        movslq  %edx, %rdx


This could be a gdb issue because what GCC produces look correct.

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

end of thread, other threads:[~2021-03-07  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30  3:00 [Bug debug/95431] New: inconsistent behaviors at -O2 yangyibiao at hust dot edu.cn
2020-05-30  3:04 ` [Bug debug/95431] " yangyibiao at hust dot edu.cn
2021-03-07  7:21 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).