https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119959
Bug ID: 119959 Summary: [15 regression] simple loop miscompiled into an endless loop Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bruno at clisp dot org Target Milestone: --- Created attachment 61205 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61205&action=edit test case foo.c gcc 15.1.0 (built from source, full bootstrap, with isl) generates wrong code for the function 'rehash_symtab' in the attached test case foo.c. How to reproduce: $ gcc -Wall -O1 -S -fno-dwarf2-cfi-asm foo.c -o foo.gcc15.O1.s For comparison, gcc 14.2.0 (also built from source, full bootstrap, with isl) generates correct code: $ gcc -Wall -O1 -S -fno-dwarf2-cfi-asm foo.c -o foo.gcc14.O1.s In the source code, the function rehash_symtab contains two loops, each with a call to newinsert() in the middle, and a final epilogue that stores two words in memory and then returns. In foo.gcc14.O1.s (correct) you can see the second loop like this: =============================================================== .L8: addq $8, %r12 cmpq %r12, %rbx je .L16 .L9: movq STACK(%rip), %rax movq -24(%rax), %rdx movq 10(%r12,%rdx), %rdi cmpq $symbol_tab_data+6, %rdi je .L8 movq %rdi, %rdx andl $7, %edx cmpq $2, %rdx je .L8 movq %rdi, (%rax) addq $8, STACK(%rip) movl %ebp, %esi call newinsert subq $8, STACK(%rip) jmp .L8 =============================================================== In foo.gcc15.O1.s (miscompiled) you can see the second loop like this: =============================================================== .L7: addq $8, %rbx .L8: movq STACK(%rip), %rax movq -24(%rax), %rdx movq 10(%rbx,%rdx), %rdi cmpq $symbol_tab_data+6, %rdi je .L7 movq %rdi, %rdx andl $7, %edx cmpq $2, %rdx je .L7 movq %rdi, (%rax) addq $8, STACK(%rip) movl %ebp, %esi call newinsert subq $8, STACK(%rip) jmp .L7 =============================================================== You can see that here, - between .L7 and .L8 the loop termination condition is missing, (foo.c line 118), - accordingly the loop has become and endless loop, - and as a consequence the function's epilogue has been removed.