clang 20.0.0git
CheckExprLifetime.h
Go to the documentation of this file.
1//===- CheckExprLifetime.h ----------------------------------- -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This files implements a statement-local lifetime analysis.
9//
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H
13#define LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H
14
15#include "clang/AST/Expr.h"
17#include "clang/Sema/Sema.h"
18
19namespace clang::sema {
20
21// Tells whether the type is annotated with [[gsl::Pointer]] or is a pointer
22// type.
23bool isPointerLikeType(QualType QT);
24
25/// Describes an entity that is being assigned.
27 // The left-hand side expression of the assignment.
28 Expr *LHS = nullptr;
30};
31
33 // In an function call involving a lifetime capture, this would be the
34 // argument capturing the lifetime of another argument.
35 // void addToSet(std::string_view sv [[clang::lifetime_capture_by(setsv)]],
36 // set<std::string_view>& setsv);
37 // set<std::string_view> setsv;
38 // addToSet(std::string(), setsv); // Here 'setsv' is the 'Entity'.
39 //
40 // This is 'nullptr' when the capturing entity is 'global' or 'unknown'.
41 Expr *Entity = nullptr;
42};
43
44/// Check that the lifetime of the given expr (and its subobjects) is
45/// sufficient for initializing the entity, and perform lifetime extension
46/// (when permitted) if not.
47void checkInitLifetime(Sema &SemaRef, const InitializedEntity &Entity,
48 Expr *Init);
49
50/// Check that the lifetime of the given expr (and its subobjects) is
51/// sufficient for assigning to the entity.
52void checkAssignmentLifetime(Sema &SemaRef, const AssignedEntity &Entity,
53 Expr *Init);
54
55void checkCaptureByLifetime(Sema &SemaRef, const CapturingEntity &Entity,
56 Expr *Init);
57
58/// Check that the lifetime of the given expr (and its subobjects) is
59/// sufficient, assuming that it is passed as an argument to a musttail
60/// function.
62 const InitializedEntity &Entity, Expr *Init);
63
65
66} // namespace clang::sema
67
68#endif // LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
This represents one expression.
Definition: Expr.h:110
Represents a function declaration or definition.
Definition: Decl.h:1935
Describes an entity that is being initialized.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD)
void checkExprLifetimeMustTailArg(Sema &SemaRef, const InitializedEntity &Entity, Expr *Init)
Check that the lifetime of the given expr (and its subobjects) is sufficient, assuming that it is pas...
bool isPointerLikeType(QualType QT)
void checkInitLifetime(Sema &SemaRef, const InitializedEntity &Entity, Expr *Init)
Check that the lifetime of the given expr (and its subobjects) is sufficient for initializing the ent...
void checkAssignmentLifetime(Sema &SemaRef, const AssignedEntity &Entity, Expr *Init)
Check that the lifetime of the given expr (and its subobjects) is sufficient for assigning to the ent...
void checkCaptureByLifetime(Sema &SemaRef, const CapturingEntity &Entity, Expr *Init)
Describes an entity that is being assigned.
CXXMethodDecl * AssignmentOperator