summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2012-12-21 21:59:39 +0000
committerTed Kremenek <kremenek@apple.com>2012-12-21 21:59:39 +0000
commit44c2a2a26ecdd47d2933ad58a6569a0f25802d65 (patch)
treecb95abd35a447f9aa1e8787be992b74860289941 /clang
parent01a33f82d293cd2fa00021624be917b177a60459 (diff)
downloadbcm5719-llvm-44c2a2a26ecdd47d2933ad58a6569a0f25802d65.tar.gz
bcm5719-llvm-44c2a2a26ecdd47d2933ad58a6569a0f25802d65.zip
Change checkUnsafeAssignLiteral() to use the new Sema::CheckLiteralKind().
Along the way, fix a bug in CheckLiteralKind(), previously in diagnoseObjCLiteralComparison, where we didn't ignore parentheses in boxed expressions for purpose of classification. In other words, both @42 and @(42) should be classified as numeric literals. llvm-svn: 170931
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaChecking.cpp39
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
-rw-r--r--clang/test/SemaObjC/arc.m8
4 files changed, 23 insertions, 28 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c66b9702fad..1fb04e46b8a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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{dictionary literal|array literal|block literal|boxed expression}0"
+ "assigning %select{block literal|array literal|dictionary literal|numeric literal|boxed expression}0"
" to a weak %select{property|variable}1"
"; object will be released after assignment">,
InGroup<ARCUnsafeRetainedAssign>;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c2dabb45afe..7d957ec4087 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5753,33 +5753,24 @@ static bool checkUnsafeAssignLiteral(Sema &S, SourceLocation Loc,
// immediately zapped in a weak reference. Note that we explicitly
// allow ObjCStringLiterals, since those are designed to never really die.
RHS = RHS->IgnoreParenImpCasts();
- // This enum needs to match with the 'select' in warn_arc_literal_assign.
- enum Kind { Dictionary = 0, Array, Block, BoxedE, None };
- unsigned kind = None;
- switch (RHS->getStmtClass()) {
- default:
- break;
- case Stmt::ObjCDictionaryLiteralClass:
- kind = Dictionary;
- break;
- case Stmt::ObjCArrayLiteralClass:
- kind = Array;
- break;
- case Stmt::BlockExprClass:
- kind = Block;
- break;
- case Stmt::ObjCBoxedExprClass:
- kind = BoxedE;
- break;
+
+ // 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;
}
- if (kind != None) {
- S.Diag(Loc, diag::warn_arc_literal_assign)
- << (unsigned) kind
+
+ S.Diag(Loc, diag::warn_arc_literal_assign)
+ << SelectVal
<< (isProperty ? 0 : 1)
<< RHS->getSourceRange();
- return true;
- }
- return false;
+
+ return true;
}
static bool checkUnsafeAssignObject(Sema &S, SourceLocation Loc,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b8bd48dedc8..0ea3b6cc398 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6875,7 +6875,7 @@ Sema::ObjCLiteralKind Sema::CheckLiteralKind(Expr *FromE) {
// "dictionary literal"
return LK_Dictionary;
case Stmt::ObjCBoxedExprClass: {
- Expr *Inner = cast<ObjCBoxedExpr>(FromE)->getSubExpr();
+ Expr *Inner = cast<ObjCBoxedExpr>(FromE)->getSubExpr()->IgnoreParens();
switch (Inner->getStmtClass()) {
case Stmt::IntegerLiteralClass:
case Stmt::FloatingLiteralClass:
diff --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m
index 08216b6d80e..bffcd4bbde2 100644
--- a/clang/test/SemaObjC/arc.m
+++ b/clang/test/SemaObjC/arc.m
@@ -740,11 +740,15 @@ void rdar12569201(id key, id value) {
__weak id y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
__weak id z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
__weak id b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
- __weak id e = @(42); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
+ __weak id n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
+ __weak id e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
+ __weak id m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
// Assignments.
y = @{ key : value }; // expected-warning {{assigning dictionary literal to a weak variable; object will be released after assignment}}
z = @[ value ]; // expected-warning {{assigning array literal to a weak variable; object will be released after assignment}}
b = ^() {}; // expected-warning {{assigning block literal to a weak variable; object will be released after assignment}}
- e = @(42); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
+ n = @42; // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
+ e = @(42); // expected-warning {{assigning numeric literal to a weak variable; object will be released after assignment}}
+ m = @(41 + 1); // expected-warning {{assigning boxed expression to a weak variable; object will be released after assignment}}
}
OpenPOWER on IntegriCloud