public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "daniel.klauer at gin dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/95825] [10/11/12/13 Regression] boost::optional -Wuninitialized with -fsanitize=address
Date: Mon, 17 Apr 2023 08:15:44 +0000	[thread overview]
Message-ID: <bug-95825-4-YKyoAksysD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95825-4@http.gcc.gnu.org/bugzilla/>

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

daniel.klauer at gin dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.klauer at gin dot de

--- Comment #7 from daniel.klauer at gin dot de ---
Reduced test case:


template<typename T>
struct tc_optional_base
{
        // default ctor leaves m_storage uninitialized
        tc_optional_base() : m_initialized(false) {}
        bool m_initialized;
        T m_storage;
};

template<typename T>
tc_optional_base<T> f()
{
        return {};
}

tc_optional_base<int> g()
{
        return f<int>();
}


$ g++ -Wall -O1 -fsanitize=address b.cxx -c
In function ‘tc_optional_base<T> f() [with T = int]’,
    inlined from ‘tc_optional_base<int> g()’ at b.cxx:18:15:
b.cxx:13:17: warning: ‘<anonymous>.tc_optional_base<int>::m_storage’ is used
uninitialized [-Wuninitialized]
   13 |         return {};
      |                 ^
b.cxx: In function ‘tc_optional_base<int> g()’:
b.cxx:13:17: note: ‘<anonymous>’ declared here
   13 |         return {};
      |

$ g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0


It looks like the m_storage field really is uninitialized, although I think in
practice boost::optional does not access it in that state in its implementation
thanks to m_initialized. Does gcc warn about the uninitialized data during
copying of the object here? It does seem to be correct...

In the above case with templates it happens at -O1 already, but without
templates it happens too, at -O2.

  parent reply	other threads:[~2023-04-17  8:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 19:31 [Bug c++/95825] New: [7/8/9/10/11 Regression] boost::optional -Wuninitialized nok.raven at gmail dot com
2020-06-23  6:58 ` [Bug c++/95825] [8/9/10/11 " rguenth at gcc dot gnu.org
2020-08-04 16:51 ` [Bug tree-optimization/95825] " mpolacek at gcc dot gnu.org
2020-10-12 12:53 ` rguenth at gcc dot gnu.org
2021-05-14  9:53 ` [Bug tree-optimization/95825] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:17 ` rguenth at gcc dot gnu.org
2022-05-27  9:42 ` [Bug tree-optimization/95825] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:41 ` jakub at gcc dot gnu.org
2022-09-22 13:13 ` [Bug tree-optimization/95825] [10/11/12/13 Regression] boost::optional -Wuninitialized with -fsanitize=address rguenth at gcc dot gnu.org
2023-04-17  8:15 ` daniel.klauer at gin dot de [this message]
2023-04-17  8:22 ` daniel.kruegler at googlemail dot com
2023-04-17  8:46 ` daniel.klauer at gin dot de
2023-07-07 10:37 ` [Bug tree-optimization/95825] [11/12/13/14 " 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-95825-4-YKyoAksysD@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).