arphaman created this revision.

The target-specific flag 'UseSignedCharForObjCBool' is used to determine the 
type for the Objective-C BOOL type. We should set it to `false` by default so 
that new targets can avoid setting it to `true`.


Repository:
  rL LLVM

https://reviews.llvm.org/D29768

Files:
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets.cpp
  test/Frontend/objc-bool-is-bool.m

Index: test/Frontend/objc-bool-is-bool.m
===================================================================
--- test/Frontend/objc-bool-is-bool.m
+++ test/Frontend/objc-bool-is-bool.m
@@ -1,5 +1,22 @@
 // RUN: %clang_cc1 -fsyntax-only -E -dM -triple=armv7k-apple-watchos %s | FileCheck --check-prefix=BOOL %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=armv7-apple-watchos %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=armv7-apple-ios %s | FileCheck --check-prefix=CHAR %s
+
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=arm64-apple-ios %s | FileCheck --check-prefix=BOOL %s
+
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=i686-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=i686-apple-ios %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=i686-apple-tvos %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=i686-apple-watchos %s | FileCheck --check-prefix=BOOL %s
+
 // RUN: %clang_cc1 -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=x86_64-apple-ios %s | FileCheck --check-prefix=BOOL %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=x86_64-apple-tvos %s | FileCheck --check-prefix=BOOL %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=x86_64-apple-watchos %s | FileCheck --check-prefix=CHAR %s
+
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=ppc32-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
+// RUN: %clang_cc1 -fsyntax-only -E -dM -triple=ppc64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
+
 // RUN: %clang_cc1 -x c -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
 // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
 // RUN: %clang_cc1 -x c++ -fsyntax-only -E -dM -triple=x86_64-apple-darwin16 %s | FileCheck --check-prefix=CHAR %s
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1719,6 +1719,7 @@
     PtrDiffType = SignedInt; // for http://llvm.org/bugs/show_bug.cgi?id=15726
     LongLongAlign = 32;
     SuitableAlign = 128;
+    UseSignedCharForObjCBool = true;
     resetDataLayout("E-m:o-p:32:32-f64:32:64-n32");
   }
   BuiltinVaListKind getBuiltinVaListKind() const override {
@@ -1732,6 +1733,7 @@
       : DarwinTargetInfo<PPC64TargetInfo>(Triple, Opts) {
     HasAlignMac68kSupport = true;
     SuitableAlign = 128;
+    UseSignedCharForObjCBool = true;
     resetDataLayout("E-m:o-i64:64-n32:64");
   }
 };
@@ -4335,8 +4337,8 @@
     MaxVectorAlign = 256;
     // The watchOS simulator uses the builtin bool type for Objective-C.
     llvm::Triple T = llvm::Triple(Triple);
-    if (T.isWatchOS())
-      UseSignedCharForObjCBool = false;
+    if (!T.isWatchOS())
+      UseSignedCharForObjCBool = true;
     SizeType = UnsignedLong;
     IntPtrType = SignedLong;
     resetDataLayout("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128");
@@ -4767,8 +4769,8 @@
     Int64Type = SignedLongLong;
     // The 64-bit iOS simulator uses the builtin bool type for Objective-C.
     llvm::Triple T = llvm::Triple(Triple);
-    if (T.isiOS())
-      UseSignedCharForObjCBool = false;
+    if (!T.isiOS())
+      UseSignedCharForObjCBool = true;
     resetDataLayout("e-m:o-i64:64-f80:128-n8:16:32:64-S128");
   }
 
@@ -5894,11 +5896,12 @@
       // The 32-bit ABI is silent on what ptrdiff_t should be, but given that
       // size_t is long, it's a bit weird for it to be int.
       PtrDiffType = SignedLong;
-
-      // BOOL should be a real boolean on the new ABI
-      UseSignedCharForObjCBool = false;
-    } else
+    } else {
       TheCXXABI.set(TargetCXXABI::iOS);
+
+      // BOOL should be a character on the iOS ABI.
+      UseSignedCharForObjCBool = true;
+    }
   }
 };
 
@@ -6300,7 +6303,6 @@
       : DarwinTargetInfo<AArch64leTargetInfo>(Triple, Opts) {
     Int64Type = SignedLongLong;
     WCharType = SignedInt;
-    UseSignedCharForObjCBool = false;
 
     LongDoubleWidth = LongDoubleAlign = SuitableAlign = 64;
     LongDoubleFormat = &llvm::APFloat::IEEEdouble();
Index: lib/Basic/TargetInfo.cpp
===================================================================
--- lib/Basic/TargetInfo.cpp
+++ lib/Basic/TargetInfo.cpp
@@ -72,7 +72,7 @@
   Int64Type = SignedLongLong;
   SigAtomicType = SignedInt;
   ProcessIDType = SignedInt;
-  UseSignedCharForObjCBool = true;
+  UseSignedCharForObjCBool = false;
   UseBitFieldTypeAlignment = true;
   UseZeroLengthBitfieldAlignment = false;
   UseExplicitBitFieldAlignment = true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to