This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fix handling of '#pragma pack(pop [, id])'


On Fri, Sep 29, 2000 at 11:00:38PM -0500, Mike Coleman wrote:
> This patch fixes a problem with '#pragma pack(pop [, id])', which is a MSVC
> compatibility feature AFAIK.  The current parser insists on the same form for
> 'push' and 'pop' both
> 
>     #pragma pack(push [, id], <n>)
>     #pragma pack(pop [, id], <n>)
> 
> but the 'pop' form shouldn't require (or allow, I think) the numeric
> parameter.  It should parse this
> 
>     #pragma pack(pop [, id])
> 
> instead.  This patch fixes the problem, and gives slightly clearer error
> messages.

...
> +       const char *badmsg;
>         if (!strcmp (op, "push"))
> ! 	{
> ! 	  action = push;
> ! 	  badmsg = "malformed '#pragma pack(push[, id], <n>)' - ignored";
> ! 	}
>         else if (!strcmp (op, "pop"))
> ! 	{
> ! 	  action = pop;
> ! 	  badmsg = "malformed '#pragma pack(pop[, id])' - ignored";
> ! 	}
>         else
>   	BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
>   
>         if (c_lex (&x) != CPP_COMMA)
> ! 	BAD (badmsg);

You must not use a variable to hold an error message, or message
translation will break.  You have to do it like this:

   if (c_lex (&x) != CPP_COMMA)
     {
       if (action == push)
	 BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored");
       else
	 BAD ("malformed '#pragma pack(pop[, id])' - ignored");
     }

> !   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);
> !       }

Better you should set align to zero at the beginning of the function
and leave the switch alone.

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]