public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mohan.rajanna at ict dot nl" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-101817-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            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=51273&action=edit
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 most
of the time, function calls are optimized.

I am performing debug build, cmake build log with verbose argument says source
file is compiled with below example. I believe in this case -O0 is applied by
default.
Example:
std=c++14 -g   -o test.c.o -c test.c

Just for Information:
I manually applied -O0 in CMakeLists.txt with this line 
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") and below was the cmake verbose log.
std=c++14 -g -O0   -o test.c.o -c test.c

Please find the attachment to see disassemble log captured during gdb session. 

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

             reply	other threads:[~2021-08-08  7:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08  7:29 mohan.rajanna at ict dot nl [this message]
2021-08-08  7:37 ` [Bug c++/101817] " pinskia at gcc dot gnu.org
2021-08-08  7:43 ` mohan.rajanna at ict dot nl
2021-08-13 19:38 ` pinskia at gcc dot gnu.org
2021-08-16  6:22 ` mohan.rajanna at ict dot nl
2021-08-16 10:01 ` redi 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-101817-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: link
Be 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).