[PATCH] D99353: [driver] Make `clang` warn rather then error on `flang` options

Andrzej Warzynski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 5 08:52:35 PDT 2021


awarzynski added a comment.

Hi @protze.joachim , thank you for testing this so thoroughly!

In D99353#2656215 <https://reviews.llvm.org/D99353#2656215>, @protze.joachim wrote:

> I tested with `-Werror`:
>
>   $ flang -fopenmp test-f77.f -ffree-form -c
>   $ clang -fopenmp test-f77.o -ffree-form -lgfortran -Werror && echo $?
>   clang-13: warning: command line option ‘-ffree-form’ is only valid in Flang mode (i.e. for Fortran input)
>   clang-13: error: argument unused during compilation: '-ffree-form' [-Werror,-Wunused-command-line-argument]
>
> Since `-Werror` only raises the second warning, `-Wno-error=unused-command-line-argument` allows to successfully compile with `-Werror`.

I think that `-Werror` should also elevate the first warning to an error. This can be fixed by creating a definition for the diagnostic in clang/include/clang/Basic/DiagnosticDriverKinds.td.

> I also tested with `-ffixed-form` and `-ffixed-line-length-132`. The latter doesn't work, while `-ffixed-line-length=132` works.

Tl;Dr I haven't figured yet how to make this work for options that are aliases.
**Longer version:**
This is caused by the fact that `ffixed-line-length-132` is an alias <https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L4327> for `ffixed-line-length=132`. When parsing options, the OptTable API will skip unknown options (e.g. options marked with `FlangOnlyOption` when in Clang mode) and represent them internally as OPT_UNKNOWN <https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Option/OptParser.td#L238>. This happens in Optable.cpp <https://github.com/llvm/llvm-project/blob/main/llvm/lib/Option/OptTable.cpp#L388>. Options that are "unknown" contain no information, so it's impossible to check their aliases (or whether they alias some other option). This is problematic as options/args are converted to their unaliased forms when created (see here <https://github.com/llvm/llvm-project/blob/43cac1d27d7d57a7800150f95c3f8ac1e3b2bc2b/llvm/include/llvm/Option/Arg.h#L98-L99>).

Btw, how important are these aliases for you?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99353/new/

https://reviews.llvm.org/D99353



More information about the cfe-commits mailing list