71

Where can I find a complete list of Clang flags?

There are some, like -include-pch, that don't appear to be even listed in the man page. :(

I know that GCC uses some of the same flags, but it doesn't include documentation for stuff like -Os which I believe is only available in Clang. Is there a place where I can find a single, consolidated list of all the Clang options ever?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Colen
  • 13,428
  • 21
  • 78
  • 107
  • 2
    See [this answer by Chandler Carruth, clang developer](https://softwareengineering.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development/124574#124574). – ShreevatsaR Aug 09 '17 at 03:56
  • Version-dependent options: [Clang warning flags](https://github.com/barro/compiler-warnings#clang-warning-flags). Though it only lists the names of the options (not the documentation). – Peter Mortensen Oct 25 '22 at 17:11

4 Answers4

89

I don't know if this is exactly what you want. Maybe more options are described elsewhere, but I think you are interested in the Clang frontend options. By default, the options displayed seem to describe the "GCC-compatible driver".

clang -cc1 --help should give you what you want.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Guillaume Papin
  • 1,370
  • 11
  • 16
  • 1
    Thanks, this is the best option I've seen so far. – Colen Oct 26 '11 at 22:00
  • 9
    is there a way to list all possible warnings for `-W`? – marcin May 12 '13 at 21:22
  • 1
    I don't think so. There is `-Weverything` if you want to activate all of them though. Since Clang tries to be compatible with GCC you can take a look at GCC's ones (`gcc --help=warnings`). – Guillaume Papin May 12 '13 at 21:52
  • 2
    Some more info here http://programmers.stackexchange.com/a/124574 and here http://www.noxeos.com/2012/01/10/warning-flags-clang/. Note that `-Weverything` that I mentioned earlier is not for everyday use but more for 'experimentation'. – Guillaume Papin May 12 '13 at 22:03
  • @GuillaumePapin can you eleborate on what the '-cc1' option does? I can't find it documented anywhere – tjk213 Oct 28 '14 at 17:56
  • 1
    You can see at the [Clang - FAQ](http://clang.llvm.org/docs/FAQ.html#i-run-clang-cc1-and-get-weird-errors-about-missing-headers) that `clang -cc1` is the frontend. `clang` is the GCC-compatible driver. And recently, a new driver has appeared, `clang-cl`, which is a CL-compatible driver. I don't know how to explain `clang -cc1` properly but the word that matters is **frontend**. You should get answers by looking for "compiler frontend", "clang frontend". – Guillaume Papin Oct 28 '14 at 23:55
  • How come none of these places document -shared or -dynamiclib? – Jake Oct 11 '19 at 02:26
8

There are many hidden options in LLVM:

clang --help-hidden
opt --help-hidden
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DTharun
  • 746
  • 7
  • 16
7

For Clang, they are listed in the diagnostics reference, which can be found on the documentation website here

  • Better: https://clang.llvm.org/docs/ClangCommandLineReference.html – Andrew Feb 14 '21 at 04:16
  • the command line reference only references -W but with the diagnostics reference page, you can find that it takes -Wdeprecated-objc-isa-usage, for example. – Jake Mar 07 '21 at 01:07
2

If you want to get a complete list of warning flags, including hierarchies (IE which sub-flags are enabled by groups like -Wall), you can use the LLVM tool diagtool.

  • $ diagtool tree Will print the complete list of warnings clang supports.
  • $ diagtool tree -Wnon-gcc will print the warnings enabled by -Wnon-gcc.

The warnings are color-coded:

  • RED = it does nothing, exists only for GCC compatibility
  • GREEN = the warning is enabled by default
  • YELLOW = the flag enables new behavior

diagtool-example-wall-flagg=


Finally, I wrote a short script if you're interested in viewing the diff between sets of flags (see image below)

For example: -Wall -> -Wall -Wextra ->-Wall -Wextra -Wnon-gcc:

Here is a set of flags not enabled by your typical -Wall -Wextra -Wpedantic for Clang (as of LLVM 16 dev) you might find useful, that I scraped from the output of diagtool:

Hope someone out there finds this information useful =) enter image description here

Gavin Ray
  • 595
  • 1
  • 3
  • 10