public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "remi.galanalfonso at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107200] False positive -Wdangling-pointer?
Date: Mon, 10 Oct 2022 19:38:44 +0000	[thread overview]
Message-ID: <bug-107200-4-Q5mZkDPCRR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107200-4@http.gcc.gnu.org/bugzilla/>

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

Rémi Galan Alfonso <remi.galanalfonso at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |remi.galanalfonso at gmail dot com

--- Comment #3 from Rémi Galan Alfonso <remi.galanalfonso at gmail dot com> ---
Hello,

If I remember correctly, Eigen uses expression templates (and the names in the
inline stack make it look like it).
In that case your auto would not be Eigen::Vector2d (which you can see in your
godbolt by adding e.g. "static_assert(std::is_same<decltype(x),
Eigen::Vector2d>::value, "Not Eigen::Vector2d.");"), it would be a type that
represents the expression "0.5 * Eigen::Vector2d{1.0, 2.0}", which probably
contains a reference to the temporary Vector2d, which is destroyed at the end
of the line, before the "x(0)" and "x(1)". And that would explain why you don't
see the problem when you replace the auto with "Eigen::Vector2d", as in that
case that causes the evaluation of the expression template while the temporary
still exists.

Moreover, if you enable "Execute the code" on godbolt and add the option
"-fsanitize=address", it trigger the address sanitizer with auto and not
Vector2d, with "ERROR: AddressSanitizer: stack-use-after-scope".
(And bonus: when running the code without sanitizer in O3, what is printed is
not the "expected" result, for example I get "0, 1.03725e-317" on godbolt, GCC
optimized assuming the code doesn't use the dangling values)

So I think the warning is correct, but you probably want to wait for
confirmation from a GCC developer ;).

  parent reply	other threads:[~2022-10-10 19:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10 13:33 [Bug c++/107200] New: " carlosgalvezp at gmail dot com
2022-10-10 15:20 ` [Bug c++/107200] " pinskia at gcc dot gnu.org
2022-10-10 19:10 ` [Bug tree-optimization/107200] " carlosgalvezp at gmail dot com
2022-10-10 19:38 ` remi.galanalfonso at gmail dot com [this message]
2022-10-11  6:07 ` carlosgalvezp at gmail dot com

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-107200-4-Q5mZkDPCRR@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).