This is the mail archive of the 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]

Re: Silently checking whether diagnostics would occur

 > From: Michael Meissner <>
 > On Wed, Sep 13, 2000 at 11:50:02AM -0400, Kaveh R. Ghazi wrote:
 > > Hi Gabriel,
 > > 
 > > While writing a __builtin_printf expander, I found that it would be
 > > useful to be able to call the printf format checking routines silently
 > > from builtins.c to see if the printf call being expanded passed format
 > > checks before I try to optimize it.  (This needs to happen regardless
 > > of, and independent of, whether the user specifies -Wformat.)  The
 > > current format checking routines are setup to emit warnings at random
 > > points, not to return a handy status code.  (See check_format_info in
 > > c-common.c.)
 > > 
 > > So rather than do a complete restructuring of the format checking
 > > function, I though it would be much easier and cleaner to be able to
 > > call the checks conceptually like this:
 > > 
 > >  > check_diagnostics_silently = 1;  /* new global vars */
 > >  > diagnostic_occurred = 0;
 > >  > 
 > >  > <do something which might warn>
 > >  > 
 > >  > if (diagnostic_occurred) <react>
 > >  > check_diagnostics_silently = 0;
 > > 
 > > and modify diagnostic.c:count_error to do this before anything else:
 > > 
 > >  >   if (check_diagnostics_silently)
 > >  >     {
 > >  >       diagnostic_occurred = 1;
 > >  >       return 0;
 > >  >     }
 > I really, really do not like adding global variables for this
 > purpose (yes, I'm probably guily of just such behavior myself).  I
 > would rather the checking be abstracted into a function with an
 > argument that says whether to issue the warning or not, and a
 > return value that indicates whether an error would have occurred.
 > Michael Meissner, Red Hat, Inc.

If you mean rewriting check_format_info, that requires a lot of
obtrusive surgery on the code.  As I mentioned above, that function is
not structured to return a status either as a return-value, or via one
of its parameters were I to add one.  There are about 50 places in
that function which warn about format specifier problems.  I would
have to add bits at each location to mark that a warning occured and
return that bit at all of the 15 spots from which the function can
return.  Anyone writing new format warnings within it would have to
remember to do the same.  Its really hairy.  My alternative is about
five lines of code.

What is the specific problem you wish to avoid that global vars cause?
Is there some other way to design this to meet your goals?  What if
the setting were a static variable in diagnostic.c with functions
exported to set/unset it?

Kaveh R. Ghazi			Engagement Manager / Project Services		Qwest Internet Solutions

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