public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value
@ 2022-02-07 23:49 msebor at gcc dot gnu.org
  2022-02-07 23:50 ` [Bug middle-end/104436] " msebor at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-07 23:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104436
           Summary: spurious -Wdangling-pointer assigning local address to
                    a class passed by value
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The test case below, reduced from
https://bugzilla.redhat.com/show_bug.cgi?id=2051740, shows that
-Wdangling-pointer can be made to trigger by assigning an object of a C++ class
with a user-defined copy ctor that stores a pointer to a local in a function
that takes an argument of the class by value.  GCC transforms the by-value
argument of the function to a by-reference, which is one of the use cases the
warning is designed to detect.

$ cat rhbz2051740.C && gcc -O1 -S -Wall -fdump-tree-optimized=/dev/stdout
rhbz2051740.C
struct S
{
  S () = default;
  S (const S &s): p (s.p) { }

  void *p;
};

void foo (S s)
{
  int a[3];
  S t; t.p = a;
  s = t;
}
rhbz2051740.C: In function ‘void foo(S)’:
rhbz2051740.C:13:5: warning: storing the address of local variable ‘a’ in
‘*s.S::p’ [-Wdangling-pointer=]
   13 |   s = t;
      |   ~~^~~
rhbz2051740.C:11:7: note: ‘a’ declared here
   11 |   int a[3];
      |       ^
rhbz2051740.C:11:7: note: ‘s’ declared here

;; Function foo (_Z3foo1S, funcdef_no=3, decl_uid=2396, cgraph_uid=4,
symbol_order=3)

void foo (struct S & s)
{
  int a[3];

  <bb 2> [local count: 1073741824]:
  s_2(D)->p = &a;
  a ={v} {CLOBBER};
  return;

}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
@ 2022-02-07 23:50 ` msebor at gcc dot gnu.org
  2022-02-08  0:22 ` msebor at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-07 23:50 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-02-07
                URL|                            |https://bugzilla.redhat.com
                   |                            |/show_bug.cgi?id=2051740
           Keywords|                            |diagnostic
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |104077


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104077
[Bug 104077] bogus/missing -Wdangling-pointer

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
  2022-02-07 23:50 ` [Bug middle-end/104436] " msebor at gcc dot gnu.org
@ 2022-02-08  0:22 ` msebor at gcc dot gnu.org
  2022-02-08  9:08 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-08  0:22 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
It seems that DECL_BY_REFERENCE(fndecl) might be able to tell us if the
argument is a "fake reference" that the by-value argument is substituted for. 
Let me see if that works.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
  2022-02-07 23:50 ` [Bug middle-end/104436] " msebor at gcc dot gnu.org
  2022-02-08  0:22 ` msebor at gcc dot gnu.org
@ 2022-02-08  9:08 ` rguenth at gcc dot gnu.org
  2022-02-08 22:00 ` [Bug middle-end/104436] [12 Regression] " msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-08  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
DECL_BY_REFERENCE on the PARM_DECL tells you that indeed (not on the fndecl).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] [12 Regression] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-02-08  9:08 ` rguenth at gcc dot gnu.org
@ 2022-02-08 22:00 ` msebor at gcc dot gnu.org
  2022-03-09 13:18 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-02-08 22:00 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
            Summary|spurious -Wdangling-pointer |[12 Regression] spurious
                   |assigning local address to  |-Wdangling-pointer
                   |a class passed by value     |assigning local address to
                   |                            |a class passed by value
           Keywords|                            |patch

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590046.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] [12 Regression] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-02-08 22:00 ` [Bug middle-end/104436] [12 Regression] " msebor at gcc dot gnu.org
@ 2022-03-09 13:18 ` rguenth at gcc dot gnu.org
  2022-03-15  0:27 ` cvs-commit at gcc dot gnu.org
  2022-03-15  0:27 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-03-09 13:18 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] [12 Regression] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-03-09 13:18 ` rguenth at gcc dot gnu.org
@ 2022-03-15  0:27 ` cvs-commit at gcc dot gnu.org
  2022-03-15  0:27 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-15  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:373a2dc2be0089ae59b61202a6023458aaaf63d8

commit r12-7650-g373a2dc2be0089ae59b61202a6023458aaaf63d8
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Mar 14 18:23:08 2022 -0600

    Avoid -Wdangling-pointer for by-transparent-reference arguments [PR104436].

    This change avoids -Wdangling-pointer for by-value arguments transformed
    into by-transparent-reference.

    Resolves:
    PR middle-end/104436 - spurious -Wdangling-pointer assigning local address
to a class passed by value

    gcc/ChangeLog:

            PR middle-end/104436
            * gimple-ssa-warn-access.cc (pass_waccess::check_dangling_stores):
            Check for warning suppression.  Avoid by-value arguments
transformed
            into by-transparent-reference.

    gcc/testsuite/ChangeLog:

            PR middle-end/104436
            * c-c++-common/Wdangling-pointer-8.c: New test.
            * g++.dg/warn/Wdangling-pointer-5.C: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/104436] [12 Regression] spurious -Wdangling-pointer assigning local address to a class passed by value
  2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-03-15  0:27 ` cvs-commit at gcc dot gnu.org
@ 2022-03-15  0:27 ` msebor at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-03-15  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in r12-7650.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-03-15  0:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 23:49 [Bug middle-end/104436] New: spurious -Wdangling-pointer assigning local address to a class passed by value msebor at gcc dot gnu.org
2022-02-07 23:50 ` [Bug middle-end/104436] " msebor at gcc dot gnu.org
2022-02-08  0:22 ` msebor at gcc dot gnu.org
2022-02-08  9:08 ` rguenth at gcc dot gnu.org
2022-02-08 22:00 ` [Bug middle-end/104436] [12 Regression] " msebor at gcc dot gnu.org
2022-03-09 13:18 ` rguenth at gcc dot gnu.org
2022-03-15  0:27 ` cvs-commit at gcc dot gnu.org
2022-03-15  0:27 ` msebor at gcc dot gnu.org

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).