diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3677,8 +3677,10 @@ def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">; def multiply__defined : Separate<["-"], "multiply_defined">; def mwarn_nonportable_cfstrings : Flag<["-"], "mwarn-nonportable-cfstrings">, 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; def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, Flags<[NoXarchOption]>; def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1091,7 +1091,8 @@ // 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. diff --git a/clang/test/Driver/no-canonical-prefixes.c b/clang/test/Driver/no-canonical-prefixes.c --- a/clang/test/Driver/no-canonical-prefixes.c +++ b/clang/test/Driver/no-canonical-prefixes.c @@ -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 diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp --- a/clang/tools/driver/driver.cpp +++ b/clang/tools/driver/driver.cpp @@ -416,10 +416,10 @@ // 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