aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-04-09 20:26:53 +0000
committerTed Kremenek <kremenek@apple.com>2010-04-09 20:26:53 +0000
commit03a4bee558b63ead66e942c6b26381df9a8b1754 (patch)
tree3728ae5af06641be0fb1239a4ac3e4bdbd4f38c2
parentc53e3658e667fed25d428d58204f295209b81d45 (diff)
Remove fixit for string literal comparison. Telling the user to use 'strcmp' is bad, and
we don't have enough information to tell them how to use 'strncmp'. Instead, change the diagnostic to indicate they should use 'strncmp'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100890 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaExpr.cpp6
-rw-r--r--test/FixIt/fixit.c6
-rw-r--r--test/Sema/exprs.c2
4 files changed, 3 insertions, 13 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 62769decf4..c21726ba7b 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2718,7 +2718,7 @@ def warn_selfcomparison : Warning<
"self-comparison always results in a constant value">;
def warn_stringcompare : Warning<
"result of comparison against %select{a string literal|@encode}0 is "
- "unspecified (use strcmp instead)">;
+ "unspecified (use strncmp instead)">;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 654b220499..6820449e1c 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -5402,11 +5402,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
DiagRuntimeBehavior(Loc,
PDiag(diag::warn_stringcompare)
<< isa<ObjCEncodeExpr>(literalStringStripped)
- << literalString->getSourceRange()
- << FixItHint::CreateReplacement(SourceRange(Loc), ", ")
- << FixItHint::CreateInsertion(lex->getLocStart(), "strcmp(")
- << FixItHint::CreateInsertion(PP.getLocForEndOfToken(rex->getLocEnd()),
- resultComparison));
+ << literalString->getSourceRange());
}
}
diff --git a/test/FixIt/fixit.c b/test/FixIt/fixit.c
index 83d724dffc..7ee5575cf2 100644
--- a/test/FixIt/fixit.c
+++ b/test/FixIt/fixit.c
@@ -31,9 +31,3 @@ void f1(x, y)
int i0 = { 17 };
-int f2(const char *my_string) {
- // FIXME: terminal output isn't so good when "my_string" is shorter
-// CHECK: return strcmp(my_string , "foo") == 0;
- return my_string == "foo";
-}
-
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index 9acc63fa41..4df8188e43 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -84,7 +84,7 @@ void test11(struct mystruct P, float F) {
// PR3753
int test12(const char *X) {
- return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
+ return X == "foo"; // expected-warning {{comparison against a string literal is unspecified (use strncmp instead)}}
}
int test12b(const char *X) {