]> granicus.if.org Git - clang/commitdiff
Tweak Sema::CheckLiteralKind() to also include block literals
authorTed Kremenek <kremenek@apple.com>
Fri, 21 Dec 2012 22:46:35 +0000 (22:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 21 Dec 2012 22:46:35 +0000 (22:46 +0000)
This simplifies some diagnostic logic in checkUnsafeAssignLiteral(),
hopefully making it less error prone.

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

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExpr.cpp

index 1fb04e46b8abb885932b34e9f889f342592f3560..64a7472bef25c52b4a5967bce2d5f6a546838f4c 100644 (file)
@@ -3690,7 +3690,7 @@ def warn_arc_retained_property_assign : Warning<
   "; object will be released after assignment">,
   InGroup<ARCUnsafeRetainedAssign>;
 def warn_arc_literal_assign : Warning<
-  "assigning %select{block literal|array literal|dictionary literal|numeric literal|boxed expression}0"
+  "assigning %select{array literal|dictionary literal|numeric literal|boxed expression|<should not happen>|block literal}0"
   " to a weak %select{property|variable}1"
   "; object will be released after assignment">,
   InGroup<ARCUnsafeRetainedAssign>;
index d87718dc544fd8afe7b955005910f808e6e93a49..81093cb987781a0c697f765ce686f11574995ef7 100644 (file)
@@ -1879,6 +1879,7 @@ public:
     LK_Numeric,
     LK_Boxed,
     LK_String,
+    LK_Block,
     LK_None
   };
   ObjCLiteralKind CheckLiteralKind(Expr *FromE);
index 7d957ec408716951e00e81e7a7aa9f09e746f361..f0de7becb20be6525f08c30befadd49e7044f726 100644 (file)
@@ -5754,19 +5754,14 @@ static bool checkUnsafeAssignLiteral(Sema &S, SourceLocation Loc,
   // allow ObjCStringLiterals, since those are designed to never really die.
   RHS = RHS->IgnoreParenImpCasts();
 
-  // Classification for diagnostic.
-  unsigned SelectVal = /* block literal */ 0;
-  if (!isa<BlockExpr>(RHS)) {
-    // This enum needs to match with the 'select' in
-    // warn_objc_arc_literal_assign (off-by-1).
-    Sema::ObjCLiteralKind Kind = S.CheckLiteralKind(RHS);
-    if (Kind == Sema::LK_String || Kind == Sema::LK_None)
-      return false;
-    SelectVal = (unsigned) Kind + 1;
-  }
+  // This enum needs to match with the 'select' in
+  // warn_objc_arc_literal_assign (off-by-1).
+  Sema::ObjCLiteralKind Kind = S.CheckLiteralKind(RHS);
+  if (Kind == Sema::LK_String || Kind == Sema::LK_None)
+    return false;
 
   S.Diag(Loc, diag::warn_arc_literal_assign)
-    << SelectVal
+    << (unsigned) Kind
     << (isProperty ? 0 : 1)
     << RHS->getSourceRange();
 
index 0ea3b6cc398978d1d8884d650b05ac0f7239cf1b..191a26d105eab913c5ca29454bc40e7a804a949f 100644 (file)
@@ -6874,6 +6874,8 @@ Sema::ObjCLiteralKind Sema::CheckLiteralKind(Expr *FromE) {
     case Stmt::ObjCDictionaryLiteralClass:
       // "dictionary literal"
       return LK_Dictionary;
+    case Stmt::BlockExprClass:
+      return LK_Block;
     case Stmt::ObjCBoxedExprClass: {
       Expr *Inner = cast<ObjCBoxedExpr>(FromE)->getSubExpr()->IgnoreParens();
       switch (Inner->getStmtClass()) {
@@ -6923,6 +6925,7 @@ static void diagnoseObjCLiteralComparison(Sema &S, SourceLocation Loc,
   // LK_String should always be after the other literals, since it has its own
   // warning flag.
   Sema::ObjCLiteralKind LiteralKind = S.CheckLiteralKind(Literal);
+  assert(LiteralKind != Sema::LK_Block);
   if (LiteralKind == Sema::LK_None) {
     llvm_unreachable("Unknown Objective-C object literal kind");
   }