From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 922083857822; Mon, 10 Oct 2022 19:38:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 922083857822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665430725; bh=beD2IYiEBOaCFrycr4+jmOL3H1F7oLIZyExqht40wN8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VC6Vg2OmDT65g2YVI08OOI/53JkgrH1OI3k2VKcjMnmLdzdGj6h/vOk9863ALPEL9 65j+QESLuogx11qPagqtj4vOyOJW7h2M1v0zEKk+fV5K/tH42UtVEFe+7g4QLk5ybL 2Ppe336QkxcdX+aqDCOa5eWxvlnsRUXIUMszpCzE= From: "remi.galanalfonso at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107200] False positive -Wdangling-pointer? Date: Mon, 10 Oct 2022 19:38:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: remi.galanalfonso at gmail dot com X-Bugzilla-Status: WAITING 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: cc Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107200 R=C3=A9mi Galan Alfonso changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |remi.galanalfonso at gmail= dot com --- Comment #3 from R=C3=A9mi Galan Alfonso --- 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 y= our godbolt by adding e.g. "static_assert(std::is_same::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 e= nd of the line, before the "x(0)" and "x(1)". And that would explain why you d= on'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 tempor= ary still exists. Moreover, if you enable "Execute the code" on godbolt and add the option "-fsanitize=3Daddress", 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 ;).=