29 #include "llvm/ADT/DenseMap.h" 48 using namespace clang;
49 using namespace consumed;
57 for (
const auto &B : *Block)
59 return CS->getStmt()->getLocStart();
63 if (Block->succ_size() == 1 && *Block->succ_begin())
73 return StmtNode->getLocStart();
76 BE = Block->
rend(); BI != BE; ++BI) {
78 return CS->getStmt()->getLocStart();
107 llvm_unreachable(
"invalid enum");
113 for (
const auto &S : CWAttr->callableStates()) {
121 case CallableWhenAttr::Unconsumed:
125 case CallableWhenAttr::Consumed:
130 if (MappedAttrState == State)
143 return RD->hasAttr<ConsumableAttr>();
153 return RD->hasAttr<ConsumableAutoCastAttr>();
160 return RD->hasAttr<ConsumableSetOnReadAttr>();
174 llvm_unreachable(
"invalid enum");
182 return FunDecl->
hasAttr<TestTypestateAttr>();
192 const ConsumableAttr *CAttr =
195 switch (CAttr->getDefaultState()) {
198 case ConsumableAttr::Unconsumed:
200 case ConsumableAttr::Consumed:
203 llvm_unreachable(
"invalid enum");
208 switch (PTAttr->getParamState()) {
211 case ParamTypestateAttr::Unconsumed:
213 case ParamTypestateAttr::Consumed:
216 llvm_unreachable(
"invalid_enum");
221 switch (RTSAttr->getState()) {
224 case ReturnTypestateAttr::Unconsumed:
226 case ReturnTypestateAttr::Consumed:
229 llvm_unreachable(
"invalid enum");
233 switch (STAttr->getNewState()) {
236 case SetTypestateAttr::Unconsumed:
238 case SetTypestateAttr::Consumed:
241 llvm_unreachable(
"invalid_enum");
258 llvm_unreachable(
"invalid enum");
263 switch (FunDecl->
getAttr<TestTypestateAttr>()->getTestState()) {
264 case TestTypestateAttr::Unconsumed:
266 case TestTypestateAttr::Consumed:
269 llvm_unreachable(
"invalid enum");
273 struct VarTestResult {
316 : InfoType(IT_VarTest), VarTest(VarTest) {}
319 : InfoType(IT_VarTest) {
322 VarTest.TestsFor = TestsFor;
326 const VarTestResult <est,
const VarTestResult &RTest)
327 : InfoType(IT_BinTest) {
329 BinTest.Source = Source;
331 BinTest.LTest = LTest;
332 BinTest.RTest = RTest;
338 : InfoType(IT_BinTest) {
340 BinTest.Source = Source;
342 BinTest.LTest.Var = LVar;
343 BinTest.LTest.TestsFor = LTestsFor;
344 BinTest.RTest.Var = RVar;
345 BinTest.RTest.TestsFor = RTestsFor;
349 : InfoType(IT_State), State(State) {}
353 : InfoType(IT_Tmp), Tmp(Tmp) {}
356 assert(InfoType == IT_State);
361 assert(InfoType == IT_VarTest);
366 assert(InfoType == IT_BinTest);
367 return BinTest.LTest;
371 assert(InfoType == IT_BinTest);
372 return BinTest.RTest;
376 assert(InfoType == IT_Var);
381 assert(InfoType == IT_Tmp);
386 assert(isVar() || isTmp() || isState());
399 assert(InfoType == IT_BinTest);
404 assert(InfoType == IT_BinTest);
405 return BinTest.Source;
408 inline bool isValid()
const {
return InfoType != IT_None; }
409 inline bool isState()
const {
return InfoType == IT_State; }
410 inline bool isVarTest()
const {
return InfoType == IT_VarTest; }
411 inline bool isBinTest()
const {
return InfoType == IT_BinTest; }
412 inline bool isVar()
const {
return InfoType == IT_Var; }
413 inline bool isTmp()
const {
return InfoType == IT_Tmp; }
416 return InfoType == IT_VarTest || InfoType == IT_BinTest;
420 return InfoType == IT_Var || InfoType == IT_Tmp;
424 assert(InfoType == IT_VarTest || InfoType == IT_BinTest);
426 if (InfoType == IT_VarTest) {
430 }
else if (InfoType == IT_BinTest) {
455 typedef llvm::DenseMap<const Stmt *, PropagationInfo> MapType;
456 typedef std::pair<const Stmt *, PropagationInfo> PairType;
457 typedef MapType::iterator InfoEntry;
458 typedef MapType::const_iterator ConstInfoEntry;
463 MapType PropagationMap;
465 InfoEntry findInfo(
const Expr *E) {
466 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(E))
467 if (!Cleanups->cleanupsHaveSideEffects())
468 E = Cleanups->getSubExpr();
471 ConstInfoEntry findInfo(
const Expr *E)
const {
472 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(E))
473 if (!Cleanups->cleanupsHaveSideEffects())
474 E = Cleanups->getSubExpr();
481 void forwardInfo(
const Expr *From,
const Expr *To);
491 bool handleCall(
const CallExpr *Call,
const Expr *ObjArg,
495 void VisitCallExpr(
const CallExpr *Call);
496 void VisitCastExpr(
const CastExpr *Cast);
502 void VisitDeclStmt(
const DeclStmt *DelcS);
504 void VisitMemberExpr(
const MemberExpr *MExpr);
508 void VisitVarDecl(
const VarDecl *Var);
512 : AC(AC), Analyzer(Analyzer), StateMap(StateMap) {}
515 ConstInfoEntry Entry = findInfo(StmtNode);
517 if (Entry != PropagationMap.end())
518 return Entry->second;
524 StateMap = NewStateMap;
529 void ConsumedStmtVisitor::forwardInfo(
const Expr *From,
const Expr *To) {
530 InfoEntry Entry = findInfo(From);
531 if (Entry != PropagationMap.end())
532 insertInfo(To, Entry->second);
538 void ConsumedStmtVisitor::copyInfo(
const Expr *From,
const Expr *To,
540 InfoEntry Entry = findInfo(From);
541 if (Entry != PropagationMap.end()) {
554 InfoEntry Entry = findInfo(From);
555 if (Entry != PropagationMap.end()) {
565 InfoEntry Entry = findInfo(To);
566 if (Entry != PropagationMap.end()) {
582 const CallableWhenAttr *CWAttr = FunDecl->
getAttr<CallableWhenAttr>();
592 Analyzer.WarningsHandler.warnUseInInvalidState(
602 Analyzer.WarningsHandler.warnUseOfTempInInvalidState(
614 if (isa<CXXOperatorCallExpr>(Call) && isa<CXXMethodDecl>(FunD))
618 for (
unsigned Index = Offset; Index < Call->
getNumArgs(); ++Index) {
626 InfoEntry Entry = findInfo(Call->
getArg(Index));
628 if (Entry == PropagationMap.end() || Entry->second.isTest())
633 if (ParamTypestateAttr *PTA = Param->
getAttr<ParamTypestateAttr>()) {
637 if (ParamState != ExpectedState)
638 Analyzer.WarningsHandler.warnParamTypestateMismatch(
643 if (!(Entry->second.isVar() || Entry->second.isTmp()))
649 else if (ReturnTypestateAttr *RT = Param->
getAttr<ReturnTypestateAttr>())
661 InfoEntry Entry = findInfo(ObjArg);
662 if (Entry != PropagationMap.end()) {
664 checkCallability(PInfo, FunD, Call->
getExprLoc());
666 if (SetTypestateAttr *STA = FunD->
getAttr<SetTypestateAttr>()) {
671 else if (PInfo.
isTmp()) {
677 PropagationMap.insert(PairType(Call,
685 void ConsumedStmtVisitor::propagateReturnType(
const Expr *Call,
693 if (ReturnTypestateAttr *RTA = Fun->
getAttr<ReturnTypestateAttr>())
707 InfoEntry LEntry = findInfo(BinOp->
getLHS()),
708 REntry = findInfo(BinOp->
getRHS());
710 VarTestResult LTest, RTest;
712 if (LEntry != PropagationMap.end() && LEntry->second.isVarTest()) {
713 LTest = LEntry->second.getVarTest();
720 if (REntry != PropagationMap.end() && REntry->second.isVarTest()) {
721 RTest = REntry->second.getVarTest();
728 if (!(LTest.Var ==
nullptr && RTest.Var ==
nullptr))
730 static_cast<EffectiveOp>(BinOp->
getOpcode() == BO_LOr), LTest, RTest)));
737 forwardInfo(BinOp->
getLHS(), BinOp);
757 handleCall(Call,
nullptr, FunDecl);
758 propagateReturnType(Call, FunDecl);
768 InfoEntry Entry = findInfo(Temp->
getSubExpr());
770 if (Entry != PropagationMap.end() && !Entry->second.isTest()) {
771 StateMap->setState(Temp, Entry->second.getAsState(StateMap));
786 if (ReturnTypestateAttr *RTA = Constructor->
getAttr<ReturnTypestateAttr>()) {
791 PropagationMap.insert(PairType(Call,
800 copyInfo(Call->
getArg(0), Call, NS);
816 propagateReturnType(Call, MD);
825 if (!FunDecl)
return;
829 if (!handleCall(Call, Call->
getArg(0), FunDecl))
830 setInfo(Call->
getArg(0), CS);
835 handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl);
837 handleCall(Call, Call->
getArg(0), FunDecl);
839 propagateReturnType(Call, FunDecl);
843 if (
const VarDecl *Var = dyn_cast_or_null<VarDecl>(DeclRef->
getDecl()))
849 for (
const auto *DI : DeclS->
decls())
850 if (isa<VarDecl>(DI))
851 VisitVarDecl(cast<VarDecl>(DI));
865 forwardInfo(MExpr->
getBase(), MExpr);
873 if (
const ParamTypestateAttr *PTA = Param->
getAttr<ParamTypestateAttr>())
885 StateMap->setState(Param, ParamState);
889 ConsumedState ExpectedState = Analyzer.getExpectedReturnState();
891 if (ExpectedState !=
CS_None) {
894 if (Entry != PropagationMap.end()) {
897 if (RetState != ExpectedState)
898 Analyzer.WarningsHandler.warnReturnTypestateMismatch(
904 StateMap->checkParamsForReturnTypestate(Ret->
getLocStart(),
905 Analyzer.WarningsHandler);
909 InfoEntry Entry = findInfo(UOp->
getSubExpr());
910 if (Entry == PropagationMap.end())
return;
914 PropagationMap.insert(PairType(UOp, Entry->second));
918 if (Entry->second.isTest())
919 PropagationMap.insert(PairType(UOp, Entry->second.invertTest()));
932 if (VIT != PropagationMap.end()) {
937 StateMap->setState(Var, St);
957 ThenStates->
setState(Test.Var, Test.TestsFor);
963 }
else if (VarState == Test.TestsFor) {
971 const VarTestResult <est = PInfo.
getLTest(),
980 ThenStates->
setState(LTest.Var, LTest.TestsFor);
985 }
else if (LState == LTest.TestsFor &&
isKnownState(RState)) {
986 if (RState == RTest.TestsFor)
997 }
else if (LState == LTest.TestsFor) {
1003 if (RState == RTest.TestsFor)
1014 ThenStates->
setState(RTest.Var, RTest.TestsFor);
1022 else if (RState == RTest.TestsFor)
1031 assert(CurrBlock &&
"Block pointer must not be NULL");
1032 assert(TargetBlock &&
"TargetBlock pointer must not be NULL");
1034 unsigned int CurrBlockOrder = VisitOrder[CurrBlock->
getBlockID()];
1036 PE = TargetBlock->
pred_end(); PI != PE; ++PI) {
1037 if (*PI && CurrBlockOrder < VisitOrder[(*PI)->getBlockID()] )
1045 std::unique_ptr<ConsumedStateMap> &OwnedStateMap) {
1047 assert(Block &&
"Block pointer must not be NULL");
1049 auto &Entry = StateMapsArray[Block->
getBlockID()];
1052 Entry->intersect(*StateMap);
1053 }
else if (OwnedStateMap)
1054 Entry = std::move(OwnedStateMap);
1056 Entry = llvm::make_unique<ConsumedStateMap>(*StateMap);
1060 std::unique_ptr<ConsumedStateMap> StateMap) {
1062 assert(Block &&
"Block pointer must not be NULL");
1064 auto &Entry = StateMapsArray[Block->
getBlockID()];
1067 Entry->intersect(*StateMap);
1069 Entry = std::move(StateMap);
1074 assert(Block &&
"Block pointer must not be NULL");
1075 assert(StateMapsArray[Block->
getBlockID()] &&
"Block has no block info");
1077 return StateMapsArray[Block->
getBlockID()].get();
1081 StateMapsArray[Block->
getBlockID()] =
nullptr;
1084 std::unique_ptr<ConsumedStateMap>
1086 assert(Block &&
"Block pointer must not be NULL");
1088 auto &Entry = StateMapsArray[Block->
getBlockID()];
1089 return isBackEdgeTarget(Block) ? llvm::make_unique<ConsumedStateMap>(*Entry)
1094 assert(From &&
"From block must not be NULL");
1095 assert(To &&
"From block must not be NULL");
1101 assert(Block &&
"Block pointer must not be NULL");
1108 unsigned int BlockVisitOrder = VisitOrder[Block->
getBlockID()];
1110 PE = Block->
pred_end(); PI != PE; ++PI) {
1111 if (*PI && BlockVisitOrder < VisitOrder[(*PI)->getBlockID()])
1120 for (
const auto &DM : VarMap) {
1121 if (isa<ParmVarDecl>(DM.first)) {
1122 const ParmVarDecl *Param = cast<ParmVarDecl>(DM.first);
1123 const ReturnTypestateAttr *RTA = Param->
getAttr<ReturnTypestateAttr>();
1129 if (DM.second != ExpectedState)
1142 VarMapType::const_iterator Entry = VarMap.find(Var);
1144 if (Entry != VarMap.end())
1145 return Entry->second;
1152 TmpMapType::const_iterator Entry = TmpMap.find(Tmp);
1154 if (Entry != TmpMap.end())
1155 return Entry->second;
1163 if (this->From && this->From == Other.
From && !Other.
Reachable) {
1164 this->markUnreachable();
1168 for (
const auto &DM : Other.
VarMap) {
1169 LocalState = this->getState(DM.first);
1174 if (LocalState != DM.second)
1186 for (
const auto &DM : LoopBackStates->
VarMap) {
1187 LocalState = this->getState(DM.first);
1192 if (LocalState != DM.second) {
1195 DM.first->getNameAsString());
1201 this->Reachable =
false;
1207 VarMap[Var] =
State;
1212 TmpMap[Tmp] =
State;
1220 for (
const auto &DM : Other->
VarMap)
1221 if (this->getState(DM.first) != DM.second)
1231 ReturnType = Constructor->getThisType(CurrContext)->getPointeeType();
1235 if (
const ReturnTypestateAttr *RTSAttr = D->
getAttr<ReturnTypestateAttr>()) {
1237 if (!RD || !RD->
hasAttr<ConsumableAttr>()) {
1242 WarningsHandler.warnReturnTypestateForUnconsumableType(
1243 RTSAttr->getLocation(), ReturnType.
getAsString());
1244 ExpectedReturnState =
CS_None;
1249 ExpectedReturnState =
CS_None;
1254 ExpectedReturnState =
CS_None;
1257 bool ConsumedAnalyzer::splitState(
const CFGBlock *CurrBlock,
1260 std::unique_ptr<ConsumedStateMap> FalseStates(
1264 if (
const IfStmt *IfNode =
1267 const Expr *Cond = IfNode->getCond();
1269 PInfo = Visitor.getInfo(Cond);
1270 if (!PInfo.
isValid() && isa<BinaryOperator>(Cond))
1271 PInfo = Visitor.getInfo(cast<BinaryOperator>(Cond)->getRHS());
1274 CurrStates->setSource(Cond);
1275 FalseStates->setSource(Cond);
1291 PInfo = Visitor.getInfo(BinOp->getLHS());
1293 if ((BinOp = dyn_cast_or_null<BinaryOperator>(BinOp->getLHS()))) {
1294 PInfo = Visitor.getInfo(BinOp->getRHS());
1304 CurrStates->setSource(BinOp);
1305 FalseStates->setSource(BinOp);
1307 const VarTestResult &Test = PInfo.
getVarTest();
1310 if (BinOp->getOpcode() == BO_LAnd) {
1312 CurrStates->setState(Test.Var, Test.TestsFor);
1314 CurrStates->markUnreachable();
1316 }
else if (BinOp->getOpcode() == BO_LOr) {
1318 FalseStates->setState(Test.Var,
1320 else if (VarState == Test.TestsFor)
1321 FalseStates->markUnreachable();
1331 BlockInfo.addInfo(*SI, std::move(CurrStates));
1333 CurrStates =
nullptr;
1336 BlockInfo.addInfo(*SI, std::move(FalseStates));
1350 determineExpectedReturnState(AC, D);
1357 CurrStates = llvm::make_unique<ConsumedStateMap>();
1365 for (
const auto *CurrBlock : *SortedGraph) {
1367 CurrStates = BlockInfo.getInfo(CurrBlock);
1372 }
else if (!CurrStates->isReachable()) {
1373 CurrStates =
nullptr;
1377 Visitor.
reset(CurrStates.get());
1380 for (
const auto &B : *CurrBlock) {
1381 switch (B.getKind()) {
1393 CurrStates->remove(BTE);
1415 if (!splitState(CurrBlock, Visitor)) {
1416 CurrStates->setSource(
nullptr);
1418 if (CurrBlock->succ_size() > 1 ||
1419 (CurrBlock->succ_size() == 1 &&
1420 (*CurrBlock->succ_begin())->pred_size() > 1)) {
1422 auto *RawState = CurrStates.get();
1425 SE = CurrBlock->succ_end(); SI != SE; ++SI) {
1427 if (*SI ==
nullptr)
continue;
1429 if (BlockInfo.isBackEdge(CurrBlock, *SI)) {
1430 BlockInfo.borrowInfo(*SI)->intersectAtLoopHead(
1431 *SI, CurrBlock, RawState, WarningsHandler);
1433 if (BlockInfo.allBackEdgesVisited(CurrBlock, *SI))
1434 BlockInfo.discardInfo(*SI);
1436 BlockInfo.addInfo(*SI, RawState, CurrStates);
1440 CurrStates =
nullptr;
1446 CurrStates->checkParamsForReturnTypestate(D->
getLocation(),
1451 CurrStates =
nullptr;
1453 WarningsHandler.emitDiagnostics();
A call to an overloaded operator written using operator syntax.
Defines the clang::ASTContext interface.
bool isCallToStdMove() const
An instance of this class is created to represent a function declaration or definition.
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.
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.
void VisitCastExpr(const CastExpr *Cast)
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.
void addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap, std::unique_ptr< ConsumedStateMap > &OwnedStateMap)
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.
void VisitUnaryOperator(const UnaryOperator *UOp)
bool handleCall(const CallExpr *Call, const Expr *ObjArg, const FunctionDecl *FunD)
Represents a call to a C++ constructor.
void run(AnalysisDeclContext &AC)
Check a function's CFG for consumed violations.
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...
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)
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 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...
void VisitCXXMemberCallExpr(const CXXMemberCallExpr *Call)
ASTContext & getASTContext() const
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 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)
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
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)
AnalysisDeclContext contains the context data for the function or method under analysis.
CFGAutomaticObjDtor - Represents C++ object destructor implicitly generated for automatic object or t...
const Expr * getRetValue() const
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)
static void splitVarStateForIf(const IfStmt *IfNode, const VarTestResult &Test, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
PropagationInfo(const CXXBindTemporaryExpr *Tmp)
static ConsumedState mapReturnTypestateAttrState(const ReturnTypestateAttr *RTSAttr)
void markUnreachable()
Mark the block as unreachable.
ArrayRef< ParmVarDecl * > parameters() const
AdjacentBlocks::const_iterator const_succ_iterator
bool allBackEdgesVisited(const CFGBlock *CurrBlock, const CFGBlock *TargetBlock)
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
EffectiveOp testEffectiveOp() const
const CXXBindTemporaryExpr * Tmp
const VarTestResult & getVarTest() 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".
bool isRValueReferenceType() const
std::unique_ptr< ConsumedStateMap > getInfo(const CFGBlock *Block)
const VarDecl * getVarDecl() const
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents binding an expression to a temporary.
static bool isConsumableType(const QualType &QT)
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...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
static void splitVarStateForIfBinOp(const PropagationInfo &PInfo, ConsumedStateMap *ThenStates, ConsumedStateMap *ElseStates)
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
SourceLocation getLocEnd() const LLVM_READONLY
const CXXBindTemporaryExpr * getBindTemporaryExpr() const
CFGBlock - 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)
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 CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
const VarDecl * getVar() const
Defines an enumeration for C++ overloaded operators.
void VisitDeclRefExpr(const DeclRefExpr *DeclRef)
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.
const Expr * getSubExpr() const
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)
bool isConstQualified() const
Determine whether this type is const-qualified.
static ConsumedState mapConsumableAttrState(const QualType QT)
PropagationInfo invertTest() const
CFGTerminator getTerminator()
Encodes a location in the source.
Expr * getSubExpr() const
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
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 VisitMemberExpr(const MemberExpr *MExpr)
static bool isSetOnReadPtrType(const QualType &QT)
unsigned getNumBlockIDs() const
getNumBlockIDs - Returns the total number of BlockIDs allocated (which start at 0).
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Call)
const VarTestResult & getLTest() 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)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
static void setStateForVarOrTmp(ConsumedStateMap *StateMap, const PropagationInfo &PInfo, ConsumedState State)
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.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
static bool isRValueRef(QualType ParamType)
static const TypeInfo & getInfo(unsigned id)
PropagationInfo getInfo(const Expr *StmtNode) const
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.
void discardInfo(const CFGBlock *Block)
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 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]).
RetTy Visit(PTR(Stmt) S, ParamTys... P)
static ConsumedState mapParamTypestateAttrState(const ParamTypestateAttr *PTAttr)
ConsumedState getState(const VarDecl *Var) const
Get the consumed state of a given variable.
static bool isCallableInState(const CallableWhenAttr *CWAttr, ConsumedState State)
A reference to a declared variable, function, enum, etc.
void VisitCXXConstructExpr(const CXXConstructExpr *Call)
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.
CFGTemporaryDtor - Represents C++ object destructor implicitly generated at the end of full expressio...
SourceLocation getReturnLoc() const
SourceLocation getLocation() const
static ConsumedState invertConsumedUnconsumed(ConsumedState State)
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
void intersect(const ConsumedStateMap &Other)
Merge this state map with another map.