From 035cf930d51b890ecd67805d27baf70d8d2c0038 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 28 Mar 2009 19:59:33 +0000 Subject: [PATCH] Fix regression in pointer comparison with NULL (e.g., 0 != ptr). This fixes . llvm-svn: 67954 --- clang/lib/Analysis/GRSimpleVals.cpp | 10 ++++------ clang/test/Analysis/CheckNSError.m | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clang/lib/Analysis/GRSimpleVals.cpp b/clang/lib/Analysis/GRSimpleVals.cpp index a38d76d26080..8e605ca4c783 100644 --- a/clang/lib/Analysis/GRSimpleVals.cpp +++ b/clang/lib/Analysis/GRSimpleVals.cpp @@ -375,13 +375,11 @@ TryAgain: return NonLoc::MakeIntTruthVal(BasicVals, b); } - else if (isa(R)) { + else if (SymbolRef Sym = R.getAsSymbol()) { const SymIntExpr * SE = - Eng.getSymbolManager().getSymIntExpr( - cast(R).getSymbol(), - BinaryOperator::NE, - cast(L).getValue(), - Eng.getContext().IntTy); + Eng.getSymbolManager().getSymIntExpr(Sym, BinaryOperator::NE, + cast(L).getValue(), + Eng.getContext().IntTy); return nonloc::SymExprVal(SE); } diff --git a/clang/test/Analysis/CheckNSError.m b/clang/test/Analysis/CheckNSError.m index 28435727eb79..779b865aff8c 100644 --- a/clang/test/Analysis/CheckNSError.m +++ b/clang/test/Analysis/CheckNSError.m @@ -41,7 +41,19 @@ void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRe *error = 0; // expected-warning {{Potential null dereference.}} } -int bar(CFErrorRef* error) { - if (error) *error = 0; +int f1(CFErrorRef* error) { + if (error) *error = 0; // no-warning return 0; } + +int f2(CFErrorRef* error) { + if (0 != error) *error = 0; // no-warning + return 0; +} + +int f3(CFErrorRef* error) { + if (error != 0) *error = 0; // no-warning + return 0; +} + +