blight icon indicating copy to clipboard operation
blight copied to clipboard

Support `CCC_OVERRIDE_OPTIONS`

Open woodruffw opened this issue 5 years ago • 2 comments

Now that we've better separated effective and canonical options (#39), we can better model one of Clang's escape hatches CCC_OVERRIDE_OPTIONS.

Source: https://github.com/llvm/llvm-project/blob/93a1fc2e18b452216be70f534da42f7702adbe1d/clang/tools/driver/driver.cpp#L79-L105

In summary: CCC_OVERRIDE_OPTIONS can be specified in the environment, and takes precedence over all other option transformations (like response files). The transforms (that we care about) are:

  • ^FOO: Prepend FOO to the arguments (e.g. ^-Werror)
  • +FOO: Append FOO to the arguments (e.g. +-Werror)
  • s/FOO/BAR/: Replace all FOO with BAR in the arguments (e.g. s/-Werror/-Wno-error/)
  • xFOO: Remove all instances of FOO from the arguments
  • XFOO: Remove all instances of FOO opt from the arguments
    • Does this include FOO=opt? The Clang code doesn't seem to handle that, but it may be normalized to FOO opt prior to override handling.
  • Ox: Remove all optimization arguments, append -Ox (e.g., -O2)

woodruffw avatar Dec 11 '20 18:12 woodruffw

The settings in CCC_OVERRIDE_OPTIONS are space separated. The comments in Clang's driver say that they're comma separated, but the code actually splits on spaces.

woodruffw avatar Dec 11 '20 18:12 woodruffw

In summary: CCC_OVERRIDE_OPTIONS can be specified in the environment, and takes precedence over all other option transformations (like response files).

To clarify: this means that CCC_OVERRIDE_OPTIONS happens after all response files and other sources have been expanded. It's the very last phase in the clang driver's argument construction process.

woodruffw avatar Dec 21 '21 16:12 woodruffw