summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/Module.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r--clang/lib/Basic/Module.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 9ff976c03b9..440151dd061 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -71,6 +71,37 @@ Module::~Module() {
}
}
+static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
+ StringRef Platform = Target.getPlatformName();
+ StringRef Env = Target.getTriple().getEnvironmentName();
+
+ // Attempt to match platform and environment.
+ if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
+ Env == Feature)
+ return true;
+
+ auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
+ auto Pos = LHS.find("-");
+ if (Pos == StringRef::npos)
+ return false;
+ SmallString<128> NewLHS = LHS.slice(0, Pos);
+ NewLHS += LHS.slice(Pos+1, LHS.size());
+ return NewLHS == RHS;
+ };
+
+ SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
+ // Darwin has different but equivalent variants for simulators, example:
+ // 1. x86_64-apple-ios-simulator
+ // 2. x86_64-apple-iossimulator
+ // where both are valid examples of the same platform+environment but in the
+ // variant (2) the simulator is hardcoded as part of the platform name. Both
+ // forms above should match for "iossimulator" requirement.
+ if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
+ return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
+
+ return PlatformEnv == Feature;
+}
+
/// Determine whether a translation unit built using the current
/// language options has the given feature.
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
@@ -93,7 +124,8 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
.Case("opencl", LangOpts.OpenCL)
.Case("tls", Target.isTLSSupported())
.Case("zvector", LangOpts.ZVector)
- .Default(Target.hasFeature(Feature));
+ .Default(Target.hasFeature(Feature) ||
+ isPlatformEnvironment(Target, Feature));
if (!HasFeature)
HasFeature = std::find(LangOpts.ModuleFeatures.begin(),
LangOpts.ModuleFeatures.end(),
OpenPOWER on IntegriCloud