diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-11-03 18:41:06 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-11-03 18:41:06 +0000 |
commit | dc998c1b90a17d747ca2fb05e967779740747162 (patch) | |
tree | 382ad26517f3c07ded6a250c1c6b0b3210aa7613 /lib | |
parent | e584b6538a2366327f4776e00dce4d402b4c8439 (diff) |
Merge NullDerefChecker.[h,cpp] and UndefDerefChecker.[h,cpp]. They are essentially two parts of the same check.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85911 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/Analysis/DereferenceChecker.cpp (renamed from lib/Analysis/NullDerefChecker.cpp) | 38 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngineInternalChecks.cpp | 3 | ||||
-rw-r--r-- | lib/Analysis/NSErrorChecker.cpp | 2 | ||||
-rw-r--r-- | lib/Analysis/UndefDerefChecker.cpp | 53 |
5 files changed, 40 insertions, 59 deletions
diff --git a/lib/Analysis/CMakeLists.txt b/lib/Analysis/CMakeLists.txt index 0e1d9f8cac..9661335a1e 100644 --- a/lib/Analysis/CMakeLists.txt +++ b/lib/Analysis/CMakeLists.txt @@ -20,6 +20,7 @@ add_clang_library(clangAnalysis CheckObjCInstMethSignature.cpp CheckObjCUnusedIVars.cpp CheckSecuritySyntaxOnly.cpp + DereferenceChecker.cpp DivZeroChecker.cpp Environment.cpp ExplodedGraph.cpp @@ -32,7 +33,6 @@ add_clang_library(clangAnalysis MemRegion.cpp NSAutoreleasePoolChecker.cpp NSErrorChecker.cpp - NullDerefChecker.cpp PathDiagnostic.cpp RangeConstraintManager.cpp RegionStore.cpp @@ -42,7 +42,6 @@ add_clang_library(clangAnalysis SimpleSValuator.cpp Store.cpp SymbolManager.cpp - UndefDerefChecker.cpp UndefSizedVLAChecker.cpp UndefinedArgChecker.cpp UninitializedValues.cpp diff --git a/lib/Analysis/NullDerefChecker.cpp b/lib/Analysis/DereferenceChecker.cpp index ef7da61901..33c85d5074 100644 --- a/lib/Analysis/NullDerefChecker.cpp +++ b/lib/Analysis/DereferenceChecker.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h" +#include "clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h" #include "clang/Analysis/PathSensitive/GRExprEngine.h" #include "clang/Analysis/PathSensitive/BugReporter.h" @@ -74,3 +74,39 @@ ExplodedNode *NullDerefChecker::CheckLocation(const Stmt *S, ExplodedNode *Pred, return Builder.generateNode(S, NotNullState, Pred, ProgramPoint::PostLocationChecksSucceedKind); } + + +void *UndefDerefChecker::getTag() { + static int x = 0; + return &x; +} + +ExplodedNode *UndefDerefChecker::CheckLocation(const Stmt *S, + ExplodedNode *Pred, + const GRState *state, SVal V, + GRExprEngine &Eng) { + GRStmtNodeBuilder &Builder = Eng.getBuilder(); + BugReporter &BR = Eng.getBugReporter(); + + if (V.isUndef()) { + ExplodedNode *N = Builder.generateNode(S, state, Pred, + ProgramPoint::PostUndefLocationCheckFailedKind); + if (N) { + N->markAsSink(); + + if (!BT) + BT = new BuiltinBug(0, "Undefined dereference", + "Dereference of undefined pointer value"); + + EnhancedBugReport *R = + new EnhancedBugReport(*BT, BT->getDescription().c_str(), N); + R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, + bugreporter::GetDerefExpr(N)); + BR.EmitReport(R); + } + return 0; + } + + return Pred; +} + diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp index 089d25d6cf..23ef2885a4 100644 --- a/lib/Analysis/GRExprEngineInternalChecks.cpp +++ b/lib/Analysis/GRExprEngineInternalChecks.cpp @@ -15,8 +15,7 @@ #include "clang/Analysis/PathSensitive/BugReporter.h" #include "clang/Analysis/PathSensitive/GRExprEngine.h" #include "clang/Analysis/PathSensitive/CheckerVisitor.h" -#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h" -#include "clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h" +#include "clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h" #include "clang/Analysis/PathSensitive/Checkers/DivZeroChecker.h" #include "clang/Analysis/PathSensitive/Checkers/BadCallChecker.h" #include "clang/Analysis/PathSensitive/Checkers/UndefinedArgChecker.h" diff --git a/lib/Analysis/NSErrorChecker.cpp b/lib/Analysis/NSErrorChecker.cpp index 2f6df23e08..307686ff57 100644 --- a/lib/Analysis/NSErrorChecker.cpp +++ b/lib/Analysis/NSErrorChecker.cpp @@ -18,7 +18,7 @@ #include "clang/Analysis/LocalCheckers.h" #include "clang/Analysis/PathSensitive/BugReporter.h" #include "clang/Analysis/PathSensitive/GRExprEngine.h" -#include "clang/Analysis/PathSensitive/Checkers/NullDerefChecker.h" +#include "clang/Analysis/PathSensitive/Checkers/DereferenceChecker.h" #include "BasicObjCFoundationChecks.h" #include "llvm/Support/Compiler.h" #include "clang/AST/DeclObjC.h" diff --git a/lib/Analysis/UndefDerefChecker.cpp b/lib/Analysis/UndefDerefChecker.cpp deleted file mode 100644 index da04826b7a..0000000000 --- a/lib/Analysis/UndefDerefChecker.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// UndefDerefChecker.cpp - Undefined dereference checker ----------*- C++ -*--// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This defines UndefDerefChecker, a builtin check in GRExprEngine that performs -// checks for defined pointers at loads and stores. -// -//===----------------------------------------------------------------------===// - -#include "clang/Analysis/PathSensitive/Checkers/UndefDerefChecker.h" -#include "clang/Analysis/PathSensitive/GRExprEngine.h" -#include "clang/Analysis/PathSensitive/BugReporter.h" - -using namespace clang; - -void *UndefDerefChecker::getTag() { - static int x = 0; - return &x; -} - -ExplodedNode *UndefDerefChecker::CheckLocation(const Stmt *S, - ExplodedNode *Pred, - const GRState *state, SVal V, - GRExprEngine &Eng) { - GRStmtNodeBuilder &Builder = Eng.getBuilder(); - BugReporter &BR = Eng.getBugReporter(); - - if (V.isUndef()) { - ExplodedNode *N = Builder.generateNode(S, state, Pred, - ProgramPoint::PostUndefLocationCheckFailedKind); - if (N) { - N->markAsSink(); - - if (!BT) - BT = new BuiltinBug(0, "Undefined dereference", - "Dereference of undefined pointer value"); - - EnhancedBugReport *R = - new EnhancedBugReport(*BT, BT->getDescription().c_str(), N); - R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, - bugreporter::GetDerefExpr(N)); - BR.EmitReport(R); - } - return 0; - } - - return Pred; -} |