From 1a241d161948d80b3f8990ecac0806474469c5d5 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Feb 2011 05:11:46 +0000 Subject: Teach CFGBuilder about null pointer constants in conditionals, and how they can be used to prune branches. Fixes false null pointer dereference warning in PR 8183. llvm-svn: 126305 --- clang/lib/Analysis/CFG.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'clang/lib/Analysis/CFG.cpp') diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 0957875fd26..90b3120cd22 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -17,6 +17,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/StmtVisitor.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/AST/CharUnits.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Format.h" @@ -413,9 +414,16 @@ private: Expr::EvalResult Result; if (!S->isTypeDependent() && !S->isValueDependent() && - S->Evaluate(Result, *Context) && Result.Val.isInt()) - return Result.Val.getInt().getBoolValue(); - + S->Evaluate(Result, *Context)) { + if (Result.Val.isInt()) + return Result.Val.getInt().getBoolValue(); + if (Result.Val.isLValue()) { + Expr *e = Result.Val.getLValueBase(); + const CharUnits &c = Result.Val.getLValueOffset(); + if (!e && c.isZero()) + return false; + } + } return TryResult(); } }; -- cgit v1.2.3