[clang] Add a -canonical-prefixes option

In https://reviews.llvm.org/D47480 I complained that there's no positive
form of this flag, so let's add one :)

https://gcc.gnu.org/PR29931 also has a pending patch to add the positive
form to gcc (but there's admittedly not a lot of movement on that bug).

This doesn't change any defaults.

Differential Revision: https://reviews.llvm.org/D108818
This commit is contained in:
Nico Weber 2021-08-27 10:14:27 -04:00
parent 779d24e151
commit 3d157cfcc4
4 changed files with 22 additions and 7 deletions

View File

@ -3677,8 +3677,10 @@ def multi__module : Flag<["-"], "multi_module">;
def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
def multiply__defined : Separate<["-"], "multiply_defined">;
def mwarn_nonportable_cfstrings : Flag<["-"], "mwarn-nonportable-cfstrings">, Group<m_Group>;
def canonical_prefixes : Flag<["-"], "canonical-prefixes">, Flags<[HelpHidden, CoreOption]>,
HelpText<"Use absolute paths for invoking subcommands (default)">;
def no_canonical_prefixes : Flag<["-"], "no-canonical-prefixes">, Flags<[HelpHidden, CoreOption]>,
HelpText<"Use relative instead of canonical paths">;
HelpText<"Use relative paths for invoking subcommands">;
def no_cpp_precomp : Flag<["-"], "no-cpp-precomp">, Group<clang_ignored_f_Group>;
def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, Flags<[NoXarchOption]>;
def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group<pedantic_Group>;

View File

@ -1091,7 +1091,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
// Silence driver warnings if requested
Diags.setIgnoreAllWarnings(Args.hasArg(options::OPT_w));
// -no-canonical-prefixes is used very early in main.
// -canonical-prefixes, -no-canonical-prefixes are used very early in main.
Args.ClaimAllArgs(options::OPT_canonical_prefixes);
Args.ClaimAllArgs(options::OPT_no_canonical_prefixes);
// f(no-)integated-cc1 is also used very early in main.

View File

@ -10,8 +10,20 @@
// RUN: rm -f %t.fake
// RUN: ln -sf %t.real %t.fake
// RUN: cd %t.fake
// RUN: ./test-clang -v -S %s 2>&1 | FileCheck --check-prefix=CANONICAL %s
// RUN: ./test-clang -v -S %s -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=NON-CANONICAL %s
// RUN: ./test-clang -v -S %s 2>&1 \
// RUN: | FileCheck --check-prefix=CANONICAL %s
// RUN: ./test-clang -v -S %s 2>&1 \
// RUN: -no-canonical-prefixes \
// RUN: | FileCheck --check-prefix=NON-CANONICAL %s
// RUN: ./test-clang -v -S %s 2>&1 \
// RUN: -no-canonical-prefixes \
// RUN: -canonical-prefixes \
// RUN: | FileCheck --check-prefix=CANONICAL %s
// RUN: ./test-clang -v -S %s 2>&1 \
// RUN: -no-canonical-prefixes \
// RUN: -canonical-prefixes \
// RUN: -no-canonical-prefixes \
// RUN: | FileCheck --check-prefix=NON-CANONICAL %s
//
// FIXME: This should really be '.real'.
// CANONICAL: InstalledDir: {{.*}}.fake

View File

@ -416,10 +416,10 @@ int main(int Argc, const char **Argv) {
// Skip end-of-line response file markers
if (Args[i] == nullptr)
continue;
if (StringRef(Args[i]) == "-no-canonical-prefixes") {
if (StringRef(Args[i]) == "-canonical-prefixes")
CanonicalPrefixes = true;
else if (StringRef(Args[i]) == "-no-canonical-prefixes")
CanonicalPrefixes = false;
break;
}
}
// Handle CL and _CL_ which permits additional command line options to be