[PATCH] D108818: [clang] Add a -canonical-prefixes option

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 27 07:23:08 PDT 2021


thakis created this revision.
thakis added reviewers: hans, rnk.
Herald added a subscriber: dang.
thakis requested review of this revision.

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.


https://reviews.llvm.org/D108818

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/no-canonical-prefixes.c
  clang/tools/driver/driver.cpp


Index: clang/tools/driver/driver.cpp
===================================================================
--- clang/tools/driver/driver.cpp
+++ 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
Index: clang/test/Driver/no-canonical-prefixes.c
===================================================================
--- clang/test/Driver/no-canonical-prefixes.c
+++ 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
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ 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.
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3676,8 +3676,10 @@
 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>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108818.369094.patch
Type: text/x-patch
Size: 3484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210827/47b038fa/attachment-0001.bin>


More information about the cfe-commits mailing list