This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/81788] New: address of a local variable escapes too early


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

            Bug ID: 81788
           Summary: address of a local variable escapes too early
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This is similar to bug 81776.

It seems that the alias analysis considers the address of a local variable to
escape if a call to an unknown function is made after the latter variable has
been declared, that takes the address of another local variable even if the
variable isn't used until after the call.

Clang emits optimal code for both functions below (though other compilers
suffer  the same limitation).

$ cat x.c && gcc -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout x.c
void f (void*);

void g0 (void)
{
  int a = 123;

  f (&a);

  int b = 456;

  if (b != 456)           // can never be true
    __builtin_abort ();   // eliminated

  f (&b);
}

void g1 (void)
{
  int a = 123;
  int b = 456;

  f (&a);

  if (b != 456)           // can never be true
    __builtin_abort ();   // not eliminated

  f (&b);
}

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

g0 ()
{
  int b;
  int a;

  <bb 2> [100.00%] [count: INV]:
  a = 123;
  f (&a);
  b = 456;
  f (&b);
  a ={v} {CLOBBER};
  b ={v} {CLOBBER};
  return;

}



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

g1 ()
{
  int b;
  int a;
  int b.1_1;

  <bb 2> [100.00%] [count: INV]:
  a = 123;
  b = 456;
  f (&a);
  b.1_1 = b;
  if (b.1_1 != 456)
    goto <bb 3>; [0.04%] [count: 0]
  else
    goto <bb 4>; [99.96%] [count: INV]

  <bb 3> [0.04%] [count: 0]:
  __builtin_abort ();

  <bb 4> [99.96%] [count: INV]:
  f (&b);
  a ={v} {CLOBBER};
  b ={v} {CLOBBER};
  return;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]