[cfe-dev] Quick RFC about some consistency guidelines for the Clang driver

Joerg Sonnenberger joerg at britannica.bec.de
Wed Jun 19 09:08:07 PDT 2013


On Sat, Jun 15, 2013 at 03:21:43AM -0700, Chandler Carruth wrote:
> 1) The goal of Clang's driver is to be drop-in compatible with GCC in many
> (most?) situations. This often trumps all other concerns, so I list it
> first.

I'd put this different: If the interface exposed by GCC is consistent
(with other options and across different versions), we want to stay
compatible with it. If it is not consistent across versions and the
current versions make sense, we want to be compatible with that.

> 2) GCC's commandline syntax establishes some nice consistent naming
> patterns that I think it is worthwhile for Clang to continue following
> where suitable.

I agree for the -W (warning), -m and -f option groups. -g needs some
thought first and -O is a problem of its own.

> 3) For flags which the driver accepts as high-level "toolchain" style
> options, and consequentially don't fit in any of the existing option groups
> (or have i missed one?), prefer a double-dash syntax to distinguish them:
> '--gcc-toolchain' for example to tell the driver where to find a GCC
> toolchain.

An alternative would be to have a --driver-var=value style. This might
more naturally translate into an (optional) configuration file later?

> 4) All boolean flags should be reversible by adding a complemented flag
> spelling. This is particularly important when building up multi-system
> build configurations where you may not have the ability to edit a lower
> level configuration's option set, but you can append new options.

One issue I have with the way clang behaves here is that it is not
always easy to append new options. From a build system perspective, many
source distributions in the wild append -Wall -Werror to the
CFLAGS/CXXFLAGS specified by the other and clang's behavior makes this a
lot more difficult to deal with. It would be nice to have a sticky way
to override following group flags. Something like
	-Wreallly-no-error=cast-align -Werror -Wall
as an example. I'm quite sure the FreeBSD folks will agree with me on
this.

> 5) All flags should provide at least a "joined" spelling when they accept a
> value. This can often significantly simplify life when trying to properly
> quote and group options in build configurations. Unless there is some
> unusual reason to deviate, the pattern should be:
>   - If the flag is a single letter, double letter, or 'sigil' and the
> joined form has no '=' or other marker, it should be JoinedOrSeparate. This
> follows the syntax used by '-I'.

I'd reserve this class for existing historic practise. No new flags
should be added here.

>   - Otherwise, the flag is text and would need a '=' character in the
> joined form, only the joined form should be provided.

Agreed.

There is one other form in use that should be reserved for this kind of
push-through usage (-Wp, -Wl, -Wa etc) and keeping this separate feels
acceptable to me. It should be explicitly mentioned that the first '='
character is the option separator.

> 6) Existing spellings should be preserved and kept working going forward.
> (Duh...)

It might be acceptable to clean up the list once and start an obsoletion
process now, but generally this tends to be more painful than it helps.
See history of -m486 vs -march=486 with GCC.

Joerg



More information about the cfe-dev mailing list