25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/Support/raw_ostream.h"
29 using namespace clang;
33 class MacOSXAPIChecker :
public Checker< check::PreStmt<CallExpr> > {
34 mutable std::unique_ptr<BugType> BT_dispatchOnce;
40 StringRef FName)
const;
44 StringRef FName)
const;
53 StringRef FName)
const {
70 BT_dispatchOnce.reset(
new BugType(
this,
"Improper use of 'dispatch_once'",
71 "API Misuse (Apple)"));
78 StringRef TrimmedFName = FName.ltrim(
'_');
79 if (TrimmedFName != FName)
84 llvm::raw_svector_ostream os(S);
85 os <<
"Call to '" << FName <<
"' uses";
86 if (
const VarRegion *VR = dyn_cast<VarRegion>(R))
87 os <<
" the local variable '" << VR->getDecl()->getName() <<
'\'';
89 os <<
" stack allocated memory";
90 os <<
" for the predicate value. Using such transient memory for "
91 "the predicate is potentially dangerous.";
92 if (isa<VarRegion>(R) && isa<StackLocalsSpaceRegion>(R->
getMemorySpace()))
93 os <<
" Perhaps you intended to declare the variable as 'static'?";
95 auto report = llvm::make_unique<BugReport>(*BT_dispatchOnce, os.str(), N);
96 report->addRange(CE->
getArg(0)->getSourceRange());
104 void MacOSXAPIChecker::checkPreStmt(
const CallExpr *CE,
111 llvm::StringSwitch<SubChecker>(
Name)
112 .Cases(
"dispatch_once",
115 &MacOSXAPIChecker::CheckDispatchOnce)
119 (this->*SC)(C, CE, Name);
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.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
const MemSpaceRegion * getMemorySpace() const
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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
const ProgramStateRef & getState() const
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
SourceLocation getLocStart() const LLVM_READONLY
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
const LocationContext * getLocationContext() const