__is_target_environment: Check the environment after parsing it

This ensures that target triples with environment versions can still work with
__is_target_environment.

llvm-svn: 320854
This commit is contained in:
Alex Lorenz 2017-12-15 20:07:53 +00:00
parent 268759e58f
commit 3b288c6e1b
2 changed files with 9 additions and 4 deletions

View File

@ -1643,10 +1643,9 @@ static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II) {
/// Implements the __is_target_environment builtin macro.
static bool isTargetEnvironment(const TargetInfo &TI,
const IdentifierInfo *II) {
StringRef EnvName = TI.getTriple().getEnvironmentName();
if (EnvName.empty())
EnvName = "unknown";
return EnvName.equals_lower(II->getName());
std::string EnvName = (llvm::Twine("---") + II->getName().lower()).str();
llvm::Triple Env(EnvName);
return TI.getTriple().getEnvironment() == Env.getEnvironment();
}
/// ExpandBuiltinMacro - If an identifier token is read that is to be expanded

View File

@ -0,0 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-windows-msvc18.0.0 -verify %s
// expected-no-diagnostics
#if !__is_target_environment(msvc)
#error "mismatching environment"
#endif