void checkCallability(const PropagationInfo &PInfo,
const FunctionDecl *FunDecl,
SourceLocation BlameLoc);
-
- using ArgRange = llvm::iterator_range<CallExpr::const_arg_iterator>;
- bool handleCall(const Expr *Call, const Expr *ObjArg,
- ArgRange args, const FunctionDecl *FunD);
+ bool handleCall(const CallExpr *Call, const Expr *ObjArg,
+ const FunctionDecl *FunD);
void VisitBinaryOperator(const BinaryOperator *BinOp);
void VisitCallExpr(const CallExpr *Call);
// Factors out common behavior for function, method, and operator calls.
// Check parameters and set parameter state if necessary.
// Returns true if the state of ObjArg is set, or false otherwise.
-bool ConsumedStmtVisitor::handleCall(const Expr *Call,
- const Expr *ObjArg,
- ArgRange Args,
+bool ConsumedStmtVisitor::handleCall(const CallExpr *Call, const Expr *ObjArg,
const FunctionDecl *FunD) {
+ unsigned Offset = 0;
+ if (isa<CXXOperatorCallExpr>(Call) && isa<CXXMethodDecl>(FunD))
+ Offset = 1; // first argument is 'this'
+
// check explicit parameters
- unsigned Index = 0;
- for (const Expr *Arg : Args) {
+ for (unsigned Index = Offset; Index < Call->getNumArgs(); ++Index) {
// Skip variable argument lists.
- if (Index >= FunD->getNumParams())
+ if (Index - Offset >= FunD->getNumParams())
break;
- const ParmVarDecl *Param = FunD->getParamDecl(Index++);
+ const ParmVarDecl *Param = FunD->getParamDecl(Index - Offset);
QualType ParamType = Param->getType();
- InfoEntry Entry = findInfo(Arg);
+ InfoEntry Entry = findInfo(Call->getArg(Index));
if (Entry == PropagationMap.end() || Entry->second.isTest())
continue;
if (ParamState != ExpectedState)
Analyzer.WarningsHandler.warnParamTypestateMismatch(
- Arg->getExprLoc(),
+ Call->getArg(Index)->getExprLoc(),
stateToString(ExpectedState), stateToString(ParamState));
}
return;
}
- handleCall(Call, nullptr, Call->arguments(), FunDecl);
+ handleCall(Call, nullptr, FunDecl);
propagateReturnType(Call, FunDecl);
}
if (!MD)
return;
- handleCall(Call, Call->getImplicitObjectArgument(), Call->arguments(), MD);
+ handleCall(Call, Call->getImplicitObjectArgument(), MD);
propagateReturnType(Call, MD);
}
const CXXOperatorCallExpr *Call) {
const auto *FunDecl = dyn_cast_or_null<FunctionDecl>(Call->getDirectCallee());
if (!FunDecl) return;
- ArgRange Args = Call->arguments();
if (Call->getOperator() == OO_Equal) {
- ConsumedState CS = getInfo(llvm::index(Args, 1));
- if (!handleCall(Call, llvm::index(Args, 0), llvm::drop_begin(Args, 1),
- FunDecl))
- setInfo(llvm::index(Args, 0), CS);
+ ConsumedState CS = getInfo(Call->getArg(1));
+ if (!handleCall(Call, Call->getArg(0), FunDecl))
+ setInfo(Call->getArg(0), CS);
return;
}
- if (isa<CXXMethodDecl>(FunDecl))
- handleCall(Call, llvm::index(Args, 0), llvm::drop_begin(Args, 1), FunDecl);
+ if (const auto *MCall = dyn_cast<CXXMemberCallExpr>(Call))
+ handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl);
else
- handleCall(Call, nullptr, Args, FunDecl);
+ handleCall(Call, Call->getArg(0), FunDecl);
propagateReturnType(Call, FunDecl);
}
#include <iterator>
#include <utility>
-#include <cassert>
namespace llvm {
-template <typename T>
-constexpr bool is_random_iterator() {
- return std::is_same<
- typename std::iterator_traits<T>::iterator_category,
- std::random_access_iterator_tag>::value;
-}
-
/// A range adaptor for a pair of iterators.
///
/// This just wraps two iterators into a range-compatible interface. Nothing
return iterator_range<T>(std::move(p.first), std::move(p.second));
}
-/// Non-random-iterator version
template <typename T>
-auto drop_begin(T &&t, int n) ->
- typename std::enable_if<!is_random_iterator<decltype(adl_begin(t))>(),
- iterator_range<decltype(adl_begin(t))>>::type {
- auto begin = adl_begin(t);
- auto end = adl_end(t);
- for (int i = 0; i < n; i++) {
- assert(begin != end);
- ++begin;
- }
- return make_range(begin, end);
+iterator_range<decltype(adl_begin(std::declval<T>()))> drop_begin(T &&t,
+ int n) {
+ return make_range(std::next(adl_begin(t), n), adl_end(t));
}
-
-/// Optimized version for random iterators
-template <typename T>
-auto drop_begin(T &&t, int n) ->
- typename std::enable_if<is_random_iterator<decltype(adl_begin(t))>(),
- iterator_range<decltype(adl_begin(t))>>::type {
- auto begin = adl_begin(t);
- auto end = adl_end(t);
- assert(end - begin >= n && "Dropping more elements than exist!");
- return make_range(std::next(begin, n), end);
-}
-
}
#endif