]> granicus.if.org Git - clang/commitdiff
__is_target_environment: Check the environment after parsing it
authorAlex Lorenz <arphaman@gmail.com>
Fri, 15 Dec 2017 20:07:53 +0000 (20:07 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 15 Dec 2017 20:07:53 +0000 (20:07 +0000)
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

lib/Lex/PPMacroExpansion.cpp
test/Preprocessor/is_target_environment_version.c [new file with mode: 0644]

index 9b062643b9bd0dc95698a59b404695134029f779..41633f90c34da280126dc9b8ffbdcc71ad0f2638 100644 (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
diff --git a/test/Preprocessor/is_target_environment_version.c b/test/Preprocessor/is_target_environment_version.c
new file mode 100644 (file)
index 0000000..e933860
--- /dev/null
@@ -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