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]
Other format: [Raw text]

Re: [PATCH] Fix PR c/9262


Eric Botcazou <ebotcazou at libertysurf dot fr> writes:

>> First, please try to change the C parser so that it does not add case
>> labels to the chain of statements if there is no enclosing SWITCH_STMT.
>> This may be impractical.
>
> But there is an enclosing SWITCH_STMT by the time the case label is added to 
> the chain. Otherwise the parse error "not within a switch statement" would 
> trigger and the case label would not be added.

Okay.

> The problem is that the parser chains the case labels to the SWITCH_STMT 
> itself, not to its SWITCH_BODY. And it's up to c-typeck.c:c_finish_case() to 
> rechain them to the latter. Therefore, if the function is not called (as it 
> is the case for this PR), there are never rechained and we end up passing a 
> SWITCH_STMT with an empty SWITCH_BODY to add_case_node(), which doesn't like 
> that at all.
>
> The straightforward solution that consists in rechaining the labels on the 
> first addition seems to work. I just had to modify a few line numbers for 
> -Wswitch warnings in three testcases.

Looks like we're on the right track.  But your patch appears to chain
just the first case label to the SWITCH_BODY; further labels continue
to be chained after the SWITCH_STMT.  Why is this the right thing to
do?  And I don't understand your change to c_finish_case at all.

zw


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