]> granicus.if.org Git - clang/commitdiff
__is_target_arch: Check the arch and subarch instead of the arch name
authorAlex Lorenz <arphaman@gmail.com>
Fri, 15 Dec 2017 19:58:38 +0000 (19:58 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 15 Dec 2017 19:58:38 +0000 (19:58 +0000)
This ensures that when compiling for "arm64" __is_target_arch will succeed for
both "arm64" and "aarch64".

Thanks to Bob Wilson who pointed this out!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320853 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3d72006bad4e1e2979fc89d9d4f76ee67cf976de..9b062643b9bd0dc95698a59b404695134029f779 100644 (file)
@@ -1615,9 +1615,9 @@ static bool isTargetArch(const TargetInfo &TI, const IdentifierInfo *II) {
   }
   // Check the parsed arch when it has no sub arch to allow Clang to
   // match thumb to thumbv7 but to prohibit matching thumbv6 to thumbv7.
-  return (Arch.getSubArch() == llvm::Triple::NoSubArch &&
-          Arch.getArch() == TT.getArch()) ||
-         Arch.getArchName() == TT.getArchName();
+  return (Arch.getSubArch() == llvm::Triple::NoSubArch ||
+          Arch.getSubArch() == TT.getSubArch()) &&
+         Arch.getArch() == TT.getArch();
 }
 
 /// Implements the __is_target_vendor builtin macro.
diff --git a/test/Preprocessor/is_target_arm64.c b/test/Preprocessor/is_target_arm64.c
new file mode 100644 (file)
index 0000000..87ebe94
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios11 -verify %s
+// expected-no-diagnostics
+
+#if !__is_target_arch(arm64) || !__is_target_arch(aarch64)
+  #error "mismatching arch"
+#endif
+
+#if __is_target_arch(aarch64_be)
+  #error "mismatching arch"
+#endif