63 lines · c
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-exception6//===----------------------------------------------------------------------===//7//8// This files implements a statement-local lifetime analysis.9//10//===----------------------------------------------------------------------===//11 12#ifndef LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H13#define LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H14 15#include "clang/AST/Expr.h"16#include "clang/Sema/Initialization.h"17#include "clang/Sema/Sema.h"18 19namespace clang::sema {20 21/// Describes an entity that is being assigned.22struct AssignedEntity {23 // The left-hand side expression of the assignment.24 Expr *LHS = nullptr;25 CXXMethodDecl *AssignmentOperator = nullptr;26};27 28struct CapturingEntity {29 // In an function call involving a lifetime capture, this would be the30 // argument capturing the lifetime of another argument.31 // void addToSet(std::string_view sv [[clang::lifetime_capture_by(setsv)]],32 // set<std::string_view>& setsv);33 // set<std::string_view> setsv;34 // addToSet(std::string(), setsv); // Here 'setsv' is the 'Entity'.35 //36 // This is 'nullptr' when the capturing entity is 'global' or 'unknown'.37 Expr *Entity = nullptr;38};39 40/// Check that the lifetime of the given expr (and its subobjects) is41/// sufficient for initializing the entity, and perform lifetime extension42/// (when permitted) if not.43void checkInitLifetime(Sema &SemaRef, const InitializedEntity &Entity,44 Expr *Init);45 46/// Check that the lifetime of the given expr (and its subobjects) is47/// sufficient for assigning to the entity.48void checkAssignmentLifetime(Sema &SemaRef, const AssignedEntity &Entity,49 Expr *Init);50 51void checkCaptureByLifetime(Sema &SemaRef, const CapturingEntity &Entity,52 Expr *Init);53 54/// Check that the lifetime of the given expr (and its subobjects) is55/// sufficient, assuming that it is passed as an argument to a musttail56/// function.57void checkExprLifetimeMustTailArg(Sema &SemaRef,58 const InitializedEntity &Entity, Expr *Init);59 60} // namespace clang::sema61 62#endif // LLVM_CLANG_SEMA_CHECK_EXPR_LIFETIME_H63