[cfe-commits] r170945 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/Sema.h lib/Sema/SemaChecking.cpp lib/Sema/SemaExpr.cpp
Ted Kremenek
kremenek at apple.com
Fri Dec 21 14:46:35 PST 2012
Author: kremenek
Date: Fri Dec 21 16:46:35 2012
New Revision: 170945
URL: http://llvm.org/viewvc/llvm-project?rev=170945&view=rev
Log:
Tweak Sema::CheckLiteralKind() to also include block literals
This simplifies some diagnostic logic in checkUnsafeAssignLiteral(),
hopefully making it less error prone.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=170945&r1=170944&r2=170945&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 21 16:46:35 2012
@@ -3690,7 +3690,7 @@
"; 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>;
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=170945&r1=170944&r2=170945&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Dec 21 16:46:35 2012
@@ -1879,6 +1879,7 @@
LK_Numeric,
LK_Boxed,
LK_String,
+ LK_Block,
LK_None
};
ObjCLiteralKind CheckLiteralKind(Expr *FromE);
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=170945&r1=170944&r2=170945&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Dec 21 16:46:35 2012
@@ -5754,19 +5754,14 @@
// 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();
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=170945&r1=170944&r2=170945&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec 21 16:46:35 2012
@@ -6874,6 +6874,8 @@
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 @@
// 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");
}
More information about the cfe-commits
mailing list