[Bug objc++/99056] New: NIOS GCC optimizaton issue with memset

lpacheco at ael dot com.br gcc-bugzilla@gcc.gnu.org
Wed Feb 10 12:24:38 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99056

            Bug ID: 99056
           Summary: NIOS GCC optimizaton issue with memset
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lpacheco at ael dot com.br
  Target Milestone: ---

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' - 'mov
r2,zero').

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

$ nios2-elf-g++ --version
nios2-elf-g++.exe (Altera 17.1 Build 590) 5.3.0
Copyright (C) 2015 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.


More information about the Gcc-bugs mailing list