From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 20CD13858022; Sun, 8 Aug 2021 07:29:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20CD13858022 From: "mohan.rajanna at ict dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101817] New: g++ apply optimization irrespective of -O0 flag is set Date: Sun, 08 Aug 2021 07:29:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mohan.rajanna at ict dot nl X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Aug 2021 07:29:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101817 Bug ID: 101817 Summary: g++ apply optimization irrespective of -O0 flag is set Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mohan.rajanna at ict dot nl Target Milestone: --- Created attachment 51273 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51273&action=3Dedit disassemble log captured during gdb session Hello Team, I observe g++ applies optimization even when -O0 flag is used for compiling. I am performing unit testing with CMocka setup. Due to optimization, I am unable to test stub function call to strncmp(). Please Note: Stub function call to strncmp() will work in some cases but mo= st of the time, function calls are optimized. I am performing debug build, cmake build log with verbose argument says sou= rce file is compiled with below example. I believe in this case -O0 is applied = by default. Example: std=3Dc++14 -g -o test.c.o -c test.c Just for Information: I manually applied -O0 in CMakeLists.txt with this line=20 set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") and below was the cmake verbose log. std=3Dc++14 -g -O0 -o test.c.o -c test.c Please find the attachment to see disassemble log captured during gdb sessi= on.=20 Please find below the versions used for g++, cmake, ubuntu: g++ --version g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 cmake --version cmake version 3.16.3 Ubuntu 20.04.2 LTS This is inconsistent behaviour with -O0 flag. Sometimes this flag disables = the optimization but not always. Kind Regards Mohan=