objective-c modern translator: buildit objc bool
type for rewriter project will be BoolTy.
// rdar://11231426. 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154861 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 48c4872..baaddcf 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1547,9 +1547,6 @@
   "using %0 with a literal is redundant">, InGroup<ObjCRedundantLiteralUse>;
 }
 
-def warn_bool_for_boolean_literal : Warning<
-  "BOOL of type %0 is non-intergal and unsuitable for a "
-  "boolean literal - ignored">, InGroup<DiagGroup<"numeric-literals">>;
 def err_only_annotate_after_access_spec : Error<
   "access specifier can only have annotation attributes">;
 def err_attribute_section_invalid_for_target : Error<
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index bbd376a..a03cf83 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -132,6 +132,11 @@
   IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
 
+  /// Flag whether the Objective-C built-in boolean type should be signed char.
+  /// Otherwise, when this flag is not set, the normal built-in boolean type is
+  /// used.
+  unsigned UseSignedCharForObjCBool : 1;
+
   /// Control whether the alignment of bit-field types is respected when laying
   /// out structures. If true, then the alignment of the bit-field type will be
   /// used to (a) impact the alignment of the containing structure, and (b)
@@ -299,6 +304,16 @@
     return MCountName;
   }
 
+  /// useSignedCharForObjCBool - Check if the Objective-C built-in boolean
+  /// type should be signed char.  Otherwise, if this returns false, the
+  /// normal built-in boolean type should also be used for Objective-C.
+  bool useSignedCharForObjCBool() const {
+    return UseSignedCharForObjCBool;
+  }
+  void noSignedCharForObjCBool() {
+    UseSignedCharForObjCBool = false;
+  }
+
   /// useBitFieldTypeAlignment() - Check whether the alignment of bit-field 
   /// types is respected when laying out structures.
   bool useBitFieldTypeAlignment() const {
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index acf5e0b..887beac 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -481,7 +481,8 @@
   InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel);
   
   // Builtin type for __objc_yes and __objc_no
-  ObjCBuiltinBoolTy = SignedCharTy;
+  ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ?
+                       SignedCharTy : BoolTy);
   
   ObjCConstantStringType = QualType();
 
diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
index f938b5a..8c49486 100644
--- a/lib/Basic/TargetInfo.cpp
+++ b/lib/Basic/TargetInfo.cpp
@@ -58,6 +58,7 @@
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
   SigAtomicType = SignedInt;
+  UseSignedCharForObjCBool = true;
   UseBitFieldTypeAlignment = true;
   UseZeroLengthBitfieldAlignment = false;
   ZeroLengthBitfieldBoundary = 0;
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index cab6b90..803e418 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -651,6 +651,10 @@
   // created. This complexity should be lifted elsewhere.
   getTarget().setForcedLangOptions(getLangOpts());
 
+  // rewriter project will change target built-in bool type from its default. 
+  if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
+    getTarget().noSignedCharForObjCBool();
+
   // Validate/process some options.
   if (getHeaderSearchOpts().Verbose)
     OS << "clang -cc1 version " CLANG_VERSION_STRING
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0d0f2f5..3e368a3 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -11268,22 +11268,6 @@
 Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
   assert((Kind == tok::kw___objc_yes || Kind == tok::kw___objc_no) &&
          "Unknown Objective-C Boolean value!");
-  QualType ObjCBoolLiteralQT = Context.ObjCBuiltinBoolTy;
-  // signed char is the default type for boolean literals. Use 'BOOL'
-  // instead, if BOOL typedef is visible in its scope instead.
-  Decl *TD = 
-    LookupSingleName(TUScope, &Context.Idents.get("BOOL"), 
-                     SourceLocation(), LookupOrdinaryName);
-  if (TypedefDecl *BoolTD = dyn_cast_or_null<TypedefDecl>(TD)) {
-    QualType QT = BoolTD->getUnderlyingType();
-    if (!QT->isIntegralOrUnscopedEnumerationType()) {
-      Diag(OpLoc, diag::warn_bool_for_boolean_literal) << QT;
-      Diag(BoolTD->getLocation(), diag::note_previous_declaration);
-    }
-    else
-      ObjCBoolLiteralQT = QT;
-  }
-  
   return Owned(new (Context) ObjCBoolLiteralExpr(Kind == tok::kw___objc_yes,
-                                        ObjCBoolLiteralQT, OpLoc));
+                                        Context.ObjCBuiltinBoolTy, OpLoc));
 }
diff --git a/test/Rewriter/objc-bool-literal-check-modern.mm b/test/Rewriter/objc-bool-literal-check-modern.mm
index b28e594..3386197 100644
--- a/test/Rewriter/objc-bool-literal-check-modern.mm
+++ b/test/Rewriter/objc-bool-literal-check-modern.mm
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s 
 // rdar://11124775
 
-typedef signed char BOOL;
+typedef bool BOOL;
 
 BOOL yes() {
   return __objc_yes;
@@ -22,8 +22,8 @@
   return __objc_yes;
 }
 
-// CHECK: return ((signed char)1);
-// CHECK: return ((signed char)0);
-// CHECK: which (((signed char)1));
-// CHECK: which (((signed char)0));
-// CHECK: return ((signed char)1);
+// CHECK: return ((bool)1);
+// CHECK: return ((bool)0);
+// CHECK: which (((bool)1));
+// CHECK: which (((bool)0));
+// CHECK: return ((bool)1);
diff --git a/test/Rewriter/objc-bool-literal-modern.mm b/test/Rewriter/objc-bool-literal-modern.mm
index 6bbbb44..328ee6b 100644
--- a/test/Rewriter/objc-bool-literal-modern.mm
+++ b/test/Rewriter/objc-bool-literal-modern.mm
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -fsyntax-only -D"__declspec(X)=" %t-rw.cpp
 // rdar://11124775
 
-typedef signed char BOOL;
+typedef bool BOOL;
 
 BOOL yes() {
   return __objc_yes;
diff --git a/test/Rewriter/objc-modern-numeric-literal.mm b/test/Rewriter/objc-modern-numeric-literal.mm
index d27d03d..5f0b1fc 100644
--- a/test/Rewriter/objc-modern-numeric-literal.mm
+++ b/test/Rewriter/objc-modern-numeric-literal.mm
@@ -4,7 +4,7 @@
 
 extern "C" void *sel_registerName(const char *);
 
-typedef signed char BOOL;
+typedef bool BOOL;
 typedef long NSInteger;
 typedef unsigned long NSUInteger;
 
@@ -63,7 +63,7 @@
 // CHECK:  NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), 42LL);
 // CHECK:  NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.1415927);
 // CHECK:  NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535);
-// CHECK:  NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)true);
-// CHECK:  NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)false);
-// CHECK:  NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)true);
-// CHECK:  NSNumber *falseNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)false);
+// CHECK:  NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true);
+// CHECK:  NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false);
+// CHECK:  NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true);
+// CHECK:  NSNumber *falseNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false);
diff --git a/test/Rewriter/rewrite-modern-container-literal.mm b/test/Rewriter/rewrite-modern-container-literal.mm
index 87b9b89..2c2f61d 100644
--- a/test/Rewriter/rewrite-modern-container-literal.mm
+++ b/test/Rewriter/rewrite-modern-container-literal.mm
@@ -5,7 +5,7 @@
 void *sel_registerName(const char *);
 typedef unsigned long NSUInteger;
 typedef long NSInteger;
-typedef signed char BOOL;
+typedef bool BOOL;
 
 @interface NSNumber
 + (NSNumber *)numberWithChar:(char)value;
diff --git a/test/SemaObjC/objc-literal-nsnumber.m b/test/SemaObjC/objc-literal-nsnumber.m
index 449bfff..6635bea 100644
--- a/test/SemaObjC/objc-literal-nsnumber.m
+++ b/test/SemaObjC/objc-literal-nsnumber.m
@@ -78,8 +78,8 @@
 }
 
 // rdar:// 11231426
-typedef float BOOL; // expected-note {{previous declaration is here}}
+typedef float BOOL;
 
 BOOL radar11231426() {
-        return __objc_yes; // expected-warning {{BOOL of type 'float' is non-intergal and unsuitable for a boolean literal - ignored}}
+        return __objc_yes;
 }
diff --git a/test/SemaObjCXX/literals.mm b/test/SemaObjCXX/literals.mm
index eed6765..6cdd207 100644
--- a/test/SemaObjCXX/literals.mm
+++ b/test/SemaObjCXX/literals.mm
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s
 
 // rdar://11231426
-typedef bool BOOL;
+typedef signed char BOOL;
 
 void y(BOOL (^foo)());