30 #include "llvm/ADT/DenseMap.h" 31 #include "llvm/ADT/Optional.h" 32 #include "llvm/ADT/STLExtras.h" 33 #include "llvm/ADT/StringRef.h" 34 #include "llvm/Support/Casting.h" 35 #include "llvm/Support/ErrorHandling.h" 56 using namespace clang;
57 using namespace consumed;
65 for (
const auto &B : *Block)
67 return CS->getStmt()->getBeginLoc();
71 if (Block->succ_size() == 1 && *Block->succ_begin())
81 return StmtNode->getBeginLoc();
84 BE = Block->
rend(); BI != BE; ++BI) {
86 return CS->getStmt()->getBeginLoc();
115 llvm_unreachable(
"invalid enum");
120 for (
const auto &S : CWAttr->callableStates()) {
128 case CallableWhenAttr::Unconsumed:
132 case CallableWhenAttr::Consumed:
137 if (MappedAttrState == State)
149 return RD->hasAttr<ConsumableAttr>();
159 return RD->hasAttr<ConsumableAutoCastAttr>();
166 return RD->hasAttr<ConsumableSetOnReadAttr>();
179 llvm_unreachable(
"invalid enum");
187 return FunDecl->
hasAttr<TestTypestateAttr>();
197 const ConsumableAttr *CAttr =
200 switch (CAttr->getDefaultState()) {
203 case ConsumableAttr::Unconsumed:
205 case ConsumableAttr::Consumed:
208 llvm_unreachable(
"invalid enum");
213 switch (PTAttr->getParamState()) {
216 case ParamTypestateAttr::Unconsumed:
218 case ParamTypestateAttr::Consumed:
221 llvm_unreachable(
"invalid_enum");
226 switch (RTSAttr->getState()) {
229 case ReturnTypestateAttr::Unconsumed:
231 case ReturnTypestateAttr::Consumed:
234 llvm_unreachable(
"invalid enum");
238 switch (STAttr->getNewState()) {
241 case SetTypestateAttr::Unconsumed:
243 case SetTypestateAttr::Consumed:
246 llvm_unreachable(
"invalid_enum");
263 llvm_unreachable(
"invalid enum");
268 switch (FunDecl->
getAttr<TestTypestateAttr>()->getTestState()) {
269 case TestTypestateAttr::Unconsumed:
271 case TestTypestateAttr::Consumed:
274 llvm_unreachable(
"invalid enum");
279 struct VarTestResult {
302 } InfoType = IT_None;
322 : InfoType(IT_VarTest), VarTest(VarTest) {}
325 : InfoType(IT_VarTest) {
327 VarTest.TestsFor = TestsFor;
331 const VarTestResult <est,
const VarTestResult &RTest)
332 : InfoType(IT_BinTest) {
333 BinTest.Source = Source;
335 BinTest.LTest = LTest;
336 BinTest.RTest = RTest;
342 : 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) {}
355 : InfoType(IT_Tmp), Tmp(Tmp) {}
358 assert(InfoType == IT_State);
363 assert(InfoType == IT_VarTest);
368 assert(InfoType == IT_BinTest);
369 return BinTest.LTest;
373 assert(InfoType == IT_BinTest);
374 return BinTest.RTest;
378 assert(InfoType == IT_Var);
383 assert(InfoType == IT_Tmp);
388 assert(isVar() || isTmp() || isState());
401 assert(InfoType == IT_BinTest);
406 assert(InfoType == IT_BinTest);
407 return BinTest.Source;
410 bool isValid()
const {
return InfoType != IT_None; }
411 bool isState()
const {
return InfoType == IT_State; }
412 bool isVarTest()
const {
return InfoType == IT_VarTest; }
413 bool isBinTest()
const {
return InfoType == IT_BinTest; }
414 bool isVar()
const {
return InfoType == IT_Var; }
415 bool isTmp()
const {
return InfoType == IT_Tmp; }
418 return InfoType == IT_VarTest || InfoType == IT_BinTest;
422 return InfoType == IT_Var || InfoType == IT_Tmp;
426 assert(InfoType == IT_VarTest || InfoType == IT_BinTest);
428 if (InfoType == IT_VarTest) {
432 }
else if (InfoType == IT_BinTest) {
461 using MapType = llvm::DenseMap<const Stmt *, PropagationInfo>;
462 using PairType= std::pair<const Stmt *, PropagationInfo>;
463 using InfoEntry = MapType::iterator;
464 using ConstInfoEntry = MapType::const_iterator;
468 MapType PropagationMap;
470 InfoEntry findInfo(
const Expr *E) {
471 if (
const auto Cleanups = dyn_cast<ExprWithCleanups>(E))
472 if (!Cleanups->cleanupsHaveSideEffects())
473 E = Cleanups->getSubExpr();
477 ConstInfoEntry findInfo(
const Expr *E)
const {
478 if (
const auto Cleanups = dyn_cast<ExprWithCleanups>(E))
479 if (!Cleanups->cleanupsHaveSideEffects())
480 E = Cleanups->getSubExpr();
488 void forwardInfo(
const Expr *From,
const Expr *To);
498 bool handleCall(
const CallExpr *Call,
const Expr *ObjArg,
502 void VisitCallExpr(
const CallExpr *Call);
503 void VisitCastExpr(
const CastExpr *Cast);
509 void VisitDeclStmt(
const DeclStmt *DelcS);
511 void VisitMemberExpr(
const MemberExpr *MExpr);
515 void VisitVarDecl(
const VarDecl *Var);
518 : Analyzer(Analyzer), StateMap(StateMap) {}
521 ConstInfoEntry Entry = findInfo(StmtNode);
523 if (Entry != PropagationMap.end())
524 return Entry->second;
530 StateMap = NewStateMap;
537 void ConsumedStmtVisitor::forwardInfo(
const Expr *From,
const Expr *To) {
538 InfoEntry Entry = findInfo(From);
539 if (Entry != PropagationMap.end())
540 insertInfo(To, Entry->second);
545 void ConsumedStmtVisitor::copyInfo(
const Expr *From,
const Expr *To,
547 InfoEntry Entry = findInfo(From);
548 if (Entry != PropagationMap.end()) {
560 InfoEntry Entry = findInfo(From);
561 if (Entry != PropagationMap.end()) {
570 InfoEntry Entry = findInfo(To);
571 if (Entry != PropagationMap.end()) {
585 const CallableWhenAttr *CWAttr = FunDecl->
getAttr<CallableWhenAttr>();
595 Analyzer.WarningsHandler.warnUseInInvalidState(
604 Analyzer.WarningsHandler.warnUseOfTempInInvalidState(
615 if (isa<CXXOperatorCallExpr>(Call) && isa<CXXMethodDecl>(FunD))
619 for (
unsigned Index = Offset; Index < Call->
getNumArgs(); ++Index) {
627 InfoEntry Entry = findInfo(Call->
getArg(Index));
629 if (Entry == PropagationMap.end() || Entry->second.isTest())
634 if (ParamTypestateAttr *PTA = Param->
getAttr<ParamTypestateAttr>()) {
638 if (ParamState != ExpectedState)
639 Analyzer.WarningsHandler.warnParamTypestateMismatch(
644 if (!(Entry->second.isVar() || Entry->second.isTmp()))
650 else if (ReturnTypestateAttr *RT = Param->
getAttr<ReturnTypestateAttr>())
662 InfoEntry Entry = findInfo(ObjArg);
663 if (Entry != PropagationMap.end()) {
665 checkCallability(PInfo, FunD, Call->
getExprLoc());
667 if (SetTypestateAttr *STA = FunD->
getAttr<SetTypestateAttr>()) {
672 else if (PInfo.
isTmp()) {
678 PropagationMap.insert(PairType(Call,
685 void ConsumedStmtVisitor::propagateReturnType(
const Expr *Call,
693 if (ReturnTypestateAttr *RTA = Fun->
getAttr<ReturnTypestateAttr>())
706 InfoEntry LEntry = findInfo(BinOp->
getLHS()),
707 REntry = findInfo(BinOp->
getRHS());
709 VarTestResult LTest, RTest;
711 if (LEntry != PropagationMap.end() && LEntry->second.isVarTest()) {
712 LTest = LEntry->second.getVarTest();
718 if (REntry != PropagationMap.end() && REntry->second.isVarTest()) {
719 RTest = REntry->second.getVarTest();
725 if (!(LTest.Var ==
nullptr && RTest.Var ==
nullptr))
727 static_cast<EffectiveOp>(BinOp->
getOpcode() == BO_LOr), LTest, RTest)));
733 forwardInfo(BinOp->
getLHS(), BinOp);
753 handleCall(Call,
nullptr, FunDecl);
754 propagateReturnType(Call, FunDecl);
764 InfoEntry Entry = findInfo(Temp->
getSubExpr());
766 if (Entry != PropagationMap.end() && !Entry->second.isTest()) {
767 StateMap->setState(Temp, Entry->second.getAsState(StateMap));
781 if (ReturnTypestateAttr *RTA = Constructor->
getAttr<ReturnTypestateAttr>()) {
786 PropagationMap.insert(PairType(Call,
795 copyInfo(Call->
getArg(0), Call, NS);
810 propagateReturnType(Call, MD);
815 const auto *FunDecl = dyn_cast_or_null<FunctionDecl>(Call->
getDirectCallee());
816 if (!FunDecl)
return;
820 if (!handleCall(Call, Call->
getArg(0), FunDecl))
821 setInfo(Call->
getArg(0), CS);
825 if (
const auto *MCall = dyn_cast<CXXMemberCallExpr>(Call))
826 handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl);
828 handleCall(Call, Call->
getArg(0), FunDecl);
830 propagateReturnType(Call, FunDecl);
834 if (
const auto *Var = dyn_cast_or_null<VarDecl>(DeclRef->
getDecl()))
840 for (
const auto *DI : DeclS->
decls())
841 if (isa<VarDecl>(DI))
842 VisitVarDecl(cast<VarDecl>(DI));
845 if (
const auto *Var = dyn_cast_or_null<VarDecl>(DeclS->
getSingleDecl()))
855 forwardInfo(MExpr->
getBase(), MExpr);
862 if (
const ParamTypestateAttr *PTA = Param->
getAttr<ParamTypestateAttr>())
874 StateMap->setState(Param, ParamState);
878 ConsumedState ExpectedState = Analyzer.getExpectedReturnState();
880 if (ExpectedState !=
CS_None) {
883 if (Entry != PropagationMap.end()) {
886 if (RetState != ExpectedState)
887 Analyzer.WarningsHandler.warnReturnTypestateMismatch(
893 StateMap->checkParamsForReturnTypestate(Ret->
getBeginLoc(),
894 Analyzer.WarningsHandler);
898 InfoEntry Entry = findInfo(UOp->
getSubExpr());
899 if (Entry == PropagationMap.end())
return;
903 PropagationMap.insert(PairType(UOp, Entry->second));
907 if (Entry->second.isTest())
908 PropagationMap.insert(PairType(UOp, Entry->second.invertTest()));
921 if (VIT != PropagationMap.end()) {
926 StateMap->setState(Var, St);
942 ThenStates->
setState(Test.Var, Test.TestsFor);
946 }
else if (VarState == Test.TestsFor) {
954 const VarTestResult <est = PInfo.
getLTest(),
963 ThenStates->
setState(LTest.Var, LTest.TestsFor);
966 }
else if (LState == LTest.TestsFor &&
isKnownState(RState)) {
967 if (RState == RTest.TestsFor)
976 }
else if (LState == LTest.TestsFor) {
980 if (RState == RTest.TestsFor)
991 ThenStates->
setState(RTest.Var, RTest.TestsFor);
998 else if (RState == RTest.TestsFor)
1006 assert(CurrBlock &&
"Block pointer must not be NULL");
1007 assert(TargetBlock &&
"TargetBlock pointer must not be NULL");
1009 unsigned int CurrBlockOrder = VisitOrder[CurrBlock->
getBlockID()];
1011 PE = TargetBlock->
pred_end(); PI != PE; ++PI) {
1012 if (*PI && CurrBlockOrder < VisitOrder[(*PI)->getBlockID()] )
1020 std::unique_ptr<ConsumedStateMap> &OwnedStateMap) {
1021 assert(Block &&
"Block pointer must not be NULL");
1023 auto &Entry = StateMapsArray[Block->
getBlockID()];
1026 Entry->intersect(*StateMap);
1027 }
else if (OwnedStateMap)
1028 Entry = std::move(OwnedStateMap);
1030 Entry = llvm::make_unique<ConsumedStateMap>(*StateMap);
1034 std::unique_ptr<ConsumedStateMap> StateMap) {
1035 assert(Block &&
"Block pointer must not be NULL");
1037 auto &Entry = StateMapsArray[Block->
getBlockID()];
1040 Entry->intersect(*StateMap);
1042 Entry = std::move(StateMap);
1047 assert(Block &&
"Block pointer must not be NULL");
1048 assert(StateMapsArray[Block->
getBlockID()] &&
"Block has no block info");
1050 return StateMapsArray[Block->
getBlockID()].get();
1054 StateMapsArray[Block->
getBlockID()] =
nullptr;
1057 std::unique_ptr<ConsumedStateMap>
1059 assert(Block &&
"Block pointer must not be NULL");
1061 auto &Entry = StateMapsArray[Block->
getBlockID()];
1062 return isBackEdgeTarget(Block) ? llvm::make_unique<ConsumedStateMap>(*Entry)
1067 assert(From &&
"From block must not be NULL");
1068 assert(To &&
"From block must not be NULL");
1074 assert(Block &&
"Block pointer must not be NULL");
1081 unsigned int BlockVisitOrder = VisitOrder[Block->
getBlockID()];
1083 PE = Block->
pred_end(); PI != PE; ++PI) {
1084 if (*PI && BlockVisitOrder < VisitOrder[(*PI)->getBlockID()])
1093 for (
const auto &DM : VarMap) {
1094 if (isa<ParmVarDecl>(DM.first)) {
1095 const auto *Param = cast<ParmVarDecl>(DM.first);
1096 const ReturnTypestateAttr *RTA = Param->getAttr<ReturnTypestateAttr>();
1102 if (DM.second != ExpectedState)
1115 VarMapType::const_iterator Entry = VarMap.find(Var);
1117 if (Entry != VarMap.end())
1118 return Entry->second;
1125 TmpMapType::const_iterator Entry = TmpMap.find(Tmp);
1127 if (Entry != TmpMap.end())
1128 return Entry->second;
1136 if (this->From && this->From == Other.
From && !Other.
Reachable) {
1137 this->markUnreachable();
1141 for (
const auto &DM : Other.
VarMap) {
1142 LocalState = this->getState(DM.first);
1147 if (LocalState != DM.second)
1159 for (
const auto &DM : LoopBackStates->
VarMap) {
1160 LocalState = this->getState(DM.first);
1165 if (LocalState != DM.second) {
1168 DM.first->getNameAsString());
1174 this->Reachable =
false;
1180 VarMap[Var] =
State;
1185 TmpMap[Tmp] =
State;
1193 for (
const auto &DM : Other->
VarMap)
1194 if (this->getState(DM.first) != DM.second)
1202 if (
const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1203 ReturnType = Constructor->getThisType()->getPointeeType();
1207 if (
const ReturnTypestateAttr *RTSAttr = D->
getAttr<ReturnTypestateAttr>()) {
1209 if (!RD || !RD->
hasAttr<ConsumableAttr>()) {
1214 WarningsHandler.warnReturnTypestateForUnconsumableType(
1215 RTSAttr->getLocation(), ReturnType.
getAsString());
1216 ExpectedReturnState =
CS_None;
1221 ExpectedReturnState =
CS_None;
1226 ExpectedReturnState =
CS_None;
1229 bool ConsumedAnalyzer::splitState(
const CFGBlock *CurrBlock,
1231 std::unique_ptr<ConsumedStateMap> FalseStates(
1235 if (
const auto *IfNode =
1237 const Expr *Cond = IfNode->getCond();
1239 PInfo = Visitor.getInfo(Cond);
1240 if (!PInfo.
isValid() && isa<BinaryOperator>(Cond))
1241 PInfo = Visitor.getInfo(cast<BinaryOperator>(Cond)->getRHS());
1244 CurrStates->setSource(Cond);
1245 FalseStates->setSource(Cond);
1255 }
else if (
const auto *BinOp =
1257 PInfo = Visitor.getInfo(BinOp->getLHS());
1259 if ((BinOp = dyn_cast_or_null<BinaryOperator>(BinOp->getLHS()))) {
1260 PInfo = Visitor.getInfo(BinOp->getRHS());
1269 CurrStates->setSource(BinOp);
1270 FalseStates->setSource(BinOp);
1272 const VarTestResult &Test = PInfo.
getVarTest();
1275 if (BinOp->getOpcode() == BO_LAnd) {
1277 CurrStates->setState(Test.Var, Test.TestsFor);
1279 CurrStates->markUnreachable();
1281 }
else if (BinOp->getOpcode() == BO_LOr) {
1283 FalseStates->setState(Test.Var,
1285 else if (VarState == Test.TestsFor)
1286 FalseStates->markUnreachable();
1295 BlockInfo.addInfo(*SI, std::move(CurrStates));
1297 CurrStates =
nullptr;
1300 BlockInfo.addInfo(*SI, std::move(FalseStates));
1306 const auto *D = dyn_cast_or_null<FunctionDecl>(AC.
getDecl());
1314 determineExpectedReturnState(AC, D);
1321 CurrStates = llvm::make_unique<ConsumedStateMap>();
1329 for (
const auto *CurrBlock : *SortedGraph) {
1331 CurrStates = BlockInfo.getInfo(CurrBlock);
1335 }
else if (!CurrStates->isReachable()) {
1336 CurrStates =
nullptr;
1340 Visitor.
reset(CurrStates.get());
1343 for (
const auto &B : *CurrBlock) {
1344 switch (B.getKind()) {
1356 CurrStates->remove(BTE);
1378 if (!splitState(CurrBlock, Visitor)) {
1379 CurrStates->setSource(
nullptr);
1381 if (CurrBlock->succ_size() > 1 ||
1382 (CurrBlock->succ_size() == 1 &&
1383 (*CurrBlock->succ_begin())->pred_size() > 1)) {
1385 auto *RawState = CurrStates.get();
1388 SE = CurrBlock->succ_end(); SI != SE; ++SI) {
1389 if (*SI ==
nullptr)
continue;
1391 if (BlockInfo.isBackEdge(CurrBlock, *SI)) {
1392 BlockInfo.borrowInfo(*SI)->intersectAtLoopHead(
1393 *SI, CurrBlock, RawState, WarningsHandler);
1395 if (BlockInfo.allBackEdgesVisited(CurrBlock, *SI))
1396 BlockInfo.discardInfo(*SI);
1398 BlockInfo.addInfo(*SI, RawState, CurrStates);
1402 CurrStates =
nullptr;
1408 CurrStates->checkParamsForReturnTypestate(D->
getLocation(),
1413 CurrStates =
nullptr;
1415 WarningsHandler.emitDiagnostics();
void VisitDeclStmt(const DeclStmt *DelcS)
A call to an overloaded operator written using operator syntax.
bool isCallToStdMove() const
Represents a function declaration or definition.
const ConsumedState & getState() const
SourceLocation getBeginLoc() const
A (possibly-)qualified type.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
AdjacentBlocks::const_iterator const_pred_iterator
const Stmt * getStmt() const
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
succ_iterator succ_begin()
Stmt - This represents one statement.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
IfStmt - This represents an if/then/else.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
C Language Family Type Representation.
QualType getThisType() const
Returns the type of the this pointer.
unsigned getBlockID() const
Expr * getImplicitObjectArgument() const
Retrieves the implicit object argument for the member call.
virtual void warnParamReturnTypestateMismatch(SourceLocation Loc, StringRef VariableName, StringRef ExpectedState, StringRef ObservedState)
Warn about parameter typestate mismatches upon return.
Represents a call to a C++ constructor.
QualType getCallResultType() const
Determine the type of an expression that calls this function.
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
bool isBackEdge(const CFGBlock *From, const CFGBlock *To)
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)
unsigned succ_size() const
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
void VisitBinaryOperator(const BinaryOperator *BinOp)
Represents a variable declaration or definition.
ASTContext & getASTContext() const
static void splitVarStateForIf(const IfStmt *IfNode, const VarTestResult &Test, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
Expr * IgnoreImplicit() LLVM_READONLY
IgnoreImplicit - Skip past any implicit AST nodes which might surround this expression.
const CXXBindTemporaryExpr * getTmp() const
const Stmt * getTriggerStmt() const
void VisitParmVarDecl(const ParmVarDecl *Param)
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
PropagationInfo(const VarTestResult &VarTest)
PropagationInfo(const VarDecl *Var)
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
ConsumedState getState(const VarDecl *Var) const
Get the consumed state of a given variable.
AnalysisDeclContext contains the context data for the function or method under analysis.
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
const BinaryOperator * testSourceNode() const
const VarTestResult & getRTest() const
bool isReferenceType() const
PropagationInfo(const BinaryOperator *Source, EffectiveOp EOp, const VarDecl *LVar, ConsumedState LTestsFor, const VarDecl *RVar, ConsumedState RTestsFor)
PropagationInfo(const CXXBindTemporaryExpr *Tmp)
static ConsumedState mapReturnTypestateAttrState(const ReturnTypestateAttr *RTSAttr)
ArrayRef< ParmVarDecl * > parameters() const
AdjacentBlocks::const_iterator const_succ_iterator
EffectiveOp testEffectiveOp() const
bool operator!=(const ConsumedStateMap *Other) const
Tests to see if there is a mismatch in the states stored in two maps.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
ConsumedStmtVisitor(ConsumedAnalyzer &Analyzer, ConsumedStateMap *StateMap)
void intersectAtLoopHead(const CFGBlock *LoopHead, const CFGBlock *LoopBack, const ConsumedStateMap *LoopBackStates, ConsumedWarningsHandlerBase &WarningsHandler)
const CXXBindTemporaryExpr * Tmp
const VarTestResult & getVarTest() const
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
A builtin binary operation expression such as "x + y" or "x <= y".
bool isRValueReferenceType() const
const VarDecl * getVarDecl() const
bool isBackEdgeTarget(const CFGBlock *Block)
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
void VisitCXXMemberCallExpr(const CXXMemberCallExpr *Call)
static void splitVarStateForIfBinOp(const PropagationInfo &PInfo, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
static bool isConsumableType(const QualType &QT)
void remove(const CXXBindTemporaryExpr *Tmp)
Remove the temporary value from our state map.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
const CXXBindTemporaryExpr * getBindTemporaryExpr() const
Represents a single basic block in a source-level CFG.
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)
This represents one expression.
static StringRef stateToString(ConsumedState State)
void discardInfo(const CFGBlock *Block)
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
std::unique_ptr< ConsumedStateMap > getInfo(const CFGBlock *Block)
void VisitMemberExpr(const MemberExpr *MExpr)
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to...
const VarDecl * getVar() const
Defines an enumeration for C++ overloaded operators.
bool allBackEdgesVisited(const CFGBlock *CurrBlock, const CFGBlock *TargetBlock)
void setState(const VarDecl *Var, ConsumedState State)
Set the consumed state of a given variable.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
void VisitCastExpr(const CastExpr *Cast)
PropagationInfo(ConsumedState State)
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.
CXXMethodDecl * getMethodDecl() const
Retrieves the declaration of the called method.
void VisitReturnStmt(const ReturnStmt *Ret)
const Expr * getSubExpr() const
reverse_iterator rbegin()
SourceLocation getEndLoc() const LLVM_READONLY
bool isConstQualified() const
Determine whether this type is const-qualified.
void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, std::unique_ptr< ConsumedStateMap > &OwnedStateMap)
static ConsumedState mapConsumableAttrState(const QualType QT)
static void setStateForVarOrTmp(ConsumedStateMap *StateMap, const PropagationInfo &PInfo, ConsumedState State)
PropagationInfo invertTest() const
CFGTerminator getTerminator()
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...
Encodes a location in the source.
Expr * getSubExpr() const
void VisitDeclRefExpr(const DeclRefExpr *DeclRef)
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
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.
static bool isTestingFunction(const FunctionDecl *FunDecl)
static bool isKnownState(ConsumedState State)
const ParmVarDecl * getParamDecl(unsigned i) const
PropagationInfo(const BinaryOperator *Source, EffectiveOp EOp, const VarTestResult <est, const VarTestResult &RTest)
const Decl * getDecl() const
bool isPointerToValue() const
void VisitUnaryOperator(const UnaryOperator *UOp)
static bool isSetOnReadPtrType(const QualType &QT)
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
const VarTestResult & getLTest() const
void intersect(const ConsumedStateMap &Other)
Merge this state map with another map.
void VisitVarDecl(const VarDecl *Var)
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Call)
pred_iterator pred_begin()
void checkCallability(const PropagationInfo &PInfo, const FunctionDecl *FunDecl, SourceLocation BlameLoc)
void reset(ConsumedStateMap *NewStateMap)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
void clearTemporaries()
Clear the TmpMap.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Temp)
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
const Expr * getInit() const
unsigned pred_size() const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool isMoveConstructor(unsigned &TypeQuals) const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
const Decl * getSingleDecl() const
A class that handles the analysis of uniqueness violations.
ConsumedStateMap * borrowInfo(const CFGBlock *Block)
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
static bool isRValueRef(QualType ParamType)
void markUnreachable()
Mark the block as unreachable.
static const TypeInfo & getInfo(unsigned id)
PropagationInfo getInfo(const Expr *StmtNode) const
PropagationInfo(const VarDecl *Var, ConsumedState TestsFor)
virtual ~ConsumedWarningsHandlerBase()
Expr * getArg(unsigned Arg)
Return the specified argument.
void VisitCallExpr(const CallExpr *Call)
ConsumedState getAsState(const ConsumedStateMap *StateMap) const
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.
Defines the clang::SourceLocation class and associated facilities.
void VisitCXXConstructExpr(const CXXConstructExpr *Call)
Represents a C++ struct/union/class.
bool handleCall(const CallExpr *Call, const Expr *ObjArg, const FunctionDecl *FunD)
static bool isAutoCastType(const QualType &QT)
void run(AnalysisDeclContext &AC)
Check a function's CFG for consumed violations.
Represents a top-level expression in a basic block.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
RetTy Visit(PTR(Stmt) S, ParamTys... P)
static ConsumedState mapParamTypestateAttrState(const ParamTypestateAttr *PTAttr)
static bool isCallableInState(const CallableWhenAttr *CWAttr, ConsumedState State)
A reference to a declared variable, function, enum, etc.
bool isPointerType() const
static SourceLocation getLastStmtLoc(const CFGBlock *Block)
static ConsumedState mapSetTypestateAttrState(const SetTypestateAttr *STAttr)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
SourceLocation getReturnLoc() const
SourceLocation getLocation() const
static ConsumedState invertConsumedUnconsumed(ConsumedState State)
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Temp)