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.