21#include "llvm/Support/raw_ostream.h"
27class UndefResultChecker
28 :
public Checker< check::PostStmt<BinaryOperator> > {
30 const BugType BT{
this,
"Result of operation is garbage or undefined"};
33 void checkPostStmt(
const BinaryOperator *B, CheckerContext &
C)
const;
56 std::tie(StInBound, StOutBound) = state->assumeInBoundDual(Idx, ElementCount);
57 return StOutBound && !StInBound;
62 if (
C.getSVal(B).isUndef()) {
66 if (
const FunctionDecl *EnclosingFunctionDecl =
67 dyn_cast<FunctionDecl>(
C.getStackFrame()->getDecl()))
68 if (
C.getCalleeName(EnclosingFunctionDecl) ==
"swap")
72 ExplodedNode *N =
C.generateErrorNode();
76 SmallString<256> sbuf;
77 llvm::raw_svector_ostream
OS(sbuf);
78 const Expr *Ex =
nullptr;
81 if (
C.getSVal(B->
getLHS()).isUndef()) {
85 else if (
C.getSVal(B->
getRHS()).isUndef()) {
91 OS <<
"The " << (isLeft ?
"left" :
"right") <<
" operand of '"
93 <<
"' is a garbage value";
95 OS <<
" due to array index out of bounds";
98 OS <<
"The result of the '"
100 <<
"' expression is undefined";
102 auto report = std::make_unique<PathSensitiveBugReport>(BT,
OS.str(), N);
110 C.emitReport(std::move(report));
114void ento::registerUndefResultChecker(CheckerManager &mgr) {
118bool ento::shouldRegisterUndefResultChecker(
const CheckerManager &mgr) {
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
static bool isArrayIndexOutOfBounds(CheckerContext &C, const Expr *Ex)
A builtin binary operation expression such as "x + y" or "x <= y".
StringRef getOpcodeStr() const
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
bool isValid() const =delete
ElementRegion is used to represent both array elements and casts.
QualType getValueType() const override
MemRegion - The root abstract class for all memory regions.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getSuperRegion() const
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.
DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State, const MemRegion *MR, SValBuilder &SVB, QualType Ty)
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)