summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-07-07 09:53:47 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-07-07 09:53:47 +0000
commit3803df3dcdad05b68d1547ee9e1cbbd2996dbb23 (patch)
tree4f1d56800f4d07e05535c24be7d422dc53b5d910 /llvm/lib/Support
parent67049f034da014ad51f1e5a09fbb97a86925c31f (diff)
downloadbcm5719-llvm-3803df3dcdad05b68d1547ee9e1cbbd2996dbb23.tar.gz
bcm5719-llvm-3803df3dcdad05b68d1547ee9e1cbbd2996dbb23.zip
[Support] sys::getProcessTriple should return a macOS triple using
the system's version of macOS sys::getProcessTriple returns LLVM_HOST_TRIPLE, whose system version might not be the actual version of the system on which the compiler running. This commit ensures that, for macOS, sys::getProcessTriple returns a triple with the system's macOS version. rdar://33177551 Differential Revision: https://reviews.llvm.org/D34446 llvm-svn: 307372
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Host.cpp3
-rw-r--r--llvm/lib/Support/Unix/Host.inc25
-rw-r--r--llvm/lib/Support/Windows/Host.inc4
3 files changed, 25 insertions, 7 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 232efe648b0..31d43fed193 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -1494,7 +1494,8 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) { return false; }
#endif
std::string sys::getProcessTriple() {
- Triple PT(Triple::normalize(LLVM_HOST_TRIPLE));
+ std::string TargetTripleString = updateTripleOSVersion(LLVM_HOST_TRIPLE);
+ Triple PT(Triple::normalize(TargetTripleString));
if (sizeof(void *) == 8 && PT.isArch32Bit())
PT = PT.get64BitArchVariant();
diff --git a/llvm/lib/Support/Unix/Host.inc b/llvm/lib/Support/Unix/Host.inc
index 0ba6a25aa19..5580e63893c 100644
--- a/llvm/lib/Support/Unix/Host.inc
+++ b/llvm/lib/Support/Unix/Host.inc
@@ -34,18 +34,31 @@ static std::string getOSVersion() {
return info.release;
}
-std::string sys::getDefaultTargetTriple() {
- std::string TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
-
- // On darwin, we want to update the version to match that of the
- // target.
+static std::string updateTripleOSVersion(std::string TargetTripleString) {
+ // On darwin, we want to update the version to match that of the target.
std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
if (DarwinDashIdx != std::string::npos) {
TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
TargetTripleString += getOSVersion();
+ return TargetTripleString;
+ }
+ std::string::size_type MacOSDashIdx = TargetTripleString.find("-macos");
+ if (MacOSDashIdx != std::string::npos) {
+ TargetTripleString.resize(MacOSDashIdx);
+ // Reset the OS to darwin as the OS version from `uname` doesn't use the
+ // macOS version scheme.
+ TargetTripleString += "-darwin";
+ TargetTripleString += getOSVersion();
}
+ return TargetTripleString;
+}
+
+std::string sys::getDefaultTargetTriple() {
+ std::string TargetTripleString =
+ updateTripleOSVersion(LLVM_DEFAULT_TARGET_TRIPLE);
- // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
+ // Override the default target with an environment variable named by
+ // LLVM_TARGET_TRIPLE_ENV.
#if defined(LLVM_TARGET_TRIPLE_ENV)
if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
TargetTripleString = EnvTriple;
diff --git a/llvm/lib/Support/Windows/Host.inc b/llvm/lib/Support/Windows/Host.inc
index 7e196cf0ce1..461fb7833b8 100644
--- a/llvm/lib/Support/Windows/Host.inc
+++ b/llvm/lib/Support/Windows/Host.inc
@@ -17,6 +17,10 @@
using namespace llvm;
+static void updateTripleOSVersion(std::string &) {
+ // Do nothing.
+}
+
std::string sys::getDefaultTargetTriple() {
const char *Triple = LLVM_DEFAULT_TARGET_TRIPLE;
OpenPOWER on IntegriCloud