From: Alex Lorenz Date: Fri, 15 Dec 2017 20:07:53 +0000 (+0000) Subject: __is_target_environment: Check the environment after parsing it X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=817210c218310bb222f03149bfb6d23e7fd4d122;p=clang __is_target_environment: Check the environment after parsing it This ensures that target triples with environment versions can still work with __is_target_environment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320854 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 9b062643b9..41633f90c3 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -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 diff --git a/test/Preprocessor/is_target_environment_version.c b/test/Preprocessor/is_target_environment_version.c new file mode 100644 index 0000000000..e93386013c --- /dev/null +++ b/test/Preprocessor/is_target_environment_version.c @@ -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