public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset
@ 2021-02-10 12:24 lpacheco at ael dot com.br
  2021-02-10 12:32 ` [Bug objc++/99056] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lpacheco at ael dot com.br @ 2021-02-10 12:24 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug objc++/99056] NIOS GCC optimizaton issue with memset
  2021-02-10 12:24 [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset lpacheco at ael dot com.br
@ 2021-02-10 12:32 ` rguenth at gcc dot gnu.org
  2021-02-10 12:42 ` lpacheco at ael dot com.br
  2021-02-15  7:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-10 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
             Target|                            |nios2
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-02-10

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note GCC 5 is no longer maintained, you should go and report the issue to
Altera who provided the compiler.

When I use current trunk and a simple cc1 cross to nios2-elf I get with -O2

ServiceCallingMemset:
        addi    sp, sp, -8
        mov     r6, r5
        mov     r5, r4
        addi    r4, sp, 3
        stw     ra, 4(sp)
        stb     zero, 3(sp)
        call    memset
        ldbu    r2, 3(sp)
        cmpeqi  r2, r2, 1
        ldw     ra, 4(sp)
        addi    sp, sp, 8
        ret

which I'd say shows the issue is fixed?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug objc++/99056] NIOS GCC optimizaton issue with memset
  2021-02-10 12:24 [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset lpacheco at ael dot com.br
  2021-02-10 12:32 ` [Bug objc++/99056] " rguenth at gcc dot gnu.org
@ 2021-02-10 12:42 ` lpacheco at ael dot com.br
  2021-02-15  7:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: lpacheco at ael dot com.br @ 2021-02-10 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Leonardo Pacheco <lpacheco at ael dot com.br> ---
Yes, your result shows that the issue is already fixed.

Thanks, will try to open bug report to Altera.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug objc++/99056] NIOS GCC optimizaton issue with memset
  2021-02-10 12:24 [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset lpacheco at ael dot com.br
  2021-02-10 12:32 ` [Bug objc++/99056] " rguenth at gcc dot gnu.org
  2021-02-10 12:42 ` lpacheco at ael dot com.br
@ 2021-02-15  7:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-15  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|WAITING                     |RESOLVED

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-15  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 12:24 [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset lpacheco at ael dot com.br
2021-02-10 12:32 ` [Bug objc++/99056] " rguenth at gcc dot gnu.org
2021-02-10 12:42 ` lpacheco at ael dot com.br
2021-02-15  7:46 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).