This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC]: designing customizable format attributes
- From: "Kaveh R. Ghazi" <ghazi at caipclassic dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: joseph at codesourcery dot com
- Date: Fri, 8 Jul 2005 22:16:58 -0400 (EDT)
- Subject: [RFC]: designing customizable format attributes
We now have six custom format attributes inside GCC to support
verifying various different output function styles. People seem to
like defining non-standard printf formats. Our current solution of
defining internal format attribute styles only works for GCC source,
not the rest of the world. Plus it's brittle. It requires specific
versions of GCC to match the source code, so if you update the format
specifiers you have to update the compiler and bump which version of
GCC can do the checking.
I think it's agreed that being able to specify the format attribute's
properties in the source code rather than hardcoding it into the
compiler is better. :-) So I'd like to take a stab at doing this. If
we can come up with a good design, implementing it shouldn't be too
hard.
I start with the assumption that we'll decide to preserve GCC's
current internal data structures for defining each format attribute.
So we need a way to specify the values for additional entries on the
fly. I'm thinking that we could use a #pragma like so:
#pragma GCC format_attribute __foo__ "string1" "string2" "..."
In this example __foo__ would be the name of the format attribute.
The strings following it would contain parsable data specifying the
contents of the format_* data structures from c-format.h.
When GCC sees the #pragma, it could slurp the info from the strings,
malloc the data structures and populate them appropriately. Then it
would enlarge the relevant arrays and put the new data in the right
place.
Some issues:
1. Obviously, the grammer for the strings in the pragma would have to
be specified and documented. I haven't gotten that far yet. :-)
2. If any format specifiers take user-defined types (like a tree) the
pragma would have to appear after the typedef. We could simply
decree that as a requirement.
3. Does #pragma work in .i files? (I forget). I'm thinking about
what happens if we use --save-temps. We have to put the #pragma
directive into the .i file and cc1 would have to know what to do
with it. Hopefully this "just works".
4. The current code has an enum format_type, I'm not sure but I
suspect the current code might hork if we add more on the fly. (?)
(More investigation needed.)
5. I'd also like to be able to find a shorthand way of saying, "give
me all of printf-style, plus these few extra things", or maybe
"minus these few things". Can't think of a good way to define it.
Thoughts?
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu