15#ifndef LLVM_CLANG_LIB_SEMA_SEMALIFETIMESAFETY_H
16#define LLVM_CLANG_LIB_SEMA_SEMALIFETIMESAFETY_H
27 return !Diags.
isIgnored(diag::warn_lifetime_safety_use_after_scope,
29 !Diags.
isIgnored(diag::warn_lifetime_safety_use_after_scope_moved,
31 !Diags.
isIgnored(diag::warn_lifetime_safety_return_stack_addr,
33 !Diags.
isIgnored(diag::warn_lifetime_safety_return_stack_addr_moved,
35 !Diags.
isIgnored(diag::warn_lifetime_safety_invalidation,
37 !Diags.
isIgnored(diag::warn_lifetime_safety_noescape_escapes,
47 const Expr *MovedExpr,
50 MovedExpr ? diag::warn_lifetime_safety_use_after_scope_moved
51 : diag::warn_lifetime_safety_use_after_scope)
54 S.Diag(MovedExpr->
getExprLoc(), diag::note_lifetime_safety_moved_here)
56 S.Diag(FreeLoc, diag::note_lifetime_safety_destroyed_here);
57 S.Diag(UseExpr->
getExprLoc(), diag::note_lifetime_safety_used_here)
62 const Expr *MovedExpr,
65 MovedExpr ? diag::warn_lifetime_safety_return_stack_addr_moved
66 : diag::warn_lifetime_safety_return_stack_addr)
69 S.Diag(MovedExpr->
getExprLoc(), diag::note_lifetime_safety_moved_here)
71 S.Diag(ReturnExpr->
getExprLoc(), diag::note_lifetime_safety_returned_here)
77 const Expr *MovedExpr,
80 MovedExpr ? diag::warn_lifetime_safety_dangling_field_moved
81 : diag::warn_lifetime_safety_dangling_field)
84 S.Diag(MovedExpr->
getExprLoc(), diag::note_lifetime_safety_moved_here)
87 diag::note_lifetime_safety_dangling_field_here)
93 const Expr *MovedExpr,
96 MovedExpr ? diag::warn_lifetime_safety_dangling_global_moved
97 : diag::warn_lifetime_safety_dangling_global)
100 S.Diag(MovedExpr->
getExprLoc(), diag::note_lifetime_safety_moved_here)
104 diag::note_lifetime_safety_dangling_static_here)
108 diag::note_lifetime_safety_dangling_global_here)
113 const Expr *InvalidationExpr)
override {
114 S.Diag(IssueExpr->
getExprLoc(), diag::warn_lifetime_safety_invalidation)
117 diag::note_lifetime_safety_invalidated_here)
119 S.Diag(UseExpr->
getExprLoc(), diag::note_lifetime_safety_used_here)
123 const Expr *InvalidationExpr)
override {
125 diag::warn_lifetime_safety_invalidation)
128 diag::note_lifetime_safety_invalidated_here)
130 S.Diag(UseExpr->
getExprLoc(), diag::note_lifetime_safety_used_here)
136 const Expr *EscapeExpr)
override {
139 ? diag::warn_lifetime_safety_cross_tu_param_suggestion
140 : diag::warn_lifetime_safety_intra_tu_param_suggestion;
142 ParmToAnnotate->
getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
143 StringRef FixItText =
" [[clang::lifetimebound]]";
148 FixItText =
"[[clang::lifetimebound]] ";
154 diag::note_lifetime_safety_suggestion_returned_here)
160 const Expr *EscapeExpr)
override {
162 ? diag::warn_lifetime_safety_cross_tu_this_suggestion
163 : diag::warn_lifetime_safety_intra_tu_this_suggestion;
166 MDL.getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
180 0, S.getSourceManager(), S.getLangOpts());
182 S.Diag(InsertionPoint, DiagID)
185 " [[clang::lifetimebound]]");
187 diag::note_lifetime_safety_suggestion_returned_here)
192 const Expr *EscapeExpr)
override {
194 diag::warn_lifetime_safety_noescape_escapes)
198 diag::note_lifetime_safety_suggestion_returned_here)
205 diag::warn_lifetime_safety_noescape_escapes)
209 diag::note_lifetime_safety_escapes_to_field_here)
214 const VarDecl *EscapeGlobal)
override {
216 diag::warn_lifetime_safety_noescape_escapes)
220 diag::note_lifetime_safety_escapes_to_static_storage_here)
224 diag::note_lifetime_safety_escapes_to_global_here)
229 S.addLifetimeBoundToImplicitThis(
const_cast<CXXMethodDecl *
>(MD));
Represents a static or instance method of a struct/union/class.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Concrete class used by the front-end to report problems and issues.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
DeclarationNameInfo getNameInfo() const
Represents a prototype with parameter type info, e.g.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Wrapper for source info for functions.
static std::optional< Token > findPreviousToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments)
Finds the token that comes before the given location.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a parameter to a function.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Scope - A scope is a transient data structure that is used while parsing the program.
Sema - This implements semantic analysis and AST building for C.
DiagnosticsEngine & getDiagnostics() const
Encodes a location in the source.
SourceLocation getBegin() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const Expr *EscapeExpr) override
void reportUseAfterInvalidation(const ParmVarDecl *PVD, const Expr *UseExpr, const Expr *InvalidationExpr) override
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const VarDecl *EscapeGlobal) override
LifetimeSafetySemaHelperImpl(Sema &S)
void suggestLifetimeboundToImplicitThis(SuggestionScope Scope, const CXXMethodDecl *MD, const Expr *EscapeExpr) override
void suggestLifetimeboundToParmVar(SuggestionScope Scope, const ParmVarDecl *ParmToAnnotate, const Expr *EscapeExpr) override
void reportDanglingGlobal(const Expr *IssueExpr, const VarDecl *DanglingGlobal, const Expr *MovedExpr, SourceLocation ExpiryLoc) override
void reportUseAfterFree(const Expr *IssueExpr, const Expr *UseExpr, const Expr *MovedExpr, SourceLocation FreeLoc) override
void reportDanglingField(const Expr *IssueExpr, const FieldDecl *DanglingField, const Expr *MovedExpr, SourceLocation ExpiryLoc) override
void addLifetimeBoundToImplicitThis(const CXXMethodDecl *MD) override
void reportUseAfterInvalidation(const Expr *IssueExpr, const Expr *UseExpr, const Expr *InvalidationExpr) override
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const FieldDecl *EscapeField) override
void reportUseAfterReturn(const Expr *IssueExpr, const Expr *ReturnExpr, const Expr *MovedExpr, SourceLocation ExpiryLoc) override
LifetimeSafetySemaHelper()=default
SuggestionScope
Enum to track functions visible across or within TU.
bool IsLifetimeSafetyDiagnosticEnabled(Sema &S, const Decl *D)
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.