Author: Dan Liew
Date: 2021-05-04T11:28:26-07:00
New Revision: 1971823ecb9eaa077554a5d268a44c7cb75eccce

URL: 
https://github.com/llvm/llvm-project/commit/1971823ecb9eaa077554a5d268a44c7cb75eccce
DIFF: 
https://github.com/llvm/llvm-project/commit/1971823ecb9eaa077554a5d268a44c7cb75eccce.diff

LOG: [Driver] Fix `ToolChain::getCompilerRTPath()` to return the correct path 
on Apple platforms.

When the target triple was an Apple platform `ToolChain::getOSLibName()`
(called by `getCompilerRTPath()`) would return the full OS name
including the version number (e.g. `darwin20.3.0`). This is not correct
because the library directory for all Apple platforms is `darwin`.

This in turn caused

* `-print-runtime-dir` to return a non-existant path.
* `-print-file-name=<any compiler-rt library>` to return the filename
  instead of the full path to the library.

Two regression tests are included.

rdar://77417317

Differential Revision: https://reviews.llvm.org/D101682

Added: 
    clang/test/Driver/darwin-print-file-name.c
    clang/test/Driver/darwin-print-runtime-dir.c

Modified: 
    clang/lib/Driver/ToolChain.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 88bc640a0b2d..3342de85fc30 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -387,6 +387,9 @@ static StringRef getArchNameForCompilerRTLib(const 
ToolChain &TC,
 }
 
 StringRef ToolChain::getOSLibName() const {
+  if (Triple.isOSDarwin())
+    return "darwin";
+
   switch (Triple.getOS()) {
   case llvm::Triple::FreeBSD:
     return "freebsd";

diff  --git a/clang/test/Driver/darwin-print-file-name.c 
b/clang/test/Driver/darwin-print-file-name.c
new file mode 100644
index 000000000000..91623a4c589f
--- /dev/null
+++ b/clang/test/Driver/darwin-print-file-name.c
@@ -0,0 +1,27 @@
+// 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
+
+// RUN: %clang -print-file-name=libclang_rt.osx.a 
--target=x86_64-apple-macosx11.0.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
+
+// RUN: %clang -print-file-name=libclang_rt.ios.a 
--target=arm64-apple-ios14.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR-IOS %s
+// PRINT-RUNTIME-DIR-IOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.ios.a
+
+// RUN: %clang -print-file-name=libclang_rt.tvos.a 
--target=arm64-apple-tvos14.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR-TVOS %s
+// PRINT-RUNTIME-DIR-TVOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.tvos.a
+
+// RUN: %clang -print-file-name=libclang_rt.watchos.a 
--target=arm64-apple-watchos5.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR-WATCHOS %s
+// PRINT-RUNTIME-DIR-WATCHOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.watchos.a

diff  --git a/clang/test/Driver/darwin-print-runtime-dir.c 
b/clang/test/Driver/darwin-print-runtime-dir.c
new file mode 100644
index 000000000000..967cdbfa94b7
--- /dev/null
+++ b/clang/test/Driver/darwin-print-runtime-dir.c
@@ -0,0 +1,24 @@
+// Regression test. Previously the output returned the full OS name
+// (e.g. `darwin20.3.0`) instead of just `darwin`.
+
+// 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
+
+// RUN: %clang -print-runtime-dir --target=x86_64-apple-macosx11.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+
+// RUN: %clang -print-runtime-dir --target=arm64-apple-ios14.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+
+// RUN: %clang -print-runtime-dir --target=arm64-apple-tvos14.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+
+// RUN: %clang -print-runtime-dir --target=arm64-apple-watchos5.0.0 \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:      | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
+
+// PRINT-RUNTIME-DIR: lib{{/|\\}}darwin{{$}}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to