fix handling of '#pragma pack(pop [, id])'
Mike Coleman
mcoleman2@kc.rr.com
Fri Oct 13 03:28:00 GMT 2000
"Zack Weinberg" <zackw@Stanford.EDU> writes:
> On Sat, Sep 30, 2000 at 12:06:50AM -0500, Mike Coleman wrote:
> > "Zack Weinberg" <zackw@stanford.edu> writes:
> > > You must not use a variable to hold an error message, or message
> > > translation will break. You have to do it like this:
> >
> > Ok, I didn't know about this.
> >
> > > Better you should set align to zero at the beginning of the function
> > > and leave the switch alone.
> >
> > That would also work. I put the 'action != pop' check in to make it clearer
> > to the reader that the switch didn't apply in the 'pop' case. Personal
> > taste--your way is fine with me.
>
> Your way is fine with me, too.
>
> > Do I need to submit a revised patch?
>
> Please. And maybe some test cases?
Okay, here's another try. I wrote a macro to avoid repeating the same verbose
if-else error statement, but it's still kind of ugly.
As for test cases, not unless someone can point me to a good test case to ape.
I wandered around in the test tree for a while and realized there's too much
stuff there for me to try to comprehend right now (time is short).
--Mike
2000-09-29 Mike Coleman <mkc@users.sourceforge.net>
* c-pragma.c (handle_pragma_pack): fixed handling of '#pragma
pack(pop [, id])' and improved error messages.
Index: gcc/c-pragma.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-pragma.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 c-pragma.c
*** c-pragma.c 2000/09/11 04:29:58 1.37
--- c-pragma.c 2000/10/13 10:17:51
*************** handle_pragma_pack (dummy)
*** 186,192 ****
cpp_reader *dummy ATTRIBUTE_UNUSED;
{
tree x, id = 0;
! int align;
enum cpp_ttype token;
enum { set, push, pop } action;
--- 186,192 ----
cpp_reader *dummy ATTRIBUTE_UNUSED;
{
tree x, id = 0;
! int align = -1;
enum cpp_ttype token;
enum { set, push, pop } action;
*************** handle_pragma_pack (dummy)
*** 208,213 ****
--- 208,219 ----
}
else if (token == CPP_NAME)
{
+ #define BAD_ACTION do { if (action == push) \
+ BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored"); \
+ else \
+ BAD ("malformed '#pragma pack(pop[, id])' - ignored"); \
+ } while (0)
+
const char *op = IDENTIFIER_POINTER (x);
if (!strcmp (op, "push"))
action = push;
*************** handle_pragma_pack (dummy)
*** 217,240 ****
BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
if (c_lex (&x) != CPP_COMMA)
! BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored", op);
token = c_lex (&x);
if (token == CPP_NAME)
{
id = x;
! if (c_lex (&x) != CPP_COMMA)
! BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored", op);
token = c_lex (&x);
}
-
- if (token == CPP_NUMBER)
- align = TREE_INT_CST_LOW (x);
- else
- BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored", op);
! if (c_lex (&x) != CPP_CLOSE_PAREN)
! BAD ("malformed '#pragma pack' - ignored");
}
else
BAD ("malformed '#pragma pack' - ignored");
--- 223,251 ----
BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
if (c_lex (&x) != CPP_COMMA)
! BAD_ACTION;
token = c_lex (&x);
if (token == CPP_NAME)
{
id = x;
! if (action == push && c_lex (&x) != CPP_COMMA)
! BAD_ACTION;
token = c_lex (&x);
}
! if (action == push)
! if (token == CPP_NUMBER)
! {
! align = TREE_INT_CST_LOW (x);
! token = c_lex (&x);
! }
! else
! BAD_ACTION;
!
! if (token != CPP_CLOSE_PAREN)
! BAD_ACTION;
! #undef BAD_ACTION
}
else
BAD ("malformed '#pragma pack' - ignored");
*************** handle_pragma_pack (dummy)
*** 242,260 ****
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma pack'");
! switch (align)
! {
! case 0:
! case 1:
! case 2:
! case 4:
! case 8:
! case 16:
! align *= BITS_PER_UNIT;
! break;
! default:
! BAD2 ("alignment must be a small power of two, not %d", align);
! }
switch (action)
{
--- 253,272 ----
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma pack'");
! if (action != pop)
! switch (align)
! {
! case 0:
! case 1:
! case 2:
! case 4:
! case 8:
! case 16:
! align *= BITS_PER_UNIT;
! break;
! default:
! BAD2 ("alignment must be a small power of two, not %d", align);
! }
switch (action)
{
--
[O]ne of the features of the Internet [...] is that small groups of people can
greatly disturb large organizations. --Charles C. Mann
More information about the Gcc-patches
mailing list