News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Recent posts

#71
Bug reports / Re: Maybe a optimization bug.
Last post by Pelle - April 18, 2026, 05:52:29 PM
Quote from: John Z on April 14, 2026, 04:43:36 PMBut seriously yes there have been, and are issues, with using the optimizations and extensive testing is always needed for these.  I have many programs using optimizations successfully.
I my experience, enabling the optimizer on poorly written C code is more of a problem than the optimizer itself.
#72
Bug reports / Re: Maybe a optimization bug.
Last post by Pelle - April 18, 2026, 05:48:32 PM
A sanity check is missing in the loop idiom optimizer: triangular numbers. This affects all targets. We'll see when I can fix this...

/* The triangular numbers are given by the following formula:
 * Tn = 1 + 2 + 3 + .. + n = (n * (n + 1)) / 2
 */
#73
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 16, 2026, 09:13:41 PM
Disassembling the 32-bit MS COFF object module, building the project as 32-bit console application :

_text   SEGMENT PARA PUBLIC 'CODE'

_main   PROC NEAR
        push    eax
        push    offset @152
        call    _printf                               
        add     esp, 8     
        push    5050                                   
        push    offset @154                           
        call    _printf                               
        add     esp, 8                                 
        xor     eax, eax                               
        ret                                           
_main   ENDP

.rdata  SEGMENT DWORD PUBLIC 'CONST'               

@154    label byte
        db 73H, 75H, 6DH, 3DH, 25H, 64H, 0AH, 00H       ; 0000 _ sum=%d..

@152    label byte
        db 69H, 3DH, 25H, 64H, 0AH, 00H                 ; 0008 _ i=%d..

.rdata  ENDS
#74
Bug reports / Re: Maybe a optimization bug.
Last post by TimoVJL - April 16, 2026, 06:04:07 PM
It might be a cdecl problem, so 32-bit programs can use stdcall to avoid it.
#75
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 15, 2026, 10:00:46 PM
The trick i=i-(-1); seems to solve the issue :

#include <stdio.h>

int main(void)
{
int i=1, sum=0;
while (i<=100)
{
sum=sum+i;
//i++;
i=i-(-1);
}
printf("i=%d\n",i);
printf("sum=%d\n",sum);
return 0;
}
#76
Bug reports / Re: Maybe a optimization bug.
Last post by John Z - April 15, 2026, 01:57:27 PM
Quote from: Vortex on April 15, 2026, 10:35:59 AMBy the way, uncommenting the line below will output the correct result :

Very typical in my experience for the optimization failures.  Sometimes even just a 1 byte change can make it work, or make it fail.

John Z
#77
Add-ins / Re: Line Counter Add-IN
Last post by John Z - April 15, 2026, 01:48:16 PM
Updated DLL for Pelles C Version 14.  No code changes, up-sized the menu icon

John Z
#78
Bug reports / Re: Maybe a optimization bug.
Last post by TimoVJL - April 15, 2026, 12:35:08 PM
For all bug hunters, use pope.exe to check obj-file, as it have internal disassembler.
#79
Bug reports / Re: Maybe a optimization bug.
Last post by Vortex - April 15, 2026, 10:35:59 AM
By the way, uncommenting the line below will output the correct result :

printf("i=%d\n",i);
#include <stdio.h>

int main(void)
{
    int i=1, sum=0;
    while (i<=100)
    {
        printf("i=%d\n",i);
        sum=sum+i;
        i++;
    }
    printf("i=%d\n",i);
    printf("sum=%d\n",sum);
    return 0;
}
#80
Bug reports / Re: Maybe a optimization bug.
Last post by TimoVJL - April 15, 2026, 07:55:56 AM
from Clang
main:
00000000  4883EC28                sub rsp, 28h
00000004  488D0D00000000          lea rcx, [??_C@_05BKKKKIID@i?$DN?$CFd?6?$AA@]
0000000B  BA65000000              mov edx, 65h
00000010  E800000000              call printf
00000015  488D0D00000000          lea rcx, [??_C@_07MJFEPNKA@sum?$DN?$CFd?6?$AA@]
0000001C  BABA130000              mov edx, 13BAh
00000021  E800000000              call printf
00000026  31C0                    xor eax, eax
00000028  4883C428                add rsp, 28h
0000002C  C3                      ret
As Vortex mentioned, this was missingmov edx, 65h