21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/Support/raw_ostream.h"
24 using namespace clang;
28 class UndefResultChecker
29 :
public Checker< check::PostStmt<BinaryOperator> > {
31 mutable std::unique_ptr<BugType> BT;
42 if (!isa<ArraySubscriptExpr>(Ex))
45 SVal Loc = state->getSVal(Ex, LCtx);
57 ProgramStateRef StInBound = state->assumeInBound(Idx, NumElements,
true);
58 ProgramStateRef StOutBound = state->assumeInBound(Idx, NumElements,
false);
59 return StOutBound && !StInBound;
66 if (state->getSVal(B, LCtx).isUndef()) {
83 new BuiltinBug(
this,
"Result of operation is garbage or undefined"));
86 llvm::raw_svector_ostream OS(sbuf);
87 const Expr *Ex =
nullptr;
90 if (state->getSVal(B->
getLHS(), LCtx).isUndef()) {
94 else if (state->getSVal(B->
getRHS(), LCtx).isUndef()) {
100 OS <<
"The " << (isLeft ?
"left" :
"right")
103 <<
"' is a garbage value";
105 OS <<
" due to array index out of bounds";
109 OS <<
"The result of the '"
111 <<
"' expression is undefined";
113 auto report = llvm::make_unique<BugReport>(*BT, OS.str(), N);
virtual DefinedOrUnknownSVal getSizeInElements(ProgramStateRef state, const MemRegion *region, QualType EleTy)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
StringRef getCalleeName(const FunctionDecl *FunDecl) const
Get the name of the called function (path-sensitive).
MemRegion - The root abstract class for all memory regions.
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
static bool isArrayIndexOutOfBounds(CheckerContext &C, const Expr *Ex)
A builtin binary operation expression such as "x + y" or "x <= y".
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
const MemRegion * getSuperRegion() const
Expr - This represents one expression.
const ProgramStateRef & getState() const
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
StoreManager & getStoreManager()
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
const Decl * getDecl() const
const StackFrameContext * getStackFrame() const
StringRef getOpcodeStr() const
bool trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, BugReport &R, bool IsArg=false, bool EnableNullFPSuppression=true)
Attempts to add visitors to trace a null or undefined value back to its point of origin, whether it is a symbol constrained to null or an explicit assignment.
QualType getValueType() const override
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
ElementRegin is used to represent both array elements and casts.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const LocationContext * getLocationContext() const