Take:
static inline int *fromSlotB(void)
{
  static int shuf_BZZZ = 1;
  return &shuf_BZZZ;
}

int main(void)
{
  return (int)fromSlotB();
}

--- CUT ---
At -O2, fromSlotB is still being emitted even though it is unused.
It is being marked in cxx_callgraph_analyze_expr:
      else if (DECL_CONTEXT (t)
               && TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL)
        /* If we need a static variable in a function, then we
           need the containing function.  */
        mark_decl_referenced (DECL_CONTEXT (t));

For -frepo this might be true but I don't think this is true in general.
This regression was introduced to do unit-at-a-time always for C++:
http://gcc.gnu.org/ml/gcc-patches/2004-07/msg02615.html


-- 
           Summary: [4.2/4.3/4.4 Regression] C++ front-end causing a static
                    inline function to be emitted
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36959

Reply via email to