diff --git a/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp index 153a0a51e98024..9757a00f1fb2f6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp @@ -46,13 +46,13 @@ class MIGChecker : public Checker, // additionally an argument of a MIG routine, the checker keeps track of that // information and issues a warning when an error is returned from the // respective routine. - std::vector> Deallocators = { + CallDescriptionMap Deallocators = { #define CALL(required_args, deallocated_arg, ...) \ - {{{__VA_ARGS__}, required_args}, deallocated_arg} - // E.g., if the checker sees a C function 'vm_deallocate' that is - // defined on class 'IOUserClient' that has exactly 3 parameters, it knows - // that argument #1 (starting from 0, i.e. the second argument) is going - // to be consumed in the sense of the MIG consume-on-success convention. + {{CDM::SimpleFunc, {__VA_ARGS__}, required_args}, deallocated_arg} + // E.g., if the checker sees a C function 'vm_deallocate' that has + // exactly 3 parameters, it knows that argument #1 (starting from 0, i.e. + // the second argument) is going to be consumed in the sense of the MIG + // consume-on-success convention. CALL(3, 1, "vm_deallocate"), CALL(3, 1, "mach_vm_deallocate"), CALL(2, 0, "mig_deallocate"), @@ -78,6 +78,9 @@ class MIGChecker : public Checker, CALL(1, 0, "thread_inspect_deallocate"), CALL(1, 0, "upl_deallocate"), CALL(1, 0, "vm_map_deallocate"), +#undef CALL +#define CALL(required_args, deallocated_arg, ...) \ + {{CDM::CXXMethod, {__VA_ARGS__}, required_args}, deallocated_arg} // E.g., if the checker sees a method 'releaseAsyncReference64()' that is // defined on class 'IOUserClient' that takes exactly 1 argument, it knows // that the argument is going to be consumed in the sense of the MIG @@ -87,7 +90,7 @@ class MIGChecker : public Checker, #undef CALL }; - CallDescription OsRefRetain{{"os_ref_retain"}, 1}; + CallDescription OsRefRetain{CDM::SimpleFunc, {"os_ref_retain"}, 1}; void checkReturnAux(const ReturnStmt *RS, CheckerContext &C) const; @@ -198,15 +201,12 @@ void MIGChecker::checkPostCall(const CallEvent &Call, CheckerContext &C) const { if (!isInMIGCall(C)) return; - auto I = llvm::find_if(Deallocators, - [&](const std::pair &Item) { - return Item.first.matches(Call); - }); - if (I == Deallocators.end()) + const unsigned *ArgIdxPtr = Deallocators.lookup(Call); + if (!ArgIdxPtr) return; ProgramStateRef State = C.getState(); - unsigned ArgIdx = I->second; + unsigned ArgIdx = *ArgIdxPtr; SVal Arg = Call.getArgSVal(ArgIdx); const ParmVarDecl *PVD = getOriginParam(Arg, C); if (!PVD || State->contains(PVD))