17#include "llvm/ADT/StringSet.h"
29 return cast_if_present<CXXMethodDecl>(
43 auto *MD = dyn_cast<CXXMethodDecl>(FD);
44 if (MD && MD->isCXXInstanceMember())
60static const LifetimeBoundAttr *
68 if (
auto *LBAttr = ATL.getAttrAs<LifetimeBoundAttr>())
70 TL = ATL.getModifiedLoc();
75const LifetimeBoundAttr *
80 auto CheckRedecls = [](
const FunctionDecl *F) ->
const LifetimeBoundAttr * {
88 if (
const auto *
Attr = CheckRedecls(FD))
91 return CheckRedecls(Pattern);
105 if (
const auto *ND = dyn_cast<NamespaceDecl>(DC))
107 StringRef Name = II->getName();
108 if (Name.size() >= 2 && Name.front() ==
'_' &&
124 bool RunningUnderLifetimeSafety) {
127 if (
auto *Conv = dyn_cast<CXXConversionDecl>(Callee))
129 Callee->getParent()->hasAttr<OwnerAttr>())
136 static const llvm::StringSet<> IteratorMembers = {
137 "begin",
"end",
"rbegin",
"rend",
"cbegin",
"cend",
"crbegin",
"crend"};
138 static const llvm::StringSet<> InnerPointerGetters = {
140 "c_str",
"data",
"get"};
141 static const llvm::StringSet<> ContainerFindFns = {
143 "find",
"equal_range",
"lower_bound",
"upper_bound"};
147 if (RunningUnderLifetimeSafety &&
152 switch (Callee->getOverloadedOperator()) {
163 if (Callee->getIdentifier() &&
164 (IteratorMembers.contains(Callee->getName()) ||
165 InnerPointerGetters.contains(Callee->getName())))
173 if (!Callee->getIdentifier())
175 return RunningUnderLifetimeSafety
176 ? Callee->getParent()->hasAttr<OwnerAttr>() &&
177 Callee->getOverloadedOperator() ==
178 OverloadedOperatorKind::OO_Arrow
180 return IteratorMembers.contains(Callee->getName()) ||
181 InnerPointerGetters.contains(Callee->getName()) ||
182 ContainerFindFns.contains(Callee->getName());
184 if (Callee->getReturnType()->isReferenceType()) {
185 if (!Callee->getIdentifier()) {
186 auto OO = Callee->getOverloadedOperator();
187 if (!Callee->getParent()->hasAttr<OwnerAttr>())
189 return OO == OverloadedOperatorKind::OO_Subscript ||
190 OO == OverloadedOperatorKind::OO_Star;
192 return llvm::StringSwitch<bool>(Callee->getName())
193 .Cases({
"front",
"back",
"at",
"top",
"value"},
true)
208 if (llvm::StringSwitch<bool>(FD->
getName())
227 if (!RD || !RD->isInStdNamespace())
229 if (!RD->hasAttr<PointerAttr>() && !RD->hasAttr<OwnerAttr>())
237 return llvm::StringSwitch<bool>(FD->
getName())
238 .Cases({
"begin",
"rbegin",
"cbegin",
"crbegin"},
true)
239 .Cases({
"end",
"rend",
"cend",
"crend"},
true)
244 return llvm::StringSwitch<bool>(FD->
getName())
245 .Cases({
"get",
"any_cast"},
true)
259 return RD->
hasAttr<PointerAttr>() &&
286 bool Result = RD->hasAttr<T>();
288 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
289 Result |= CTSD->getSpecializedTemplate()->getTemplatedDecl()->hasAttr<T>();
298 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(&RD))
299 return CTSD->getSpecializedTemplate()->getName();
327 static const llvm::StringSet<>
Vector = {
328 "insert",
"emplace",
"emplace_back",
329 "push_back",
"insert_range",
334 "reserve",
"resize",
"shrink_to_fit",
336 "assign",
"assign_range"};
340 static const llvm::StringSet<> Deque = {
341 "insert",
"emplace",
"insert_range",
345 "resize",
"shrink_to_fit",
347 "assign",
"assign_range"};
349 static const llvm::StringSet<> String = {
351 "insert",
"push_back",
"append",
"replace",
"replace_with_range",
352 "insert_range",
"append_range",
354 "pop_back",
"erase",
"clear",
356 "reserve",
"resize",
"resize_and_overwrite",
"shrink_to_fit",
358 "swap",
"assign",
"assign_range"};
362 static const llvm::StringSet<> PriorityQueue = {
370 static const llvm::StringSet<> NodeBased = {
376 static const llvm::StringSet<> Flat = {
377 "insert",
"emplace",
"emplace_hint",
378 "try_emplace",
"insert_or_assign",
379 "insert_range",
"merge",
381 "extract",
"erase",
"clear",
385 static const llvm::StringSet<> UniquePtr = {
388 const StringRef RecordName =
getName(*RD);
391 const llvm::StringSet<> *InvalidatingMethods =
392 llvm::StringSwitch<const llvm::StringSet<> *>(RecordName)
394 .Case(
"basic_string", &String)
395 .Case(
"deque", &Deque)
396 .Case(
"priority_queue", &PriorityQueue)
397 .Cases({
"set",
"multiset",
"map",
"multimap",
"unordered_set",
398 "unordered_multiset",
"unordered_map",
"unordered_multimap"},
400 .Cases({
"flat_map",
"flat_set",
"flat_multimap",
"flat_multiset"},
402 .Case(
"unique_ptr", &UniquePtr)
405 if (!InvalidatingMethods)
418 return RecordName ==
"flat_map";
427 return InvalidatingMethods->contains(MD.
getName());
440 return Name ==
"function" || Name ==
"move_only_function";
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines an enumeration for C++ overloaded operators.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Attr - This represents one attribute.
Type source information for an attributed type.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a C++ struct/union/class.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isStdNamespace() const
Decl - This represents one declaration (or definition), e.g.
bool isInStdNamespace() const
ASTContext & getASTContext() const LLVM_READONLY
DeclContext * getDeclContext()
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
size_t param_size() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
A (possibly-)qualified type.
Base wrapper for a particular "section" of type source info.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isPointerType() const
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
bool isLValueReferenceType() const
bool isNullPtrType() const
static bool isRecordWithAttr(QualType Type)
bool isGslPointerType(QualType QT)
bool isStdCallableWrapperType(const CXXRecordDecl *RD)
bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee, bool RunningUnderLifetimeSafety)
bool shouldTrackFirstArgument(const FunctionDecl *FD)
static StringRef getName(const CXXRecordDecl &RD)
bool isAssignmentOperatorLifetimeBound(const CXXMethodDecl *CMD)
static const LifetimeBoundAttr * getLifetimeBoundAttrFromFunctionType(const TypeSourceInfo &TSI)
Check if a function has a lifetimebound attribute on its function type (which represents the implicit...
bool isPointerLikeType(QualType QT)
bool isNormalAssignmentOperator(const FunctionDecl *FD)
bool isUniquePtrRelease(const CXXMethodDecl &MD)
static bool isReferenceOrPointerLikeType(QualType QT)
bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD)
const LifetimeBoundAttr * getImplicitObjectParamLifetimeBoundAttr(const FunctionDecl *FD)
const FunctionDecl * getDeclWithMergedLifetimeBoundAttrs(const FunctionDecl *FD)
bool isInvalidationMethod(const CXXMethodDecl &MD)
bool destructsFirstArg(const FunctionDecl &FD)
bool isGslOwnerType(QualType QT)
bool isInStlNamespace(const Decl *D)
bool shouldTrackSecondArgument(const FunctionDecl *FD)
static bool isStdUniquePtr(const CXXRecordDecl &RD)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
bool isa(CodeGen::Address addr)
bool isCompoundAssignmentOperator(OverloadedOperatorKind Kind)
Determine if this is a compound assignment operator.
LLVM_READONLY bool isUppercase(unsigned char c)
Return true if this character is an uppercase ASCII letter: [A-Z].
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Result
The result type of a method or function.