This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Support for %d$c format specifier in diagnostics.c
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: Ishikawa <ishikawa at yk dot rim dot or dot jp>
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>, Zack Weinberg <zack at codesourcery dot com>, Neil Booth <neil at daikokuya dot co dot uk>, gcc-patches at gcc dot gnu dot org
- Date: Mon, 21 Jul 2003 10:38:57 +0100 (BST)
- Subject: Re: Support for %d$c format specifier in diagnostics.c
- References: <m19WKhW-000H3mC@standard.erephon> <20030628193135.GA1767@daikokuya.co.uk> <87llvlk3gi.fsf@egil.codesourcery.com> <3EFE65DC.52576EC7@yk.rim.or.jp> <87vfupiglu.fsf@egil.codesourcery.com> <3EFEE0EF.C560ED1A@yk.rim.or.jp> <87isqoiwng.fsf@egil.codesourcery.com> <3F061172.814BA7A0@yk.rim.or.jp> <Pine.LNX.4.56.0307051127540.6302@kern.srcf.societies.cam.ac.uk> <3F0CA938.1FA02D3E@yk.rim.or.jp> <m3vfuayizy.fsf@uniton.integrable-solutions.net> <3F1A1654.4476090C@yk.rim.or.jp> <Pine.LNX.4.56.0307201539320.2839@kern.srcf.societies.cam.ac.uk> <3F1B275C.515D7FE1@yk.rim.or.jp> <m3d6g4z509.fsf@uniton.integrable-solutions.net><3F1BB1E7.3E46E4DB@yk.rim.or.jp>
On Mon, 21 Jul 2003, Ishikawa wrote:
> (We essentially need the width of the argument to bump the pointer
> for
> variable argument processing is necessary. So all we need is
> the # of bytes for the argument type. The value itself can be opaque,
> and will be stored in an appropriate argumet array cell.)
We need the actual type, not the width. Passing the wrong type to va_arg
will lead to (a) aliasing issues (generating wrong code), (b) problems
with ABIs that handle integer/floating point/pointer arguments differently
in variable arguments (if such ABIs aren't currently in use, someone will
one day invent one), (c) problems when someone implements a safer ABI that
stores information about argument types and actually checks at runtime
that they are correct. So you should always store information about the
actual type (distinguishing "int" and "long" even if the same size, for
example).
For the format decoders, I'd guess that just the character 'D', 'T', etc.,
is sufficient to determine what the type is, and so can be stored as an
opaque identifier itself. So you need (a) a list of valid characters for
the front end (needn't be a function, though using a function would keep
more generality), (b) a function to extract and store the relevant value,
(c) a function to print the saved value. Trying to call va_arg to extract
the value from within diagnostic.c, using some substitute type because
diagnostic.c shouldn't know about "tree" etc., would I think end up being
a mistake.
--
Joseph S. Myers
jsm@polyomino.org.uk