[Bug c/101358] Warn when saving a pointer to an object with temporary lifetime

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jul 7 21:59:40 GMT 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |87403
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-07-07
           Severity|normal                      |enhancement

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed as an enhancement request for the front end.  The Gimplifier
introduces a local variable for the return value so the problem is no longer
detectable:

$ cat pr101358.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -S
-Wall -fdump-tree-original=/dev/stdout -fdump-tree-gimple=/dev/stdout
pr101358.c
typedef struct {
    int x[1];
} foo;

foo f(void);

int g(void) {
    int *p = f().x;
    return *p;
}

;; Function g (null)
;; enabled by -tree-original


{
  int * p = (int *) &f ().x;

    int * p = (int *) &f ().x;
  return *p;
}

int g ()
{
  struct 
{
  int x[1];
} D.1952;
  int D.1953;
  int * p;

  D.1952 = f ();
  p = &D.1952.x;
  D.1953 = *p;
  return D.1953;
}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning


More information about the Gcc-bugs mailing list