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]

Silently checking whether diagnostics would occur

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

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;
 >     }

This would fool gcc into keeping quiet about the warnings while still
letting me know whether some kind of diagnostic would have issued.
Note the current controls like inhibit_warnings don't seem to do what
quite I want.  It would silence the warnings without me being able to
tell that a warning would have occured.  I also don't want to worry
about side effects modifying gcc's internal state, e.g. errorcount, or
whether the user specified -Werror.  My approach seems to solve all of
these issues.

First of all, I wanted to know if there was already something in there
that I missed which allows me to do this.  Second, if nothing exists
is this approach something you feel would be acceptable into
diagnostic.c?  I'll provide a patch if you react positively.

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]