[cfe-commits] r154861 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Basic/TargetInfo.h lib/AST/ASTContext.cpp lib/Basic/TargetInfo.cpp lib/Frontend/CompilerInstance.cpp lib/Sema/SemaExpr.cpp test/Rewriter/objc-bool-literal-check-modern.mm test/Rewriter/objc-bool-literal-modern.mm test/Rewriter/objc-modern-numeric-literal.mm test/Rewriter/rewrite-modern-container-literal.mm test/SemaObjC/objc-literal-nsnumber.m test/SemaObjCXX/literals.mm

Fariborz Jahanian fjahanian at apple.com
Mon Apr 16 14:03:30 PDT 2012


Author: fjahanian
Date: Mon Apr 16 16:03:30 2012
New Revision: 154861

URL: http://llvm.org/viewvc/llvm-project?rev=154861&view=rev
Log:
objective-c modern translator: buildit objc bool
type for rewriter project will be BoolTy.
// rdar://11231426. 

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Rewriter/objc-bool-literal-check-modern.mm
    cfe/trunk/test/Rewriter/objc-bool-literal-modern.mm
    cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm
    cfe/trunk/test/Rewriter/rewrite-modern-container-literal.mm
    cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
    cfe/trunk/test/SemaObjCXX/literals.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Apr 16 16:03:30 2012
@@ -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<

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Apr 16 16:03:30 2012
@@ -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 {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Apr 16 16:03:30 2012
@@ -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();
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Mon Apr 16 16:03:30 2012
@@ -58,6 +58,7 @@
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
   SigAtomicType = SignedInt;
+  UseSignedCharForObjCBool = true;
   UseBitFieldTypeAlignment = true;
   UseZeroLengthBitfieldAlignment = false;
   ZeroLengthBitfieldBoundary = 0;

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Apr 16 16:03:30 2012
@@ -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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Apr 16 16:03:30 2012
@@ -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));
 }

Modified: cfe/trunk/test/Rewriter/objc-bool-literal-check-modern.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-bool-literal-check-modern.mm?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-bool-literal-check-modern.mm (original)
+++ cfe/trunk/test/Rewriter/objc-bool-literal-check-modern.mm Mon Apr 16 16:03:30 2012
@@ -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);

Modified: cfe/trunk/test/Rewriter/objc-bool-literal-modern.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-bool-literal-modern.mm?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-bool-literal-modern.mm (original)
+++ cfe/trunk/test/Rewriter/objc-bool-literal-modern.mm Mon Apr 16 16:03:30 2012
@@ -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;

Modified: cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm Mon Apr 16 16:03:30 2012
@@ -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);

Modified: cfe/trunk/test/Rewriter/rewrite-modern-container-literal.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-container-literal.mm?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-container-literal.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-modern-container-literal.mm Mon Apr 16 16:03:30 2012
@@ -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;

Modified: cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m Mon Apr 16 16:03:30 2012
@@ -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;
 }

Modified: cfe/trunk/test/SemaObjCXX/literals.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/literals.mm?rev=154861&r1=154860&r2=154861&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/literals.mm (original)
+++ cfe/trunk/test/SemaObjCXX/literals.mm Mon Apr 16 16:03:30 2012
@@ -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)());
 





More information about the cfe-commits mailing list