[cfe-commits] r68407 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjC/exprs.m
Chris Lattner
sabre at nondot.org
Fri Apr 3 14:11:29 PDT 2009
Author: lattner
Date: Fri Apr 3 16:11:28 2009
New Revision: 68407
URL: http://llvm.org/viewvc/llvm-project?rev=68407&view=rev
Log:
improve the string literal comparison warning to not call @encode's "string literals".
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/exprs.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=68407&r1=68406&r2=68407&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 3 16:11:28 2009
@@ -1417,8 +1417,8 @@
def warn_selfcomparison : Warning<
"self-comparison always results in a constant value">;
def warn_stringcompare : Warning<
- "result of comparison against a string literal is unspecified "
- "(use strcmp?)">;
+ "result of comparison against %select{a string literal|@encode}0 is "
+ "unspecified (use strcmp instead)">;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=68407&r1=68406&r2=68407&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr 3 16:11:28 2009
@@ -3411,7 +3411,8 @@
// operand is null), the user probably wants strcmp.
if ((isa<StringLiteral>(LHSStripped) || isa<ObjCEncodeExpr>(LHSStripped)) &&
!RHSStripped->isNullPointerConstant(Context))
- Diag(Loc, diag::warn_stringcompare)
+ Diag(Loc, diag::warn_stringcompare)
+ << isa<ObjCEncodeExpr>(LHSStripped)
<< lex->getSourceRange()
<< CodeModificationHint::CreateReplacement(SourceRange(Loc), ", ")
<< CodeModificationHint::CreateInsertion(lex->getLocStart(),
@@ -3423,6 +3424,7 @@
isa<ObjCEncodeExpr>(RHSStripped)) &&
!LHSStripped->isNullPointerConstant(Context))
Diag(Loc, diag::warn_stringcompare)
+ << isa<ObjCEncodeExpr>(RHSStripped)
<< rex->getSourceRange()
<< CodeModificationHint::CreateReplacement(SourceRange(Loc), ", ")
<< CodeModificationHint::CreateInsertion(lex->getLocStart(),
Modified: cfe/trunk/test/SemaObjC/exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/exprs.m?rev=68407&r1=68406&r2=68407&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/exprs.m (original)
+++ cfe/trunk/test/SemaObjC/exprs.m Fri Apr 3 16:11:28 2009
@@ -15,5 +15,7 @@
"bar"
@"baz"
" b\0larg"; // expected-warning {{literal contains NUL character}}
+
+ if (@encode(int) == "foo") { } // expected-warning {{result of comparison against @encode is unspecified}}
}
More information about the cfe-commits
mailing list