This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: new #pragma pack failure
- To: Robert Lipe <robertl at sco dot com>
- Subject: Re: new #pragma pack failure
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 9 Sep 2000 13:50:22 -0700
- Cc: gcc-bugs at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- References: <20000909142140.Q4191@rjlhome.sco.com>
On Sat, Sep 09, 2000 at 02:21:40PM -0500, Robert Lipe wrote:
> I'm not certain that this was introduced with Zack's patch
...
> but there's been a recent regression with HANDLE_SYSV_PRAGMA code. This
> following code isn't malformed; this construct returns the packing to the
> default. But GCC now complains about it.
>
> $ cat /tmp/p.c
> #pragma pack()
> (robertl) rjlhome:/play/negcs/gcc/stage1
> $ ./xgcc -c -B./ /tmp/p.c
> /tmp/p.c:1: warning: malformed '#pragma pack' - ignored
It wasn't introduced by that patch, but it is my fault. :) The
big integrated preprocessor patch that went in a couple of days ago
contains, among other things, a total rewrite of the #pragma parser.
And I got this case wrong.
This patch fixes the problem for me; I'm bootstrapping now. Since
you're up on these things, could you write up some tests for #pragma
pack?
zw
* c-pragma.c (handle_pragma_pack): Correct parsing logic so it
won't give a spurious error for '#pragma pack()'. Simplify
control flow for readability. 'reset' action is not necessary.
===================================================================
Index: c-pragma.c
--- c-pragma.c 2000/09/08 22:17:24 1.36
+++ c-pragma.c 2000/09/09 20:47:34
@@ -188,59 +188,57 @@ handle_pragma_pack (dummy)
tree x, id = 0;
int align;
enum cpp_ttype token;
- enum { set, reset, push, pop } action;
+ enum { set, push, pop } action;
if (c_lex (&x) != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma pack' - ignored");
token = c_lex (&x);
if (token == CPP_CLOSE_PAREN)
- action = reset;
+ {
+ action = set;
+ align = 0;
+ }
else if (token == CPP_NUMBER)
{
align = TREE_INT_CST_LOW (x);
action = set;
+ if (c_lex (&x) != CPP_CLOSE_PAREN)
+ BAD ("malformed '#pragma pack' - ignored");
}
else if (token == CPP_NAME)
{
- if (!strcmp (IDENTIFIER_POINTER (x), "push"))
+ const char *op = IDENTIFIER_POINTER (x);
+ if (!strcmp (op, "push"))
action = push;
- else if (!strcmp (IDENTIFIER_POINTER (x), "pop"))
+ else if (!strcmp (op, "pop"))
action = pop;
else
- BAD2 ("unknown action '%s' for '#pragma pack' - ignored",
- IDENTIFIER_POINTER (x));
- }
- else
- BAD ("malformed '#pragma pack' - ignored");
+ BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
- token = c_lex (&x);
- if ((action == set || action == reset) && token != CPP_CLOSE_PAREN)
- BAD ("malformed '#pragma pack' - ignored");
- if ((action == push || action == pop) && token != CPP_COMMA)
- BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored",
- action == push ? "push" : "pop");
+ if (c_lex (&x) != CPP_COMMA)
+ BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored", op);
- if (action == push || action == pop)
- {
token = c_lex (&x);
if (token == CPP_NAME)
{
id = x;
if (c_lex (&x) != CPP_COMMA)
- BAD2 ("malformed '#pragma pack(%s[, id], <n>)' - ignored",
- action == push ? "push" : "pop");
+ 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",
- action == push ? "push" : "pop");
+ 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");
+
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma pack'");
@@ -261,7 +259,6 @@ handle_pragma_pack (dummy)
switch (action)
{
case set: SET_GLOBAL_ALIGNMENT (align); break;
- case reset: SET_GLOBAL_ALIGNMENT (0); break;
case push: push_alignment (align, id); break;
case pop: pop_alignment (id); break;
}