public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lpacheco at ael dot com.br" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug objc++/99056] New: NIOS GCC optimizaton issue with memset Date: Wed, 10 Feb 2021 12:24:38 +0000 [thread overview] Message-ID: <bug-99056-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2021-02-10 12:24 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-10 12:24 lpacheco at ael dot com.br [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99056-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).