]> granicus.if.org Git - clang/commitdiff
[analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals.
authorJordan Rose <jordan_rose@apple.com>
Wed, 20 Aug 2014 16:51:18 +0000 (16:51 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 20 Aug 2014 16:51:18 +0000 (16:51 +0000)
PR20693. Patch by Anders Rönnholm.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216075 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
test/Analysis/identical-expressions.cpp

index d5c52b4c6a3109f7e74b1775c67583cfb49e71fd..ecb82c9031cf5a5e3b8a247f719e88050b909c38 100644 (file)
@@ -455,7 +455,7 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
   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);
index 85e3322002dd8a27541ab51ab6c2379f49f4f8d3..3c8040aed8b2b1c3d0d6cd9adf37a371a0cbccdc 100644 (file)
@@ -1511,3 +1511,10 @@ void test_nowarn_chained_if_stmts_3(int x) {
   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";
+}