From: Ted Kremenek Date: Sat, 28 Mar 2009 19:59:33 +0000 (+0000) Subject: Fix regression in pointer comparison with NULL (e.g., 0 != ptr). This fixes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a8d6b0852c47e43dac5c1679b4609b752234ed7;p=clang Fix regression in pointer comparison with NULL (e.g., 0 != ptr). This fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67954 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/GRSimpleVals.cpp b/lib/Analysis/GRSimpleVals.cpp index a38d76d260..8e605ca4c7 100644 --- a/lib/Analysis/GRSimpleVals.cpp +++ b/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/test/Analysis/CheckNSError.m b/test/Analysis/CheckNSError.m index 28435727eb..779b865aff 100644 --- a/test/Analysis/CheckNSError.m +++ b/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; +} + +