diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-11-23 03:20:54 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-11-23 03:20:54 +0000 |
commit | 0835e4cccfef3ea5346962722b79484f6b3ca602 (patch) | |
tree | ae430d81b6e27ee518338da48ce110f316dfeed5 /lib/Analysis/UndefBranchChecker.cpp | |
parent | d5532b6cfff2977e0c59fa6ead7f7973984a620d (diff) |
Initial refactor of UndefBranchChecker. We still use GRBranchNodeBuilder
in the checker directly. But I don't have a better approach for now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/UndefBranchChecker.cpp')
-rw-r--r-- | lib/Analysis/UndefBranchChecker.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/Analysis/UndefBranchChecker.cpp b/lib/Analysis/UndefBranchChecker.cpp new file mode 100644 index 0000000000..38cd107a9d --- /dev/null +++ b/lib/Analysis/UndefBranchChecker.cpp @@ -0,0 +1,63 @@ +//=== UndefBranchChecker.cpp -----------------------------------*- C++ -*--===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines UndefBranchChecker, which checks for undefined branch +// condition. +// +//===----------------------------------------------------------------------===// + +#include "GRExprEngineInternalChecks.h" +#include "clang/Analysis/PathSensitive/Checker.h" + +using namespace clang; + +namespace { + +class VISIBILITY_HIDDEN UndefBranchChecker : public Checker { + BuiltinBug *BT; +public: + UndefBranchChecker() : BT(0) {} + static void *getTag(); + void VisitBranchCondition(GRBranchNodeBuilder &Builder, GRExprEngine &Eng, + Stmt *Condition, void *tag); +}; + +} + +void clang::RegisterUndefBranchChecker(GRExprEngine &Eng) { + Eng.registerCheck(new UndefBranchChecker()); +} + +void *UndefBranchChecker::getTag() { + static int x; + return &x; +} + +void UndefBranchChecker::VisitBranchCondition(GRBranchNodeBuilder &Builder, + GRExprEngine &Eng, + Stmt *Condition, void *tag) { + const GRState *state = Builder.getState(); + SVal X = state->getSVal(Condition); + if (X.isUndef()) { + ExplodedNode *N = Builder.generateNode(state, true); + if (N) { + N->markAsSink(); + if (!BT) + BT = new BuiltinBug("Undefined branch", + "Branch condition evaluates to an undefined or garbage value"); + EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription(),N); + R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, + Condition); + Eng.getBugReporter().EmitReport(R); + } + + Builder.markInfeasible(true); + Builder.markInfeasible(false); + } +} |