This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Silently checking whether diagnostics would occur
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Silently checking whether diagnostics would occur
- From: Michael Meissner <meissner at cygnus dot com>
- Date: Wed, 13 Sep 2000 16:51:05 -0400
- Cc: gdr at codesourcery dot com, gcc at gcc dot gnu dot org
- References: <200009131550.LAA13911@caip.rutgers.edu>
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.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work: meissner@redhat.com phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org fax: +1 978-692-4482