21 using namespace clang;
25 class PointerSubChecker
26 :
public Checker< check::PreStmt<BinaryOperator> > {
27 mutable std::unique_ptr<BuiltinBug> BT;
30 void checkPreStmt(
const BinaryOperator *B, CheckerContext &C)
const;
35 CheckerContext &C)
const {
41 SVal LV = C.getSVal(B->
getLHS());
42 SVal RV = C.getSVal(B->
getRHS());
44 const MemRegion *LR = LV.getAsRegion();
45 const MemRegion *RR = RV.getAsRegion();
50 const MemRegion *BaseLR = LR->getBaseRegion();
51 const MemRegion *BaseRR = RR->getBaseRegion();
57 if (isa<SymbolicRegion>(BaseLR) || isa<SymbolicRegion>(BaseRR))
60 if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
63 new BuiltinBug(
this,
"Pointer subtraction",
64 "Subtraction of two pointers that do not point to " 65 "the same memory chunk may cause incorrect result."));
66 auto R = llvm::make_unique<BugReport>(*BT, BT->getDescription(), N);
68 C.emitReport(std::move(R));
72 void ento::registerPointerSubChecker(CheckerManager &mgr) {
73 mgr.registerChecker<PointerSubChecker>();
76 bool ento::shouldRegisterPointerSubChecker(
const LangOptions &LO) {
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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...