22 using namespace clang;
26 class PointerSubChecker
27 :
public Checker< check::PreStmt<BinaryOperator> > {
28 mutable std::unique_ptr<BuiltinBug> BT;
31 void checkPreStmt(
const BinaryOperator *B, CheckerContext &C)
const;
36 CheckerContext &C)
const {
42 SVal LV = C.getSVal(B->
getLHS());
43 SVal RV = C.getSVal(B->
getRHS());
45 const MemRegion *LR = LV.getAsRegion();
46 const MemRegion *RR = RV.getAsRegion();
51 const MemRegion *BaseLR = LR->getBaseRegion();
52 const MemRegion *BaseRR = RR->getBaseRegion();
58 if (isa<SymbolicRegion>(BaseLR) || isa<SymbolicRegion>(BaseRR))
61 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
64 new BuiltinBug(
this,
"Pointer subtraction",
65 "Subtraction of two pointers that do not point to " 66 "the same memory chunk may cause incorrect result."));
67 auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N);
69 C.emitReport(std::move(R));
73 void ento::registerPointerSubChecker(CheckerManager &mgr) {
74 mgr.registerChecker<PointerSubChecker>();
A builtin binary operation expression such as "x + y" or "x <= y".
Dataflow Directional Tag Classes.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...