forked from OSchip/llvm-project
[analyzer] Check for std::__addressof for inner pointer checker
This is an extension to diff D99260. This adds an additional exception for `std::__addressof` in `InnerPointerChecker`. Patch By alishuja (Ali Shuja Siddiqui)! Reviewed By: martong, alishuja Differential Revision: https://reviews.llvm.org/D109467
This commit is contained in:
parent
903b8845fb
commit
cf7cd664f3
|
@ -35,9 +35,9 @@ namespace {
|
|||
class InnerPointerChecker
|
||||
: public Checker<check::DeadSymbols, check::PostCall> {
|
||||
|
||||
CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
|
||||
DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
|
||||
ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
|
||||
CallDescription AppendFn, AssignFn, AddressofFn, AddressofFn_, ClearFn,
|
||||
CStrFn, DataFn, DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn,
|
||||
ReplaceFn, ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
|
||||
|
||||
public:
|
||||
class InnerPointerBRVisitor : public BugReporterVisitor {
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
InnerPointerChecker()
|
||||
: AppendFn({"std", "basic_string", "append"}),
|
||||
AssignFn({"std", "basic_string", "assign"}),
|
||||
AddressofFn({"std", "addressof"}),
|
||||
AddressofFn({"std", "addressof"}), AddressofFn_({"std", "__addressof"}),
|
||||
ClearFn({"std", "basic_string", "clear"}),
|
||||
CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
|
||||
DataMemberFn({"std", "basic_string", "data"}),
|
||||
|
@ -179,9 +179,9 @@ void InnerPointerChecker::checkFunctionArguments(const CallEvent &Call,
|
|||
if (!ArgRegion)
|
||||
continue;
|
||||
|
||||
// std::addressof function accepts a non-const reference as an argument,
|
||||
// std::addressof functions accepts a non-const reference as an argument,
|
||||
// but doesn't modify it.
|
||||
if (AddressofFn.matches(Call))
|
||||
if (matchesAny(Call, AddressofFn, AddressofFn_))
|
||||
continue;
|
||||
|
||||
markPtrSymbolsReleased(Call, State, ArgRegion, C);
|
||||
|
|
|
@ -20,6 +20,9 @@ void default_arg(int a = 42, string &b = my_string);
|
|||
template <class T>
|
||||
T *addressof(T &arg);
|
||||
|
||||
template <class T>
|
||||
T *__addressof(T &arg);
|
||||
|
||||
char *data(std::string &c);
|
||||
|
||||
} // end namespace std
|
||||
|
@ -383,6 +386,14 @@ void func_addressof() {
|
|||
consume(c); // no-warning
|
||||
}
|
||||
|
||||
void func_AddressofFn_() {
|
||||
const char *c;
|
||||
std::string s;
|
||||
c = s.c_str();
|
||||
(void)std::__addressof(s);
|
||||
consume(c); // no-warning
|
||||
}
|
||||
|
||||
void func_std_data() {
|
||||
const char *c;
|
||||
std::string s;
|
||||
|
|
Loading…
Reference in New Issue