29 #include "llvm/ADT/DenseMap.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/Support/Compiler.h"
32 #include "llvm/Support/raw_ostream.h"
51 using namespace clang;
52 using namespace consumed;
60 for (
const auto &B : *Block)
62 return CS->getStmt()->getLocStart();
66 if (Block->succ_size() == 1 && *Block->succ_begin())
76 return StmtNode->getLocStart();
79 BE = Block->
rend(); BI != BE; ++BI) {
81 return CS->getStmt()->getLocStart();
110 llvm_unreachable(
"invalid enum");
116 for (
const auto &
S : CWAttr->callableStates()) {
124 case CallableWhenAttr::Unconsumed:
128 case CallableWhenAttr::Consumed:
133 if (MappedAttrState == State)
146 return RD->hasAttr<ConsumableAttr>();
156 return RD->hasAttr<ConsumableAutoCastAttr>();
163 return RD->hasAttr<ConsumableSetOnReadAttr>();
177 llvm_unreachable(
"invalid enum");
185 return FunDecl->hasAttr<TestTypestateAttr>();
195 const ConsumableAttr *CAttr =
198 switch (CAttr->getDefaultState()) {
201 case ConsumableAttr::Unconsumed:
203 case ConsumableAttr::Consumed:
206 llvm_unreachable(
"invalid enum");
211 switch (PTAttr->getParamState()) {
214 case ParamTypestateAttr::Unconsumed:
216 case ParamTypestateAttr::Consumed:
219 llvm_unreachable(
"invalid_enum");
224 switch (RTSAttr->getState()) {
227 case ReturnTypestateAttr::Unconsumed:
229 case ReturnTypestateAttr::Consumed:
232 llvm_unreachable(
"invalid enum");
236 switch (STAttr->getNewState()) {
239 case SetTypestateAttr::Unconsumed:
241 case SetTypestateAttr::Consumed:
244 llvm_unreachable(
"invalid_enum");
261 llvm_unreachable(
"invalid enum");
266 switch (FunDecl->getAttr<TestTypestateAttr>()->getTestState()) {
267 case TestTypestateAttr::Unconsumed:
269 case TestTypestateAttr::Consumed:
272 llvm_unreachable(
"invalid enum");
276 struct VarTestResult {
319 : InfoType(IT_VarTest), VarTest(VarTest) {}
322 : InfoType(IT_VarTest) {
325 VarTest.TestsFor = TestsFor;
329 const VarTestResult <est,
const VarTestResult &RTest)
330 : InfoType(IT_BinTest) {
332 BinTest.Source = Source;
334 BinTest.LTest = LTest;
335 BinTest.RTest = RTest;
341 : InfoType(IT_BinTest) {
343 BinTest.Source = Source;
345 BinTest.LTest.Var = LVar;
346 BinTest.LTest.TestsFor = LTestsFor;
347 BinTest.RTest.Var = RVar;
348 BinTest.RTest.TestsFor = RTestsFor;
352 : InfoType(IT_State), State(State) {}
356 : InfoType(IT_Tmp), Tmp(Tmp) {}
359 assert(InfoType == IT_State);
364 assert(InfoType == IT_VarTest);
369 assert(InfoType == IT_BinTest);
370 return BinTest.LTest;
374 assert(InfoType == IT_BinTest);
375 return BinTest.RTest;
379 assert(InfoType == IT_Var);
384 assert(InfoType == IT_Tmp);
389 assert(isVar() || isTmp() || isState());
402 assert(InfoType == IT_BinTest);
407 assert(InfoType == IT_BinTest);
408 return BinTest.Source;
411 inline bool isValid()
const {
return InfoType != IT_None; }
412 inline bool isState()
const {
return InfoType == IT_State; }
413 inline bool isVarTest()
const {
return InfoType == IT_VarTest; }
414 inline bool isBinTest()
const {
return InfoType == IT_BinTest; }
415 inline bool isVar()
const {
return InfoType == IT_Var; }
416 inline bool isTmp()
const {
return InfoType == IT_Tmp; }
419 return InfoType == IT_VarTest || InfoType == IT_BinTest;
423 return InfoType == IT_Var || InfoType == IT_Tmp;
427 assert(InfoType == IT_VarTest || InfoType == IT_BinTest);
429 if (InfoType == IT_VarTest) {
433 }
else if (InfoType == IT_BinTest) {
458 typedef llvm::DenseMap<const Stmt *, PropagationInfo> MapType;
459 typedef std::pair<const Stmt *, PropagationInfo> PairType;
461 typedef MapType::const_iterator ConstInfoEntry;
466 MapType PropagationMap;
468 InfoEntry findInfo(
const Expr *
E) {
469 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(E))
470 if (!Cleanups->cleanupsHaveSideEffects())
471 E = Cleanups->getSubExpr();
474 ConstInfoEntry findInfo(
const Expr *E)
const {
475 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(E))
476 if (!Cleanups->cleanupsHaveSideEffects())
477 E = Cleanups->getSubExpr();
484 void forwardInfo(
const Expr *From,
const Expr *To);
494 bool handleCall(
const CallExpr *Call,
const Expr *ObjArg,
498 void VisitCallExpr(
const CallExpr *Call);
499 void VisitCastExpr(
const CastExpr *Cast);
505 void VisitDeclStmt(
const DeclStmt *DelcS);
507 void VisitMemberExpr(
const MemberExpr *MExpr);
511 void VisitVarDecl(
const VarDecl *Var);
515 : AC(AC), Analyzer(Analyzer), StateMap(StateMap) {}
518 ConstInfoEntry Entry = findInfo(StmtNode);
520 if (Entry != PropagationMap.end())
521 return Entry->second;
527 StateMap = NewStateMap;
532 void ConsumedStmtVisitor::forwardInfo(
const Expr *From,
const Expr *To) {
533 InfoEntry Entry = findInfo(From);
534 if (Entry != PropagationMap.end())
535 insertInfo(To, Entry->second);
541 void ConsumedStmtVisitor::copyInfo(
const Expr *From,
const Expr *To,
543 InfoEntry Entry = findInfo(From);
544 if (Entry != PropagationMap.end()) {
557 InfoEntry Entry = findInfo(From);
558 if (Entry != PropagationMap.end()) {
568 InfoEntry Entry = findInfo(To);
569 if (Entry != PropagationMap.end()) {
585 const CallableWhenAttr *CWAttr = FunDecl->getAttr<CallableWhenAttr>();
595 Analyzer.WarningsHandler.warnUseInInvalidState(
605 Analyzer.WarningsHandler.warnUseOfTempInInvalidState(
617 if (isa<CXXOperatorCallExpr>(Call) && isa<CXXMethodDecl>(FunD))
621 for (
unsigned Index = Offset; Index < Call->
getNumArgs(); ++Index) {
629 InfoEntry Entry = findInfo(Call->
getArg(Index));
631 if (Entry == PropagationMap.end() || Entry->second.isTest())
636 if (ParamTypestateAttr *PTA = Param->getAttr<ParamTypestateAttr>()) {
640 if (ParamState != ExpectedState)
641 Analyzer.WarningsHandler.warnParamTypestateMismatch(
646 if (!(Entry->second.isVar() || Entry->second.isTmp()))
652 else if (ReturnTypestateAttr *RT = Param->getAttr<ReturnTypestateAttr>())
664 InfoEntry Entry = findInfo(ObjArg);
665 if (Entry != PropagationMap.end()) {
667 checkCallability(PInfo, FunD, Call->
getExprLoc());
669 if (SetTypestateAttr *STA = FunD->getAttr<SetTypestateAttr>()) {
674 else if (PInfo.
isTmp()) {
680 PropagationMap.insert(PairType(Call,
688 void ConsumedStmtVisitor::propagateReturnType(
const Expr *Call,
696 if (ReturnTypestateAttr *RTA = Fun->getAttr<ReturnTypestateAttr>())
710 InfoEntry LEntry = findInfo(BinOp->
getLHS()),
711 REntry = findInfo(BinOp->
getRHS());
713 VarTestResult LTest, RTest;
715 if (LEntry != PropagationMap.end() && LEntry->second.isVarTest()) {
716 LTest = LEntry->second.getVarTest();
723 if (REntry != PropagationMap.end() && REntry->second.isVarTest()) {
724 RTest = REntry->second.getVarTest();
731 if (!(LTest.Var ==
nullptr && RTest.Var ==
nullptr))
733 static_cast<EffectiveOp>(BinOp->
getOpcode() == BO_LOr), LTest, RTest)));
740 forwardInfo(BinOp->
getLHS(), BinOp);
756 FunDecl->isInStdNamespace()) {
761 handleCall(Call,
nullptr, FunDecl);
762 propagateReturnType(Call, FunDecl);
772 InfoEntry Entry = findInfo(Temp->
getSubExpr());
774 if (Entry != PropagationMap.end() && !Entry->second.isTest()) {
775 StateMap->setState(Temp, Entry->second.getAsState(StateMap));
790 if (ReturnTypestateAttr *RTA = Constructor->getAttr<ReturnTypestateAttr>()) {
795 PropagationMap.insert(PairType(Call,
804 copyInfo(Call->
getArg(0), Call, NS);
820 propagateReturnType(Call, MD);
829 if (!FunDecl)
return;
833 if (!handleCall(Call, Call->
getArg(0), FunDecl))
834 setInfo(Call->
getArg(0), CS);
839 handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl);
841 handleCall(Call, Call->
getArg(0), FunDecl);
843 propagateReturnType(Call, FunDecl);
847 if (
const VarDecl *Var = dyn_cast_or_null<VarDecl>(DeclRef->
getDecl()))
853 for (
const auto *DI : DeclS->
decls())
854 if (isa<VarDecl>(DI))
855 VisitVarDecl(cast<VarDecl>(DI));
869 forwardInfo(MExpr->
getBase(), MExpr);
877 if (
const ParamTypestateAttr *PTA = Param->getAttr<ParamTypestateAttr>())
889 StateMap->setState(Param, ParamState);
893 ConsumedState ExpectedState = Analyzer.getExpectedReturnState();
895 if (ExpectedState !=
CS_None) {
898 if (Entry != PropagationMap.end()) {
901 if (RetState != ExpectedState)
902 Analyzer.WarningsHandler.warnReturnTypestateMismatch(
908 StateMap->checkParamsForReturnTypestate(Ret->
getLocStart(),
909 Analyzer.WarningsHandler);
913 InfoEntry Entry = findInfo(UOp->
getSubExpr());
914 if (Entry == PropagationMap.end())
return;
918 PropagationMap.insert(PairType(UOp, Entry->second));
922 if (Entry->second.isTest())
923 PropagationMap.insert(PairType(UOp, Entry->second.invertTest()));
936 if (VIT != PropagationMap.end()) {
941 StateMap->setState(Var, St);
961 ThenStates->
setState(Test.Var, Test.TestsFor);
967 }
else if (VarState == Test.TestsFor) {
975 const VarTestResult <est = PInfo.
getLTest(),
984 ThenStates->
setState(LTest.Var, LTest.TestsFor);
989 }
else if (LState == LTest.TestsFor &&
isKnownState(RState)) {
990 if (RState == RTest.TestsFor)
1001 }
else if (LState == LTest.TestsFor) {
1007 if (RState == RTest.TestsFor)
1018 ThenStates->
setState(RTest.Var, RTest.TestsFor);
1026 else if (RState == RTest.TestsFor)
1035 assert(CurrBlock &&
"Block pointer must not be NULL");
1036 assert(TargetBlock &&
"TargetBlock pointer must not be NULL");
1038 unsigned int CurrBlockOrder = VisitOrder[CurrBlock->
getBlockID()];
1040 PE = TargetBlock->
pred_end(); PI != PE; ++PI) {
1041 if (*PI && CurrBlockOrder < VisitOrder[(*PI)->getBlockID()] )
1049 std::unique_ptr<ConsumedStateMap> &OwnedStateMap) {
1051 assert(Block &&
"Block pointer must not be NULL");
1053 auto &Entry = StateMapsArray[Block->
getBlockID()];
1056 Entry->intersect(*StateMap);
1057 }
else if (OwnedStateMap)
1058 Entry = std::move(OwnedStateMap);
1060 Entry = llvm::make_unique<ConsumedStateMap>(*StateMap);
1064 std::unique_ptr<ConsumedStateMap> StateMap) {
1066 assert(Block &&
"Block pointer must not be NULL");
1068 auto &Entry = StateMapsArray[Block->
getBlockID()];
1071 Entry->intersect(*StateMap);
1073 Entry = std::move(StateMap);
1078 assert(Block &&
"Block pointer must not be NULL");
1079 assert(StateMapsArray[Block->
getBlockID()] &&
"Block has no block info");
1081 return StateMapsArray[Block->
getBlockID()].get();
1085 StateMapsArray[Block->
getBlockID()] =
nullptr;
1088 std::unique_ptr<ConsumedStateMap>
1090 assert(Block &&
"Block pointer must not be NULL");
1092 auto &Entry = StateMapsArray[Block->
getBlockID()];
1093 return isBackEdgeTarget(Block) ? llvm::make_unique<ConsumedStateMap>(*Entry)
1098 assert(From &&
"From block must not be NULL");
1099 assert(To &&
"From block must not be NULL");
1105 assert(Block &&
"Block pointer must not be NULL");
1112 unsigned int BlockVisitOrder = VisitOrder[Block->
getBlockID()];
1114 PE = Block->
pred_end(); PI != PE; ++PI) {
1115 if (*PI && BlockVisitOrder < VisitOrder[(*PI)->getBlockID()])
1124 for (
const auto &DM : VarMap) {
1125 if (isa<ParmVarDecl>(DM.first)) {
1126 const ParmVarDecl *Param = cast<ParmVarDecl>(DM.first);
1127 const ReturnTypestateAttr *RTA = Param->getAttr<ReturnTypestateAttr>();
1133 if (DM.second != ExpectedState)
1146 VarMapType::const_iterator Entry = VarMap.find(Var);
1148 if (Entry != VarMap.end())
1149 return Entry->second;
1156 TmpMapType::const_iterator Entry = TmpMap.find(Tmp);
1158 if (Entry != TmpMap.end())
1159 return Entry->second;
1167 if (this->From && this->From == Other.
From && !Other.
Reachable) {
1168 this->markUnreachable();
1172 for (
const auto &DM : Other.
VarMap) {
1173 LocalState = this->getState(DM.first);
1178 if (LocalState != DM.second)
1190 for (
const auto &DM : LoopBackStates->
VarMap) {
1191 LocalState = this->getState(DM.first);
1196 if (LocalState != DM.second) {
1199 DM.first->getNameAsString());
1205 this->Reachable =
false;
1211 VarMap[Var] =
State;
1216 TmpMap[Tmp] =
State;
1224 for (
const auto &DM : Other->
VarMap)
1225 if (this->getState(DM.first) != DM.second)
1235 ReturnType = Constructor->getThisType(CurrContext)->getPointeeType();
1239 if (
const ReturnTypestateAttr *RTSAttr = D->getAttr<ReturnTypestateAttr>()) {
1241 if (!RD || !RD->hasAttr<ConsumableAttr>()) {
1246 WarningsHandler.warnReturnTypestateForUnconsumableType(
1247 RTSAttr->getLocation(), ReturnType.
getAsString());
1248 ExpectedReturnState =
CS_None;
1253 ExpectedReturnState =
CS_None;
1258 ExpectedReturnState =
CS_None;
1261 bool ConsumedAnalyzer::splitState(
const CFGBlock *CurrBlock,
1264 std::unique_ptr<ConsumedStateMap> FalseStates(
1268 if (
const IfStmt *IfNode =
1271 const Expr *Cond = IfNode->getCond();
1273 PInfo = Visitor.getInfo(Cond);
1274 if (!PInfo.
isValid() && isa<BinaryOperator>(Cond))
1275 PInfo = Visitor.getInfo(cast<BinaryOperator>(Cond)->getRHS());
1278 CurrStates->setSource(Cond);
1279 FalseStates->setSource(Cond);
1295 PInfo = Visitor.getInfo(BinOp->getLHS());
1297 if ((BinOp = dyn_cast_or_null<BinaryOperator>(BinOp->getLHS()))) {
1298 PInfo = Visitor.getInfo(BinOp->getRHS());
1308 CurrStates->setSource(BinOp);
1309 FalseStates->setSource(BinOp);
1311 const VarTestResult &Test = PInfo.
getVarTest();
1314 if (BinOp->getOpcode() == BO_LAnd) {
1316 CurrStates->setState(Test.Var, Test.TestsFor);
1318 CurrStates->markUnreachable();
1320 }
else if (BinOp->getOpcode() == BO_LOr) {
1322 FalseStates->setState(Test.Var,
1324 else if (VarState == Test.TestsFor)
1325 FalseStates->markUnreachable();
1335 BlockInfo.addInfo(*SI, std::move(CurrStates));
1337 CurrStates =
nullptr;
1340 BlockInfo.addInfo(*SI, std::move(FalseStates));
1354 determineExpectedReturnState(AC, D);
1361 CurrStates = llvm::make_unique<ConsumedStateMap>();
1369 for (
const auto *CurrBlock : *SortedGraph) {
1371 CurrStates = BlockInfo.getInfo(CurrBlock);
1376 }
else if (!CurrStates->isReachable()) {
1377 CurrStates =
nullptr;
1381 Visitor.
reset(CurrStates.get());
1384 for (
const auto &B : *CurrBlock) {
1385 switch (B.getKind()) {
1397 CurrStates->remove(BTE);
1419 if (!splitState(CurrBlock, Visitor)) {
1420 CurrStates->setSource(
nullptr);
1422 if (CurrBlock->succ_size() > 1 ||
1423 (CurrBlock->succ_size() == 1 &&
1424 (*CurrBlock->succ_begin())->pred_size() > 1)) {
1426 auto *RawState = CurrStates.get();
1429 SE = CurrBlock->succ_end(); SI != SE; ++SI) {
1431 if (*SI ==
nullptr)
continue;
1433 if (BlockInfo.isBackEdge(CurrBlock, *SI)) {
1434 BlockInfo.borrowInfo(*SI)->intersectAtLoopHead(
1435 *SI, CurrBlock, RawState, WarningsHandler);
1437 if (BlockInfo.allBackEdgesVisited(CurrBlock, *SI))
1438 BlockInfo.discardInfo(*SI);
1440 BlockInfo.addInfo(*SI, RawState, CurrStates);
1444 CurrStates =
nullptr;
1450 CurrStates->checkParamsForReturnTypestate(D->getLocation(),
1455 CurrStates =
nullptr;
1457 WarningsHandler.emitDiagnostics();
A call to an overloaded operator written using operator syntax.
Defines the clang::ASTContext interface.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
ASTContext & getASTContext() const
A (possibly-)qualified type.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
QualType getCallResultType() const
Determine the type of an expression that calls this function.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
void VisitCastExpr(const CastExpr *Cast)
succ_iterator succ_begin()
IfStmt - This represents an if/then/else.
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
C Language Family Type Representation.
void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, std::unique_ptr< ConsumedStateMap > &OwnedStateMap)
virtual void warnParamReturnTypestateMismatch(SourceLocation Loc, StringRef VariableName, StringRef ExpectedState, StringRef ObservedState)
Warn about parameter typestate mismatches upon return.
std::string getAsString() const
void VisitUnaryOperator(const UnaryOperator *UOp)
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
bool handleCall(const CallExpr *Call, const Expr *ObjArg, const FunctionDecl *FunD)
const Expr * getInit() const
Represents a call to a C++ constructor.
void run(AnalysisDeclContext &AC)
Check a function's CFG for consumed violations.
SourceLocation getLocStart() const LLVM_READONLY
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
static ConsumedState testsFor(const FunctionDecl *FunDecl)
void setState(const VarDecl *Var, ConsumedState State)
Set the consumed state of a given variable.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
SourceLocation getReturnLoc() const
void VisitCXXMemberCallExpr(const CXXMemberCallExpr *Call)
const VarTestResult & getLTest() const
unsigned succ_size() const
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
Expr * IgnoreImplicit() LLVM_READONLY
IgnoreImplicit - Skip past any implicit AST nodes which might surround this expression.
const BinaryOperator * testSourceNode() const
void remove(const CXXBindTemporaryExpr *Tmp)
Remove the temporary value from our state map.
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
PropagationInfo(const VarTestResult &VarTest)
PropagationInfo(const VarDecl *Var)
void intersectAtLoopHead(const CFGBlock *LoopHead, const CFGBlock *LoopBack, const ConsumedStateMap *LoopBackStates, ConsumedWarningsHandlerBase &WarningsHandler)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ConsumedStmtVisitor(AnalysisDeclContext &AC, ConsumedAnalyzer &Analyzer, ConsumedStateMap *StateMap)
bool isReferenceType() const
AnalysisDeclContext contains the context data for the function or method under analysis.
CFGAutomaticObjDtor - Represents C++ object destructor implicitly generated for automatic object or t...
Expr * getImplicitObjectArgument() const
Retrieves the implicit object argument for the member call.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
PropagationInfo(const BinaryOperator *Source, EffectiveOp EOp, const VarDecl *LVar, ConsumedState LTestsFor, const VarDecl *RVar, ConsumedState RTestsFor)
static void splitVarStateForIf(const IfStmt *IfNode, const VarTestResult &Test, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
PropagationInfo invertTest() const
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
bool isMoveConstructor(unsigned &TypeQuals) const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
PropagationInfo(const CXXBindTemporaryExpr *Tmp)
static ConsumedState mapReturnTypestateAttrState(const ReturnTypestateAttr *RTSAttr)
void markUnreachable()
Mark the block as unreachable.
const VarTestResult & getVarTest() const
const CXXBindTemporaryExpr * getBindTemporaryExpr() const
ConsumedState getState(const VarDecl *Var) const
Get the consumed state of a given variable.
const VarTestResult & getRTest() const
void checkParamsForReturnTypestate(SourceLocation BlameLoc, ConsumedWarningsHandlerBase &WarningsHandler) const
Warn if any of the parameters being tracked are not in the state they were declared to be in upon ret...
bool allBackEdgesVisited(const CFGBlock *CurrBlock, const CFGBlock *TargetBlock)
const VarDecl * getVarDecl() const
const CXXBindTemporaryExpr * Tmp
unsigned pred_size() const
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Temp)
A builtin binary operation expression such as "x + y" or "x <= y".
std::unique_ptr< ConsumedStateMap > getInfo(const CFGBlock *Block)
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
const Decl * getDecl() const
const Stmt * getTriggerStmt() const
static bool isConsumableType(const QualType &QT)
static void splitVarStateForIfBinOp(const PropagationInfo &PInfo, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
CXXMethodDecl * getMethodDecl() const
Retrieves the declaration of the called method.
CFGBlock - Represents a single basic block in a source-level CFG.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
virtual void warnLoopStateMismatch(SourceLocation Loc, StringRef VariableName)
Warn that a variable's state doesn't match at the entry and exit of a loop.
static bool isPointerOrRef(QualType ParamType)
bool isBackEdge(const CFGBlock *From, const CFGBlock *To)
void clearTemporaries()
Clear the TmpMap.
Expr - This represents one expression.
static StringRef stateToString(ConsumedState State)
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
const CXXBindTemporaryExpr * getTmp() const
Defines an enumeration for C++ overloaded operators.
const ParmVarDecl * getParamDecl(unsigned i) const
void VisitDeclRefExpr(const DeclRefExpr *DeclRef)
PropagationInfo(ConsumedState State)
AdjacentBlocks::const_iterator const_pred_iterator
Expr * getSubExpr() const
unsigned getBlockID() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
const ConsumedState & getState() const
bool operator!=(const ConsumedStateMap *Other) const
Tests to see if there is a mismatch in the states stored in two maps.
void checkCallability(const PropagationInfo &PInfo, const FunctionDecl *FunDecl, SourceLocation BlameLoc)
reverse_iterator rbegin()
void VisitVarDecl(const VarDecl *Var)
void VisitReturnStmt(const ReturnStmt *Ret)
void VisitDeclStmt(const DeclStmt *DelcS)
const VarDecl * getVar() const
static ConsumedState mapConsumableAttrState(const QualType QT)
CFGTerminator getTerminator()
Encodes a location in the source.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
const TemplateArgument * iterator
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
Represents a call to a member function that may be written either with member call syntax (e...
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Represents a static or instance method of a struct/union/class.
const Stmt * getStmt() const
static bool isTestingFunction(const FunctionDecl *FunDecl)
static bool isKnownState(ConsumedState State)
ArrayRef< ParmVarDecl * > parameters() const
PropagationInfo(const BinaryOperator *Source, EffectiveOp EOp, const VarTestResult <est, const VarTestResult &RTest)
void VisitMemberExpr(const MemberExpr *MExpr)
static bool isSetOnReadPtrType(const QualType &QT)
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Call)
AdjacentBlocks::const_iterator const_succ_iterator
const Decl * getSingleDecl() const
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
pred_iterator pred_begin()
void reset(ConsumedStateMap *NewStateMap)
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
static void setStateForVarOrTmp(ConsumedStateMap *StateMap, const PropagationInfo &PInfo, ConsumedState State)
detail::InMemoryDirectory::const_iterator E
A class that handles the analysis of uniqueness violations.
const Expr * getRetValue() const
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool isRValueReferenceType() const
static bool isRValueRef(QualType ParamType)
static const TypeInfo & getInfo(unsigned id)
void VisitParmVarDecl(const ParmVarDecl *Param)
ConsumedStateMap * borrowInfo(const CFGBlock *Block)
PropagationInfo(const VarDecl *Var, ConsumedState TestsFor)
virtual ~ConsumedWarningsHandlerBase()
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
void discardInfo(const CFGBlock *Block)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
static SourceLocation getFirstStmtLoc(const CFGBlock *Block)
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Defines the clang::SourceLocation class and associated facilities.
void VisitCallExpr(const CallExpr *Call)
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Temp)
Represents a C++ struct/union/class.
static bool isAutoCastType(const QualType &QT)
void VisitBinaryOperator(const BinaryOperator *BinOp)
CFGElement - Represents a top-level expression in a basic block.
bool isBackEdgeTarget(const CFGBlock *Block)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static ConsumedState mapParamTypestateAttrState(const ParamTypestateAttr *PTAttr)
static bool isCallableInState(const CallableWhenAttr *CWAttr, ConsumedState State)
A reference to a declared variable, function, enum, etc.
void VisitCXXConstructExpr(const CXXConstructExpr *Call)
bool isPointerToValue() const
const Expr * getSubExpr() const
static SourceLocation getLastStmtLoc(const CFGBlock *Block)
static ConsumedState mapSetTypestateAttrState(const SetTypestateAttr *STAttr)
PropagationInfo getInfo(const Expr *StmtNode) const
bool isConstQualified() const
Determine whether this type is const-qualified.
unsigned getNumBlockIDs() const
getNumBlockIDs - Returns the total number of BlockIDs allocated (which start at 0).
CFGTemporaryDtor - Represents C++ object destructor implicitly generated at the end of full expressio...
static ConsumedState invertConsumedUnconsumed(ConsumedState State)
ConsumedState getAsState(const ConsumedStateMap *StateMap) const
EffectiveOp testEffectiveOp() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
void intersect(const ConsumedStateMap &Other)
Merge this state map with another map.
bool isPointerType() const