From: Ted Kremenek Date: Fri, 9 Apr 2010 20:26:53 +0000 (+0000) Subject: Remove fixit for string literal comparison. Telling the user to use 'strcmp' is... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03a4bee558b63ead66e942c6b26381df9a8b1754;p=clang 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 --- 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(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) {