Community
cancel
Showing results for 
Search instead for 
Did you mean: 
54 Views

NIOS GCC optimizaton issue with memset in data flow

Hi,

Performing an activity of source to object code (checking if the compiler generated exactly what was intended, nothing more,nothing less) I detected a failure.

Source code:

UINT32 ServiceCallingMemset(int a, size_t b)
{
    UINT8 MemoryToBeSet = 0;
    memset((void*)&MemoryToBeSet,a,b);
    if(MemoryToBeSet == 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

Object code:

4200bdc: defffe04 addi sp,sp,-8
4200be0: dfc00115 stw ra,4(sp)
4200be4: 280d883a mov r6,r5
4200be8: 200b883a mov r5,r4
4200bec: d809883a mov r4,sp
4200bf0: 420838c0 call 420838c <memset>
4200bf4: 0005883a mov r2,zero
4200bf8: dfc00117 ldw ra,4(sp)
4200bfc: dec00204 addi sp,sp,8
4200c00: f800283a ret

If you verify the output object code, the compiler optimization is removing the "if statement" and inserting the "else statement" only ('return 0').

But this is not correct, the compiler is not evaluating correctly the possible value for 'MemoryToBeSet'. It seems the compiler is ignoring the 'memset' instruction.

This issue only appear when using optimization.

The compilation flags used are:

nios2-elf-g++ -T'J:\HVS\Source\INT_BSP/linker.x' -msys-crt0='J:\HVS\Source\INT_BSP/obj/HAL/src/crt0.o' -msys-lib=hal_bsp -LJ:\HVS\Source\INT_BSP -Wl,-Map=Src2ObjCode.map -O1 -g -Wall -fno-defer-pop -fno-merge-constants -fno-thread-jumps -fno-loop-optimize -fno-crossjumping -fno-if-conversion -fno-if-conversion2 -fno-delayed-branch -fno-guess-branch-probability -fno-cprop-registers -mhw-div -mhw-mul -mhw-mulx -mgpopt=local -o Src2ObjCode.elf obj/Default/SRC/Src2ObjCode.o obj/Default/SRC/comm.o -lm -msys-lib=m

Where can I open a bug report for NIOS gcc ?

0 Kudos
0 Replies