Skip to content

Commit 3d157cf

Browse files
committed
[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
1 parent 779d24e commit 3d157cf

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3677,8 +3677,10 @@ def multi__module : Flag<["-"], "multi_module">;
36773677
def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
36783678
def multiply__defined : Separate<["-"], "multiply_defined">;
36793679
def mwarn_nonportable_cfstrings : Flag<["-"], "mwarn-nonportable-cfstrings">, Group<m_Group>;
3680+
def canonical_prefixes : Flag<["-"], "canonical-prefixes">, Flags<[HelpHidden, CoreOption]>,
3681+
HelpText<"Use absolute paths for invoking subcommands (default)">;
36803682
def no_canonical_prefixes : Flag<["-"], "no-canonical-prefixes">, Flags<[HelpHidden, CoreOption]>,
3681-
HelpText<"Use relative instead of canonical paths">;
3683+
HelpText<"Use relative paths for invoking subcommands">;
36823684
def no_cpp_precomp : Flag<["-"], "no-cpp-precomp">, Group<clang_ignored_f_Group>;
36833685
def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, Flags<[NoXarchOption]>;
36843686
def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group<pedantic_Group>;

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
10911091
// Silence driver warnings if requested
10921092
Diags.setIgnoreAllWarnings(Args.hasArg(options::OPT_w));
10931093

1094-
// -no-canonical-prefixes is used very early in main.
1094+
// -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1095+
Args.ClaimAllArgs(options::OPT_canonical_prefixes);
10951096
Args.ClaimAllArgs(options::OPT_no_canonical_prefixes);
10961097

10971098
// f(no-)integated-cc1 is also used very early in main.

clang/test/Driver/no-canonical-prefixes.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@
1010
// RUN: rm -f %t.fake
1111
// RUN: ln -sf %t.real %t.fake
1212
// RUN: cd %t.fake
13-
// RUN: ./test-clang -v -S %s 2>&1 | FileCheck --check-prefix=CANONICAL %s
14-
// RUN: ./test-clang -v -S %s -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=NON-CANONICAL %s
13+
// RUN: ./test-clang -v -S %s 2>&1 \
14+
// RUN: | FileCheck --check-prefix=CANONICAL %s
15+
// RUN: ./test-clang -v -S %s 2>&1 \
16+
// RUN: -no-canonical-prefixes \
17+
// RUN: | FileCheck --check-prefix=NON-CANONICAL %s
18+
// RUN: ./test-clang -v -S %s 2>&1 \
19+
// RUN: -no-canonical-prefixes \
20+
// RUN: -canonical-prefixes \
21+
// RUN: | FileCheck --check-prefix=CANONICAL %s
22+
// RUN: ./test-clang -v -S %s 2>&1 \
23+
// RUN: -no-canonical-prefixes \
24+
// RUN: -canonical-prefixes \
25+
// RUN: -no-canonical-prefixes \
26+
// RUN: | FileCheck --check-prefix=NON-CANONICAL %s
1527
//
1628
// FIXME: This should really be '.real'.
1729
// CANONICAL: InstalledDir: {{.*}}.fake

clang/tools/driver/driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@ int main(int Argc, const char **Argv) {
416416
// Skip end-of-line response file markers
417417
if (Args[i] == nullptr)
418418
continue;
419-
if (StringRef(Args[i]) == "-no-canonical-prefixes") {
419+
if (StringRef(Args[i]) == "-canonical-prefixes")
420+
CanonicalPrefixes = true;
421+
else if (StringRef(Args[i]) == "-no-canonical-prefixes")
420422
CanonicalPrefixes = false;
421-
break;
422-
}
423423
}
424424

425425
// Handle CL and _CL_ which permits additional command line options to be

0 commit comments

Comments
 (0)