#include "CheckExprLifetime.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ExprOpenMP.h"
#include "clang/AST/IgnoreExpr.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/Designator.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Ownership.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaObjC.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
usingnamespaceclang;
static bool IsWideCharCompatible(QualType T, ASTContext &Context) { … }
enum StringInitFailureKind { … };
static StringInitFailureKind IsStringInit(Expr *Init, const ArrayType *AT,
ASTContext &Context) { … }
static StringInitFailureKind IsStringInit(Expr *init, QualType declType,
ASTContext &Context) { … }
bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) { … }
static void updateStringLiteralType(Expr *E, QualType Ty) { … }
static void updateGNUCompoundLiteralRValue(Expr *E) { … }
static bool initializingConstexprVariable(const InitializedEntity &Entity) { … }
static void CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
Sema &SemaRef, QualType &TT);
static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
Sema &S, bool CheckC23ConstexprInit = false) { … }
namespace {
class InitListChecker { … };
}
ExprResult InitListChecker::PerformEmptyInit(SourceLocation Loc,
const InitializedEntity &Entity) { … }
void InitListChecker::CheckEmptyInitializable(const InitializedEntity &Entity,
SourceLocation Loc) { … }
void InitListChecker::FillInEmptyInitForBase(
unsigned Init, const CXXBaseSpecifier &Base,
const InitializedEntity &ParentEntity, InitListExpr *ILE,
bool &RequiresSecondPass, bool FillWithNoInit) { … }
void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
const InitializedEntity &ParentEntity,
InitListExpr *ILE,
bool &RequiresSecondPass,
bool FillWithNoInit) { … }
void
InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
InitListExpr *ILE,
bool &RequiresSecondPass,
InitListExpr *OuterILE,
unsigned OuterIndex,
bool FillWithNoInit) { … }
static bool hasAnyDesignatedInits(const InitListExpr *IL) { … }
InitListChecker::InitListChecker(
Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T,
bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution,
SmallVectorImpl<QualType> *AggrDeductionCandidateParamTypes)
: … { … }
int InitListChecker::numArrayElements(QualType DeclType) { … }
int InitListChecker::numStructUnionElements(QualType DeclType) { … }
RecordDecl *InitListChecker::getRecordDecl(QualType DeclType) { … }
static bool isIdiomaticBraceElisionEntity(const InitializedEntity &Entity) { … }
void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity,
InitListExpr *ParentIList,
QualType T, unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
static void warnBracedScalarInit(Sema &S, const InitializedEntity &Entity,
SourceRange Braces) { … }
void InitListChecker::CheckExplicitInitList(const InitializedEntity &Entity,
InitListExpr *IList, QualType &T,
InitListExpr *StructuredList,
bool TopLevelObject) { … }
void InitListChecker::CheckListElementTypes(const InitializedEntity &Entity,
InitListExpr *IList,
QualType &DeclType,
bool SubobjectIsDesignatorContext,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool TopLevelObject) { … }
void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
InitListExpr *IList,
QualType ElemType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool DirectlyDesignated) { … }
void InitListChecker::CheckComplexType(const InitializedEntity &Entity,
InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
void InitListChecker::CheckScalarType(const InitializedEntity &Entity,
InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
void InitListChecker::CheckReferenceType(const InitializedEntity &Entity,
InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
void InitListChecker::CheckVectorType(const InitializedEntity &Entity,
InitListExpr *IList, QualType DeclType,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
static bool checkDestructorReference(QualType ElementType, SourceLocation Loc,
Sema &SemaRef) { … }
static bool
canInitializeArrayWithEmbedDataString(ArrayRef<Expr *> ExprList,
const InitializedEntity &Entity,
ASTContext &Context) { … }
void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
InitListExpr *IList, QualType &DeclType,
llvm::APSInt elementIndex,
bool SubobjectIsDesignatorContext,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex) { … }
bool InitListChecker::CheckFlexibleArrayInit(const InitializedEntity &Entity,
Expr *InitExpr,
FieldDecl *Field,
bool TopLevelObject) { … }
void InitListChecker::CheckStructUnionTypes(
const InitializedEntity &Entity, InitListExpr *IList, QualType DeclType,
CXXRecordDecl::base_class_const_range Bases, RecordDecl::field_iterator Field,
bool SubobjectIsDesignatorContext, unsigned &Index,
InitListExpr *StructuredList, unsigned &StructuredIndex,
bool TopLevelObject) { … }
static void ExpandAnonymousFieldDesignator(Sema &SemaRef,
DesignatedInitExpr *DIE,
unsigned DesigIdx,
IndirectFieldDecl *IndirectField) { … }
static DesignatedInitExpr *CloneDesignatedInitExpr(Sema &SemaRef,
DesignatedInitExpr *DIE) { … }
namespace {
class FieldInitializerValidatorCCC final : public CorrectionCandidateCallback { … };
}
bool
InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
InitListExpr *IList,
DesignatedInitExpr *DIE,
unsigned DesigIdx,
QualType &CurrentObjectType,
RecordDecl::field_iterator *NextField,
llvm::APSInt *NextElementIndex,
unsigned &Index,
InitListExpr *StructuredList,
unsigned &StructuredIndex,
bool FinishSubobjectInit,
bool TopLevelObject) { … }
InitListExpr *
InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
unsigned StructuredIndex,
SourceRange InitRange,
bool IsFullyOverwritten) { … }
InitListExpr *
InitListChecker::createInitListExpr(QualType CurrentObjectType,
SourceRange InitRange,
unsigned ExpectedNumInits) { … }
void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList,
unsigned &StructuredIndex,
Expr *expr) { … }
bool Sema::CanPerformAggregateInitializationForOverloadResolution(
const InitializedEntity &Entity, InitListExpr *From) { … }
static ExprResult
CheckArrayDesignatorExpr(Sema &S, Expr *Index, llvm::APSInt &Value) { … }
ExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
SourceLocation EqualOrColonLoc,
bool GNUSyntax,
ExprResult Init) { … }
InitializedEntity::InitializedEntity(ASTContext &Context, unsigned Index,
const InitializedEntity &Parent)
: … { … }
InitializedEntity
InitializedEntity::InitializeBase(ASTContext &Context,
const CXXBaseSpecifier *Base,
bool IsInheritedVirtualBase,
const InitializedEntity *Parent) { … }
DeclarationName InitializedEntity::getName() const { … }
ValueDecl *InitializedEntity::getDecl() const { … }
bool InitializedEntity::allowsNRVO() const { … }
unsigned InitializedEntity::dumpImpl(raw_ostream &OS) const { … }
LLVM_DUMP_METHOD void InitializedEntity::dump() const { … }
void InitializationSequence::Step::Destroy() { … }
bool InitializationSequence::isDirectReferenceBinding() const { … }
bool InitializationSequence::isAmbiguous() const { … }
bool InitializationSequence::isConstructorInitialization() const { … }
void
InitializationSequence
::AddAddressOverloadResolutionStep(FunctionDecl *Function,
DeclAccessPair Found,
bool HadMultipleCandidates) { … }
void InitializationSequence::AddDerivedToBaseCastStep(QualType BaseType,
ExprValueKind VK) { … }
void InitializationSequence::AddReferenceBindingStep(QualType T,
bool BindingTemporary) { … }
void InitializationSequence::AddFinalCopy(QualType T) { … }
void InitializationSequence::AddExtraneousCopyToTemporary(QualType T) { … }
void
InitializationSequence::AddUserConversionStep(FunctionDecl *Function,
DeclAccessPair FoundDecl,
QualType T,
bool HadMultipleCandidates) { … }
void InitializationSequence::AddQualificationConversionStep(QualType Ty,
ExprValueKind VK) { … }
void InitializationSequence::AddFunctionReferenceConversionStep(QualType Ty) { … }
void InitializationSequence::AddAtomicConversionStep(QualType Ty) { … }
void InitializationSequence::AddConversionSequenceStep(
const ImplicitConversionSequence &ICS, QualType T,
bool TopLevelOfInitList) { … }
void InitializationSequence::AddListInitializationStep(QualType T) { … }
void InitializationSequence::AddConstructorInitializationStep(
DeclAccessPair FoundDecl, CXXConstructorDecl *Constructor, QualType T,
bool HadMultipleCandidates, bool FromInitList, bool AsInitList) { … }
void InitializationSequence::AddZeroInitializationStep(QualType T) { … }
void InitializationSequence::AddCAssignmentStep(QualType T) { … }
void InitializationSequence::AddStringInitStep(QualType T) { … }
void InitializationSequence::AddObjCObjectConversionStep(QualType T) { … }
void InitializationSequence::AddArrayInitStep(QualType T, bool IsGNUExtension) { … }
void InitializationSequence::AddArrayInitLoopStep(QualType T, QualType EltT) { … }
void InitializationSequence::AddParenthesizedArrayInitStep(QualType T) { … }
void InitializationSequence::AddPassByIndirectCopyRestoreStep(QualType type,
bool shouldCopy) { … }
void InitializationSequence::AddProduceObjCObjectStep(QualType T) { … }
void InitializationSequence::AddStdInitializerListConstructionStep(QualType T) { … }
void InitializationSequence::AddOCLSamplerInitStep(QualType T) { … }
void InitializationSequence::AddOCLZeroOpaqueTypeStep(QualType T) { … }
void InitializationSequence::AddParenthesizedListInitStep(QualType T) { … }
void InitializationSequence::AddUnwrapInitListInitStep(
InitListExpr *Syntactic) { … }
void InitializationSequence::RewrapReferenceInitList(QualType T,
InitListExpr *Syntactic) { … }
void InitializationSequence::SetOverloadFailure(FailureKind Failure,
OverloadingResult Result) { … }
static bool
maybeRecoverWithZeroInitialization(Sema &S, InitializationSequence &Sequence,
const InitializedEntity &Entity) { … }
static void MaybeProduceObjCObject(Sema &S,
InitializationSequence &Sequence,
const InitializedEntity &Entity) { … }
static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
const InitializedEntity &Entity, Expr *Initializer,
QualType DestType, InitializationSequence &Sequence,
bool TreatUnavailableAsInvalid) { … }
static void TryListInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitListExpr *InitList,
InitializationSequence &Sequence,
bool TreatUnavailableAsInvalid);
static bool TryInitializerListConstruction(Sema &S,
InitListExpr *List,
QualType DestType,
InitializationSequence &Sequence,
bool TreatUnavailableAsInvalid) { … }
static bool hasCopyOrMoveCtorParam(ASTContext &Ctx,
const ConstructorInfo &Info) { … }
static OverloadingResult ResolveConstructorOverload(
Sema &S, SourceLocation DeclLoc, MultiExprArg Args,
OverloadCandidateSet &CandidateSet, QualType DestType,
DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best,
bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
bool IsListInit, bool RequireActualConstructor,
bool SecondStepOfCopyInit = false) { … }
static void TryConstructorInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
MultiExprArg Args, QualType DestType,
QualType DestArrayType,
InitializationSequence &Sequence,
bool IsListInit = false,
bool IsInitListCopy = false) { … }
static bool
ResolveOverloadedFunctionForReferenceBinding(Sema &S,
Expr *Initializer,
QualType &SourceType,
QualType &UnqualifiedSourceType,
QualType UnqualifiedTargetType,
InitializationSequence &Sequence) { … }
static void TryReferenceInitializationCore(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
Expr *Initializer,
QualType cv1T1, QualType T1,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
InitializationSequence &Sequence,
bool TopLevelOfInitList);
static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitializationSequence &Sequence,
InitListExpr *InitList = nullptr);
static void TryReferenceListInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitListExpr *InitList,
InitializationSequence &Sequence,
bool TreatUnavailableAsInvalid) { … }
static void TryListInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitListExpr *InitList,
InitializationSequence &Sequence,
bool TreatUnavailableAsInvalid) { … }
static OverloadingResult TryRefInitWithConversionFunction(
Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind,
Expr *Initializer, bool AllowRValues, bool IsLValueRef,
InitializationSequence &Sequence) { … }
static void CheckCXX98CompatAccessibleCopy(Sema &S,
const InitializedEntity &Entity,
Expr *CurInitExpr);
static void TryReferenceInitialization(Sema &S, const InitializedEntity &Entity,
const InitializationKind &Kind,
Expr *Initializer,
InitializationSequence &Sequence,
bool TopLevelOfInitList) { … }
static bool isNonReferenceableGLValue(Expr *E) { … }
static void TryReferenceInitializationCore(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
Expr *Initializer,
QualType cv1T1, QualType T1,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
InitializationSequence &Sequence,
bool TopLevelOfInitList) { … }
static void TryStringLiteralInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
Expr *Initializer,
InitializationSequence &Sequence) { … }
static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitializationSequence &Sequence,
InitListExpr *InitList) { … }
static void TryDefaultInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
InitializationSequence &Sequence) { … }
static void TryOrBuildParenListInitialization(
Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind,
ArrayRef<Expr *> Args, InitializationSequence &Sequence, bool VerifyOnly,
ExprResult *Result = nullptr) { … }
static void TryUserDefinedConversion(Sema &S,
QualType DestType,
const InitializationKind &Kind,
Expr *Initializer,
InitializationSequence &Sequence,
bool TopLevelOfInitList) { … }
static bool isLibstdcxxPointerReturnFalseHack(Sema &S,
const InitializedEntity &Entity,
const Expr *Init) { … }
enum InvalidICRKind { … };
static InvalidICRKind isInvalidICRSource(ASTContext &C, Expr *e,
bool isAddressOf, bool &isWeakAccess) { … }
static void checkIndirectCopyRestoreSource(Sema &S, Expr *src) { … }
static bool hasCompatibleArrayTypes(ASTContext &Context, const ArrayType *Dest,
const ArrayType *Source) { … }
static bool tryObjCWritebackConversion(Sema &S,
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) { … }
static bool TryOCLSamplerInitialization(Sema &S,
InitializationSequence &Sequence,
QualType DestType,
Expr *Initializer) { … }
static bool IsZeroInitializer(Expr *Initializer, Sema &S) { … }
static bool TryOCLZeroOpaqueTypeInitialization(Sema &S,
InitializationSequence &Sequence,
QualType DestType,
Expr *Initializer) { … }
InitializationSequence::InitializationSequence(
Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind,
MultiExprArg Args, bool TopLevelOfInitList, bool TreatUnavailableAsInvalid)
: … { … }
static bool isExprAnUnaddressableFunction(Sema &S, const Expr *E) { … }
static bool canPerformArrayCopy(const InitializedEntity &Entity) { … }
void InitializationSequence::InitializeFrom(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
MultiExprArg Args,
bool TopLevelOfInitList,
bool TreatUnavailableAsInvalid) { … }
InitializationSequence::~InitializationSequence() { … }
static AssignmentAction getAssignmentAction(const InitializedEntity &Entity,
bool Diagnose = false) { … }
static bool shouldBindAsTemporary(const InitializedEntity &Entity) { … }
static bool shouldDestroyEntity(const InitializedEntity &Entity) { … }
static SourceLocation getInitializationLoc(const InitializedEntity &Entity,
Expr *Initializer) { … }
static ExprResult CopyObject(Sema &S,
QualType T,
const InitializedEntity &Entity,
ExprResult CurInit,
bool IsExtraneousCopy) { … }
static void CheckCXX98CompatAccessibleCopy(Sema &S,
const InitializedEntity &Entity,
Expr *CurInitExpr) { … }
void InitializationSequence::PrintInitLocationNote(Sema &S,
const InitializedEntity &Entity) { … }
static bool isExplicitTemporary(const InitializedEntity &Entity,
const InitializationKind &Kind,
unsigned NumArgs) { … }
static ExprResult
PerformConstructorInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
MultiExprArg Args,
const InitializationSequence::Step& Step,
bool &ConstructorInitRequiresZeroInit,
bool IsListInitialization,
bool IsStdInitListInitialization,
SourceLocation LBraceLoc,
SourceLocation RBraceLoc) { … }
void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
Expr *Init) { … }
static void DiagnoseNarrowingInInitList(Sema &S,
const ImplicitConversionSequence &ICS,
QualType PreNarrowingType,
QualType EntityType,
const Expr *PostInit);
static void CheckC23ConstexprInitConversion(Sema &S, QualType FromType,
QualType ToType, Expr *Init);
static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr,
bool IsReturnStmt) { … }
static void CheckForNullPointerDereference(Sema &S, const Expr *E) { … }
MaterializeTemporaryExpr *
Sema::CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary,
bool BoundToLvalueReference) { … }
ExprResult Sema::TemporaryMaterializationConversion(Expr *E) { … }
ExprResult Sema::PerformQualificationConversion(Expr *E, QualType Ty,
ExprValueKind VK,
CheckedConversionKind CCK) { … }
ExprResult InitializationSequence::Perform(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
MultiExprArg Args,
QualType *ResultType) { … }
static bool DiagnoseUninitializedReference(Sema &S, SourceLocation Loc,
QualType T) { … }
static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity,
Expr *op) { … }
static void diagnoseListInit(Sema &S, const InitializedEntity &Entity,
InitListExpr *InitList) { … }
bool InitializationSequence::Diagnose(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
ArrayRef<Expr *> Args) { … }
void InitializationSequence::dump(raw_ostream &OS) const { … }
void InitializationSequence::dump() const { … }
static void DiagnoseNarrowingInInitList(Sema &S,
const ImplicitConversionSequence &ICS,
QualType PreNarrowingType,
QualType EntityType,
const Expr *PostInit) { … }
static void CheckC23ConstexprInitConversion(Sema &S, QualType FromType,
QualType ToType, Expr *Init) { … }
static void CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
Sema &SemaRef, QualType &TT) { … }
bool
Sema::CanPerformCopyInitialization(const InitializedEntity &Entity,
ExprResult Init) { … }
ExprResult
Sema::PerformCopyInitialization(const InitializedEntity &Entity,
SourceLocation EqualLoc,
ExprResult Init,
bool TopLevelOfInitList,
bool AllowExplicit) { … }
static bool isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
ClassTemplateDecl *CTD) { … }
QualType Sema::DeduceTemplateSpecializationFromInitializer(
TypeSourceInfo *TSInfo, const InitializedEntity &Entity,
const InitializationKind &Kind, MultiExprArg Inits) { … }