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 middle-end/24786] Missing warning on questionable use of parameter to initialize static


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

Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-11-11 17:59:15         |2015-9-18
                 CC|                            |manu at gcc dot gnu.org
          Component|c++                         |middle-end
            Version|4.1.0                       |6.0

--- Comment #3 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> ---
GCC generates code like this:

const char *names[1];
const char *blah2() {
   char x = 7;
    if (first_time)
       names[0] = { &x }; 
   return names[0];
}

and we end up returning:

  # .MEM_1 = PHI <.MEM_4(2), .MEM_9(4), .MEM_6(3)>
  [test.c:5:17] # VUSE <.MEM_1>
  # PT = nonlocal escaped { D.2254 } (escaped)
  _10 = [test.c:5:17] _ZZ5blah2vE5namesD.2255[0];
  # .MEM_11 = VDEF <.MEM_1>
  xD.2254 ={v} {CLOBBER};
  [test.c:5:17] # VUSE <.MEM_11>
  return _10;
;;    succ:       EXIT [100.0%]

While in the non-static case we propagate &x:

;;   basic block 2, loop depth 0, count 0, freq 10000, maybe hot
;;    prev block 0, next block 1, flags: (NEW, REACHABLE)
;;    pred:       ENTRY [100.0%]  (FALLTHRU,EXECUTABLE)
;;   starting at line 5
  # .MEM_2 = VDEF <.MEM_1(D)>
  xD.2254 ={v} {CLOBBER};
  [test.c:5:17] # VUSE <.MEM_2>
  return &xD.2254;
;;    succ:       EXIT [100.0%]


This seems like a missed optimization.

Somehow related to PR60517.

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