[PATCH] D101682: [Driver] Fix `ToolChain::getCompilerRTPath()` to return the correct path on Darwin.

Dan Liew via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 30 19:20:44 PDT 2021


delcypher created this revision.
delcypher added reviewers: arphaman, dexonsmith, kubamracek, aralisza, yln.
delcypher requested review of this revision.
Herald added a project: clang.

When the Darwin target triple included the OS version number this would cause
`ToolChain::getCompilerRTPath()` to return an incorrect path because the
suffix was something like `darwin20.3.0` instead of `darwin`.

This in turn caused

- `-print-runtime-dir` to return a non-existant path.
- `-print-file-name=<any compiler-rt library>` to not return a useful path.

Two regression tests are included.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101682

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/darwin-print-file-name.c
  clang/test/Driver/darwin-print-runtime-dir.c


Index: clang/test/Driver/darwin-print-runtime-dir.c
===================================================================
--- /dev/null
+++ clang/test/Driver/darwin-print-runtime-dir.c
@@ -0,0 +1,6 @@
+// Regression test. Previously the output included the OS version number
+// which was not correct.
+// RUN: %clang -print-runtime-dir --target=x86_64-apple-darwin20.3.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}darwin{{$}}
\ No newline at end of file
Index: clang/test/Driver/darwin-print-file-name.c
===================================================================
--- /dev/null
+++ clang/test/Driver/darwin-print-file-name.c
@@ -0,0 +1,6 @@
+// Regression test. Previously Clang just returned the library name instead
+// of the full path.
+// RUN: %clang -print-file-name=libclang_rt.osx.a --target=x86_64-apple-darwin20.3.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+// PRINT-RUNTIME-DIR: lib{{/|\\}}darwin{{/|\\}}libclang_rt.osx.a
\ No newline at end of file
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -398,6 +398,8 @@
     return "sunos";
   case llvm::Triple::AIX:
     return "aix";
+  case llvm::Triple::Darwin:
+    return "darwin";
   default:
     return getOS();
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101682.342103.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210501/0cffa534/attachment.bin>


More information about the cfe-commits mailing list