[cfe-commits] r154619 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/objc-literal-nsnumber.m

Fariborz Jahanian fjahanian at apple.com
Thu Apr 12 14:24:56 PDT 2012


Author: fjahanian
Date: Thu Apr 12 16:24:56 2012
New Revision: 154619

URL: http://llvm.org/viewvc/llvm-project?rev=154619&view=rev
Log:
objective-c literals: Issue warning and ignore
when BOOL is not of an intergal type when
boolean literals are used. // rdar://11231426

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=154619&r1=154618&r2=154619&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 12 16:24:56 2012
@@ -1547,6 +1547,9 @@
   "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/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154619&r1=154618&r2=154619&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Apr 12 16:24:56 2012
@@ -11270,9 +11270,13 @@
   Decl *TD = 
     LookupSingleName(TUScope, &Context.Idents.get("BOOL"), 
                      SourceLocation(), LookupOrdinaryName);
-  if (TypeDecl *BoolTD = dyn_cast_or_null<TypeDecl>(TD)) {
-    QualType QT = QualType(BoolTD->getTypeForDecl(), 0);
-    if (!QT.isNull())
+  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;
   }
   

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=154619&r1=154618&r2=154619&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m Thu Apr 12 16:24:56 2012
@@ -76,3 +76,10 @@
                                @"date" : [NSDate date] };
   return dictionary3;
 }
+
+// rdar:// 11231426
+typedef float BOOL; // expected-note {{previous declaration is here}}
+
+BOOL radar11231426() {
+        return __objc_yes; // expected-warning {{BOOL of type 'float' is non-intergal and unsuitable for a boolean literal - ignored}}
+}





More information about the cfe-commits mailing list