[cfe-commits] r100890 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/FixIt/fixit.c test/Sema/exprs.c

Ted Kremenek kremenek at apple.com
Fri Apr 9 13:26:53 PDT 2010


Author: kremenek
Date: Fri Apr  9 15:26:53 2010
New Revision: 100890

URL: http://llvm.org/viewvc/llvm-project?rev=100890&view=rev
Log:
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'.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/FixIt/fixit.c
    cfe/trunk/test/Sema/exprs.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=100890&r1=100889&r2=100890&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  9 15:26:53 2010
@@ -2718,7 +2718,7 @@
   "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)">;
 
 
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=100890&r1=100889&r2=100890&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Apr  9 15:26:53 2010
@@ -5402,11 +5402,7 @@
       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());
     }
   }
 

Modified: cfe/trunk/test/FixIt/fixit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.c?rev=100890&r1=100889&r2=100890&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.c (original)
+++ cfe/trunk/test/FixIt/fixit.c Fri Apr  9 15:26:53 2010
@@ -31,9 +31,3 @@
 
 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";
-}
-

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=100890&r1=100889&r2=100890&view=diff
==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Fri Apr  9 15:26:53 2010
@@ -84,7 +84,7 @@
 
 // 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) {





More information about the cfe-commits mailing list