https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112565
Bug ID: 112565 Summary: Abnormal Jump in Execution using 'stepi' Command in GDB under O2 optimization Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: iamanonymous.cs at gmail dot com Target Milestone: --- Bug reported initially reported: https://sourceware.org/bugzilla/show_bug.cgi?id=31070 Tom de Vries suggests that this issue may be attributed to a GCC optimization bug. $ cat small.c int glob_int_arr[100]; int *glob_ptr_int = glob_int_arr; void simple_global () { __builtin_prefetch (glob_int_arr, 0, 0); __builtin_prefetch (glob_ptr_int, 0, 0); } int main() { simple_global (); exit (0); } $ gcc -w -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: /root/devil/a.out Breakpoint 1, main () at small.c:6 6 __builtin_prefetch (glob_int_arr, 0, 0); (gdb) si 0x0000000000401044 in simple_global () at small.c:7 7 __builtin_prefetch (glob_ptr_int, 0, 0); (gdb) si 0x000000000040104b in main () at small.c:13 13 exit (0); (gdb) si 0x000000000040104d in simple_global () at small.c:6 6 __builtin_prefetch (glob_int_arr, 0, 0); (gdb) ================================================= When using the 'stepi' command in GDB, an abnormal jump in the execution occurs when reaching line 7 of the code. The execution unexpectedly jumps to line 13. $ gcc --version gcc (GCC) 14.0.0 20231116 (experimental) Copyright (C) 2023 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) 15.0.50.20231116-git Copyright (C) 2023 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.