MaskRay wrote:

> > > I don't really understand the rationale for this, and it's kind of 
> > > annoying. Most of the compiler's flags behave in the "last one wins" 
> > > fashion (such as `-O2` and `-O0`) and it's always been convenient to add 
> > > the flag you want at the end. Why treat action flags any differently? 
> > > Also, even if this is worthwhile for some reason I haven't considered, 
> > > why is it an error rather than a warning?
> > 
> > 
> > @bogner Some action options are shared between driver and cc1 but the 
> > behaviors could be quite different. See my example in the description.
> > ```
> > %clang_cc1 -S -emit-llvm a.c     # -S is overridden
> > %clang_cc1 -emit-llvm -S a.c     # -emit-llvm is overridden
> > %clang_cc1 -fsyntax-only -S a.c  # -fsyntax-only is overridden
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > The strictness helps ensure that `%clang_cc1` tests do not have misleading, 
> > overridden action options.
> 
> So the oddity here really is the driver, which translates both `-S 
> -emit-llvm` and `-emit-llvm -S` to `-emit-llvm-bc` in the `-cc1` invocation. 
> Before this change the cc1 invocation treated `-S` and the various 
> `-emit-XYZ` flags consistently with other options like `-O`, `-g`, and most 
> `-f` group flags, letting later ones override earlier.
> 
> I suppose that it's somewhat reasonable to warn users that `-cc1` behaves 
> differently than the driver for certain combinations of `-S` and 
> `-emit-llvm`, and it's probably too impactful of a change to change the 
> driver. Even so, I really think this should just be a warning and not a hard 
> error.

The driver behavior isn't that odd. "Last option wins" applies to `-ffoo 
-fno-foo` but only in a few cases `-ffoo -fbar`.
cc1 reuses the option names but gives them different semantics (last action 
group wins).

Before this patch and the associated cleanups, a lot of tests had more than one 
actions and the authors were unaware the issue, e.g. `-ast-dump -emit-pch` 
(`-ast-dump` is ignored), `-emit-obj -emit-llvm` (`-emit-obj` is ignored). With 
this error behavior, these `%clang_cc1` usage mistakes will be caught. A 
warning would not provide protection...

https://github.com/llvm/llvm-project/pull/91140
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to