What does Clang do with unsupported GCC flags?

Hi everyone,

@EthanLuisMcDonough is looking into Flang’s behavior when using GFortran flags that are not supported at our end, see https://discourse.llvm.org/t/flang-driver-behavior-of-unsupported-gfortran-flags-when-fed-into-flang. Ideally, Flang should align with Clang so that users of LLVM-based toolchain get consistent behavior.

Question: What does Clang do when using a GCC flag that’s not supported? [1]

Perhaps all of GCC flags are also available in Clang and this problem does not exist at all?

Thank you,
-Andrzej

[1] Apologies in advance, with so many flags I couldn’t identify one that would meet the criteria.

I am most familiar with the clang-cl Driver and how it handled unsupported MSVC flags.

90% of the time it ignores them, in some other cases when the flag is deemed to have an important outcome we do a warning /XXYYYZZ is unused in the compilation.

The clang driver rejects all unknown flags, except for unknown flags starting with “-W”, which are assumed to be warning flags.

There’s a long list of gcc-compatible flags that are “known”, but ignored, because they only affect some optimizer behavior that isn’t actually user-visible, or because the option is enabling something that’s on by default anyway. Whether it’s okay to ignore a flag like this is sort of a case-by-case thing. You can grep for “ignored” in the clang options to see what I mean. For a new compiler, it’s probably fine to be aggressive with this sort of thing.

Any approach that eats unknown flags is likely to interact badly with build systems that try to detect which flags a compiler supports. That sort of check is very popular for C/C++ build systems, but not sure about Fortran.

1 Like

I see clang_ignored_f_Group and other similar flags in Options.td. I wasn’t aware of these - thanks a ton!

I guess that my main worry is inconsistency in how various flags are treated - should flag_A be just ignored and flag_B lead to an error? How are users meant to know which flags to avoid? But like you said, it might be tricky to avoid the case-by-case approach.

-Andrzej