r216075 - [analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals.

Jordan Rose jordan_rose at apple.com
Wed Aug 20 09:51:18 PDT 2014


Author: jrose
Date: Wed Aug 20 11:51:18 2014
New Revision: 216075

URL: http://llvm.org/viewvc/llvm-project?rev=216075&view=rev
Log:
[analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals.

PR20693. Patch by Anders Rönnholm.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
    cfe/trunk/test/Analysis/identical-expressions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp?rev=216075&r1=216074&r2=216075&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp Wed Aug 20 11:51:18 2014
@@ -455,7 +455,7 @@ static bool isIdenticalStmt(const ASTCon
   case Stmt::StringLiteralClass: {
     const StringLiteral *StringLit1 = cast<StringLiteral>(Stmt1);
     const StringLiteral *StringLit2 = cast<StringLiteral>(Stmt2);
-    return StringLit1->getString() == StringLit2->getString();
+    return StringLit1->getBytes() == StringLit2->getBytes();
   }
   case Stmt::MemberExprClass: {
     const MemberExpr *MemberStmt1 = cast<MemberExpr>(Stmt1);

Modified: cfe/trunk/test/Analysis/identical-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/identical-expressions.cpp?rev=216075&r1=216074&r2=216075&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/identical-expressions.cpp (original)
+++ cfe/trunk/test/Analysis/identical-expressions.cpp Wed Aug 20 11:51:18 2014
@@ -1511,3 +1511,10 @@ void test_nowarn_chained_if_stmts_3(int
   else if (x++) // no-warning
     ;
 }
+
+void test_warn_wchar() {
+  const wchar_t * a = 0 ? L"Warning" : L"Warning"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}}
+}
+void test_nowarn_wchar() {
+  const wchar_t * a = 0 ? L"No" : L"Warning";
+}





More information about the cfe-commits mailing list