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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=78412

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
To be clear, a test case that shows the effect of attribute malloc is one where
the variable is extern, like below.  (For the record, I got here by trying to
devise a test case for the attribute and having  trouble with it as noted in
bug 78412).

$ cat x.c && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout x.c
extern int* f0 (void);
extern int* __attribute__ ((malloc)) f1 (void);

extern int x;

void g0 (void)
{
  int *p = &x;
  int *q = f0 ();

  *p = 12;
  *q = 8;

  if (*p != 12)  __builtin_abort ();
}

void g1 (void)
{
  int *p = &x;
  int *q = f1 ();

  *p = 12;
  *q = 8;

  if (*p != 12)  __builtin_abort ();
}


;; Function g0 (g0, funcdef_no=0, decl_uid=1800, cgraph_uid=0, symbol_order=0)

g0 ()
{
  int * q;
  int _1;

  <bb 2>:
  q_4 = f0 ();
  x = 12;
  *q_4 = 8;
  _1 = x;
  if (_1 != 12)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  __builtin_abort ();

  <bb 4>:
  return;

}



;; Function g1 (g1, funcdef_no=1, decl_uid=1805, cgraph_uid=1, symbol_order=1)

g1 ()
{
  <bb 2>:
  f1 ();
  x = 12;
  return;

}

Reply via email to