Skip to content

Commit

Permalink
[analyzer] IdenticalExpr: use getBytes rather than getString to compa…
Browse files Browse the repository at this point in the history
…re string literals.

PR20693. Patch by Anders Rönnholm.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216075 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jrose-apple committed Aug 20, 2014
1 parent b9f1d9e commit ef75d13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions test/Analysis/identical-expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit ef75d13

Please sign in to comment.