Mudflap is not registering global variable definitions that are not referenced
within the source file that they are defined in.  Compile a C file
with the single line "short globalvar;" in it with gcc -c -fmudflap.
Note that there are no calls to __mf_register emitted.

The culprit seems to be this code in tree-mudflap.c, function
mudflap_finish_file():

   /* Omit registration for static unaddressed objects.  NB:
      Perform registration for non-static objects regardless of
      TREE_USED or TREE_ADDRESSABLE, because they may be used
      from other compilation units.  */
   if (TREE_STATIC (obj) && ! TREE_ADDRESSABLE (obj))
     continue;

The continue is being taken, which must mean that TREE_STATIC
doesn't mean what this code thinks it means.  I think it means static
storage class, not, as this code assumes, file scope.

On a related note, mudflap will register a variable when it sees
an extern in another compilation unit (if it knows the size),
but I don't think it should trust externs, since one of the
classes of bugs that it could be catching is declarations that
don't match the definitions. There needs to be a way to make the
actual definitions take precedence.

Note: I have no idea what to use for "Component" here.


-- 
           Summary: Mudflap not registering unreferenced globals
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dgraham at nortel dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to