Message ID | 4FC3349E.2050803@st.com |
---|---|
State | New |
Headers | show |
On Mon, 28 May 2012, Christian Bruel wrote: > I shared the same concern, however, after playing bits with spec toys, I > couldn't a find a way to get a %< switch recognition failure, since the > switches passed on the command line at this point are already validated > if necessary. Suppose with the existing sources an option (in a .opt file) is matched by a $< spec, and not by any other spec. Will it be rejected by the driver? It shouldn't be. Are you saying there is some pre-existing bug here, or that %< validation happens in more than one place so some setting of "validated" is redundant but the code still works correctly?
On 05/28/2012 01:11 PM, Joseph S. Myers wrote: > On Mon, 28 May 2012, Christian Bruel wrote: > >> I shared the same concern, however, after playing bits with spec toys, I >> couldn't a find a way to get a %< switch recognition failure, since the >> switches passed on the command line at this point are already validated >> if necessary. > > Suppose with the existing sources an option (in a .opt file) is matched by > a $< spec, and not by any other spec. Will it be rejected by the driver? > It shouldn't be. indeed, it's not rejected if it is present in a .opt file. I was concerned that it will not be rejected even if not in any .opt (or now in --specs). Which was what the validated setting seemed to imply. Should it be rejected ? probably. But this is not implied by the --spec changes. Are you saying there is some pre-existing bug here, or > that %< validation happens in more than one place so some setting of > "validated" is redundant but the code still works correctly? > I think the check if (! switches[i].validated) error is already done when we process the do_spec for user specs. It seems that there is no need to check for user option and set 'validated' in the cases '>:,'<', in do_spec_1 because if the switch was not valid (not present in any .opt and not present in a user --spec) it would already have been rejected. Thanks Christian
On Mon, 28 May 2012, Christian Bruel wrote: > > > On 05/28/2012 01:11 PM, Joseph S. Myers wrote: > > On Mon, 28 May 2012, Christian Bruel wrote: > > > >> I shared the same concern, however, after playing bits with spec toys, I > >> couldn't a find a way to get a %< switch recognition failure, since the > >> switches passed on the command line at this point are already validated > >> if necessary. > > > > Suppose with the existing sources an option (in a .opt file) is matched by > > a $< spec, and not by any other spec. Will it be rejected by the driver? > > It shouldn't be. > > indeed, it's not rejected if it is present in a .opt file. I was > concerned that it will not be rejected even if not in any .opt (or now > in --specs). Which was what the validated setting seemed to imply. > > Should it be rejected ? probably. But this is not implied by the --spec > changes. The existing rule is supposed to be: options are only accepted if in *both* a .opt file *and* a spec. If not in a .opt file, the common machinery will reject them; if in a .opt file but not a spec, the driver's own validation machinery will reject them. If the driver's own validation machinery isn't rejecting them, that indicates that some spec has handled them. It's possible there's more than one piece of code relating to accepting such options and some such code is redundant. (This can't be tested with options starting -f or -m because of the specs passing all such options to cc1.) The new semantics are supposed to be, I think: an option in a .opt file is accepted if any spec matches it (same as now), an option not in a .opt file is only accepted if a user spec matches it and not simply because of a match from a built-in spec (where built-in specs are considered to include those generated by some of GCC's own runtime libraries).
On 05/28/2012 06:27 PM, Joseph S. Myers wrote: > On Mon, 28 May 2012, Christian Bruel wrote: > >> >> >> On 05/28/2012 01:11 PM, Joseph S. Myers wrote: >>> On Mon, 28 May 2012, Christian Bruel wrote: >>> >>>> I shared the same concern, however, after playing bits with spec toys, I >>>> couldn't a find a way to get a %< switch recognition failure, since the >>>> switches passed on the command line at this point are already validated >>>> if necessary. >>> >>> Suppose with the existing sources an option (in a .opt file) is matched by >>> a $< spec, and not by any other spec. Will it be rejected by the driver? >>> It shouldn't be. >> >> indeed, it's not rejected if it is present in a .opt file. I was >> concerned that it will not be rejected even if not in any .opt (or now >> in --specs). Which was what the validated setting seemed to imply. >> >> Should it be rejected ? probably. But this is not implied by the --spec >> changes. > > The existing rule is supposed to be: options are only accepted if in > *both* a .opt file *and* a spec. If not in a .opt file, the common > machinery will reject them; if in a .opt file but not a spec, the driver's > own validation machinery will reject them. Thanks for confirming this, the question was more specifically for <%options. Today, with the current implementation, I see two uses cases: 1) The flag appears in a %< spec but is not in a .opt file -> It is *not* rejected. It is just ignored. 2) The flag appears in a user switch and in a %< spec, and not in a .opt file. -> It is rejected. To refocus on the original question from the patch. I'm still not convinced after our discussions and testings that the propagation of the user flag to the do_spec functions is required to keep the same semantic. If there is an issue with the current %< handling, could we handle this separately ? my primary focus was in matching --spec user options behavior with the .opt internal ones. > > If the driver's own validation machinery isn't rejecting them, that > indicates that some spec has handled them. It's possible there's more > than one piece of code relating to accepting such options and some such > code is redundant. > > (This can't be tested with options starting -f or -m because of the specs > passing all such options to cc1.) > > The new semantics are supposed to be, I think: an option in a .opt file is > accepted if any spec matches it (same as now), an option not in a .opt > file is only accepted if a user spec matches it and not simply because of > a match from a built-in spec (where built-in specs are considered to > include those generated by some of GCC's own runtime libraries). I agree. I believe my patch implements this, my focus was on not changing the current behavior for switches internally defined in a .opt (or now in a --spec file). error are still generated for other cases. Many thanks Christian
On Tue, 29 May 2012, Christian Bruel wrote: > > The existing rule is supposed to be: options are only accepted if in > > *both* a .opt file *and* a spec. If not in a .opt file, the common > > machinery will reject them; if in a .opt file but not a spec, the driver's > > own validation machinery will reject them. > > Thanks for confirming this, the question was more specifically for > <%options. Today, with the current implementation, I see two uses cases: > > 1) The flag appears in a %< spec but is not in a .opt file > -> It is *not* rejected. It is just ignored. I don't really see that as a use case; it's more a matter of an internal consistency check that could be done but isn't. I'm only concerned about cases where the option is actually passed on the command line to the driver. > 2) The flag appears in a user switch and in a %< spec, and not in a .opt > file. > -> It is rejected. There are also cases: * The option, passed by the user, is in a .opt file, a %< spec but no other spec. (Should be accepted.) * The option, passed by the user, is in a .opt file and no spec at all. (Should be rejected.) > To refocus on the original question from the patch. I'm still not > convinced after our discussions and testings that the propagation of the > user flag to the do_spec functions is required to keep the same semantic. With the proposed change to the rules for when a spec serves to validate an option, all settings of the "validated" field need to be reviewed to make sure that they are in accordance with the new rules - and that it is transparent to human readers of the code that they are in accordance with the new rules. If you don't think propagation is needed to do_spec functions, then it should be possible to remove the "validated" setting in there, with a proper explanation of the order in which the various relevant functions are called and where "validated" will previously or subsequently be set.
On 05/29/2012 12:50 PM, Joseph S. Myers wrote: > On Tue, 29 May 2012, Christian Bruel wrote: > >>> The existing rule is supposed to be: options are only accepted if in >>> *both* a .opt file *and* a spec. If not in a .opt file, the common >>> machinery will reject them; if in a .opt file but not a spec, the driver's >>> own validation machinery will reject them. >> >> Thanks for confirming this, the question was more specifically for >> <%options. Today, with the current implementation, I see two uses cases: >> >> 1) The flag appears in a %< spec but is not in a .opt file >> -> It is *not* rejected. It is just ignored. > > I don't really see that as a use case; it's more a matter of an internal > consistency check that could be done but isn't. I'm only concerned about > cases where the option is actually passed on the command line to the > driver. > >> 2) The flag appears in a user switch and in a %< spec, and not in a .opt >> file. >> -> It is rejected. > > There are also cases: > > * The option, passed by the user, is in a .opt file, a %< spec but no > other spec. (Should be accepted.) yes, it is. > > * The option, passed by the user, is in a .opt file and no spec at all. > (Should be rejected.) yes, it is. > >> To refocus on the original question from the patch. I'm still not >> convinced after our discussions and testings that the propagation of the >> user flag to the do_spec functions is required to keep the same semantic. > > With the proposed change to the rules for when a spec serves to validate > an option, all settings of the "validated" field need to be reviewed to > make sure that they are in accordance with the new rules - and that it is > transparent to human readers of the code that they are in accordance with > the new rules. If you don't think propagation is needed to do_spec > functions, then it should be possible to remove the "validated" setting in > there, with a proper explanation of the order in which the various > relevant functions are called and where "validated" will previously or > subsequently be set. > I agree. I see two potential settings of the validated field. The %< that we just reviewed, and the case : /* We have Xno-YYY, search for XYYY. */ It seems possible to remove those, I've just checked this during lunch :-) with the scenarios described above (without use m* f* specs). If it is a prerequisite before my --spec patch, I'd like to propose it as an independent one, since this is a valid modification regardless of the --spec implementation (although it makes it clearer). Many thanks Christian
On Tue, 29 May 2012, Christian Bruel wrote: > I agree. I see two potential settings of the validated field. The %< > that we just reviewed, and the case : /* We have Xno-YYY, search for > XYYY. */ > > It seems possible to remove those, I've just checked this during lunch > :-) with the scenarios described above (without use m* f* specs). > > If it is a prerequisite before my --spec patch, I'd like to propose it > as an independent one, since this is a valid modification regardless of > the --spec implementation (although it makes it clearer). Please do send such a patch (with an explanation in each case of how "validated" still gets set with that redundant setting removed).
Index: gcc/testsuite/gcc.dg/spec-options.c =================================================================== --- gcc/testsuite/gcc.dg/spec-options.c (revision 0) +++ gcc/testsuite/gcc.dg/spec-options.c (revision 0) @@ -0,0 +1,16 @@ +/* Check that -mfoo is accepted if defined in a user spec + and that it is not passed on the command line. */ +/* { dg-do compile } */ +/* { dg-do run { target sh*-*-* } } */ +/* { dg-options "-B${srcdir}/gcc.dg --specs=foo.specs -mfoo" } */ + +extern void abort(void); + +int main(void) +{ +#ifdef FOO + return 0; +#else + abort(); +#endif +} Index: gcc/testsuite/gcc.dg/spec-options-2.c =================================================================== --- gcc/testsuite/gcc.dg/spec-options-2.c (revision 0) +++ gcc/testsuite/gcc.dg/spec-options-2.c (revision 0) @@ -0,0 +1,15 @@ +/* Check that -tfoo is accepted if defined in a user spec. */ +/* { dg-do compile } */ +/* { dg-do run { target sh*-*-* } } */ +/* { dg-options "-B${srcdir}/gcc.dg --specs=foo.specs -tfoo" } */ + +extern void abort(void); + +int main(void) +{ +#ifdef FOO + return 0; +#else + abort(); +#endif +} Index: gcc/testsuite/gcc.dg/foo.specs =================================================================== --- gcc/testsuite/gcc.dg/foo.specs (revision 0) +++ gcc/testsuite/gcc.dg/foo.specs (revision 0) @@ -0,0 +1,3 @@ +*cc1runtime: ++ %{mfoo|tfoo: -DFOO} %<mfoo +