aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp157
1 files changed, 89 insertions, 68 deletions
diff --git a/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp b/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp
index c0bf240464f7..18ab4666a7d8 100644
--- a/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/contrib/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@ namespace clang {
static Decl *getMostRecentDeclImpl(...);
static Decl *getMostRecentDecl(Decl *D);
+ static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+ Decl *Previous);
+
template <typename DeclT>
static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable<DeclT> *D, Decl *Previous,
@@ -366,6 +369,7 @@ namespace clang {
void VisitFieldDecl(FieldDecl *FD);
void VisitMSPropertyDecl(MSPropertyDecl *FD);
void VisitMSGuidDecl(MSGuidDecl *D);
+ void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D);
void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
RedeclarableResult VisitVarDeclImpl(VarDecl *D);
void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
@@ -504,10 +508,9 @@ uint64_t ASTDeclReader::GetCurrentCursorOffset() {
void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) {
if (Record.readInt()) {
- Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile;
- if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
- Reader.DeclIsFromPCHWithObjectFile(FD))
- Reader.DefinitionSource[FD] = true;
+ Reader.DefinitionSource[FD] =
+ Loc.F->Kind == ModuleKind::MK_MainFile ||
+ Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
}
if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
CD->setNumCtorInitializers(Record.readInt());
@@ -865,7 +868,10 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
FD->setInlineSpecified(Record.readInt());
FD->setImplicitlyInline(Record.readInt());
FD->setVirtualAsWritten(Record.readInt());
- FD->setPure(Record.readInt());
+ // We defer calling `FunctionDecl::setPure()` here as for methods of
+ // `CXXTemplateSpecializationDecl`s, we may not have connected up the
+ // definition (which is required for `setPure`).
+ const bool Pure = Record.readInt();
FD->setHasInheritedPrototype(Record.readInt());
FD->setHasWrittenPrototype(Record.readInt());
FD->setDeletedAsWritten(Record.readInt());
@@ -885,7 +891,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
FD->ODRHash = Record.readInt();
FD->setHasODRHash(true);
- FD->setUsesFPIntrin(Record.readInt());
if (FD->isDefaulted()) {
if (unsigned NumLookups = Record.readInt()) {
@@ -1013,6 +1018,10 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
}
}
+ // Defer calling `setPure` until merging above has guaranteed we've set
+ // `DefinitionData` (as this will need to access it).
+ FD->setPure(Pure);
+
// Read in the parameters.
unsigned NumParams = Record.readInt();
SmallVector<ParmVarDecl *, 16> Params;
@@ -1375,6 +1384,17 @@ void ASTDeclReader::VisitMSGuidDecl(MSGuidDecl *D) {
Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
}
+void ASTDeclReader::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) {
+ VisitValueDecl(D);
+ D->Value = Record.readAPValue();
+
+ // Add this template parameter object to the AST context's lookup structure,
+ // and merge if needed.
+ if (TemplateParamObjectDecl *Existing =
+ Reader.getContext().TemplateParamObjectDecls.GetOrInsertNode(D))
+ Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
+}
+
void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
VisitValueDecl(FD);
@@ -1421,10 +1441,9 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
if (uint64_t Val = Record.readInt()) {
VD->setInit(Record.readExpr());
- if (Val > 1) {
+ if (Val != 1) {
EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
- Eval->CheckedICE = true;
- Eval->IsICE = (Val & 1) != 0;
+ Eval->HasConstantInitialization = (Val & 2) != 0;
Eval->HasConstantDestruction = (Val & 4) != 0;
}
}
@@ -1436,10 +1455,9 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
}
if (VD->getStorageDuration() == SD_Static && Record.readInt()) {
- Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile;
- if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
- Reader.DeclIsFromPCHWithObjectFile(VD))
- Reader.DefinitionSource[VD] = true;
+ Reader.DefinitionSource[VD] =
+ Loc.F->Kind == ModuleKind::MK_MainFile ||
+ Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
}
enum VarKind {
@@ -1700,10 +1718,9 @@ void ASTDeclReader::ReadCXXDefinitionData(
Data.HasODRHash = true;
if (Record.readInt()) {
- Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile;
- if (Reader.getContext().getLangOpts().BuildingPCHWithObjectFile &&
- Reader.DeclIsFromPCHWithObjectFile(D))
- Reader.DefinitionSource[D] = true;
+ Reader.DefinitionSource[D] =
+ Loc.F->Kind == ModuleKind::MK_MainFile ||
+ Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
}
Data.NumBases = Record.readInt();
@@ -1731,6 +1748,7 @@ void ASTDeclReader::ReadCXXDefinitionData(
Lambda.NumExplicitCaptures = Record.readInt();
Lambda.HasKnownInternalLinkage = Record.readInt();
Lambda.ManglingNumber = Record.readInt();
+ D->setDeviceLambdaManglingNumber(Record.readInt());
Lambda.ContextDecl = readDeclID();
Lambda.Captures = (Capture *)Reader.getContext().Allocate(
sizeof(Capture) * Lambda.NumCaptures);
@@ -2410,8 +2428,10 @@ void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
VisitDecl(D);
D->ExtendingDecl = readDeclAs<ValueDecl>();
D->ExprWithTemporary = Record.readStmt();
- if (Record.readInt())
+ if (Record.readInt()) {
D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
+ D->getASTContext().addDestruction(D->Value);
+ }
D->ManglingNumber = Record.readInt();
mergeMergeable(D);
}
@@ -2655,41 +2675,18 @@ void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
}
void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
+ Record.readOMPChildren(D->Data);
VisitDecl(D);
- unsigned NumVars = D->varlist_size();
- SmallVector<Expr *, 16> Vars;
- Vars.reserve(NumVars);
- for (unsigned i = 0; i != NumVars; ++i) {
- Vars.push_back(Record.readExpr());
- }
- D->setVars(Vars);
}
void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
+ Record.readOMPChildren(D->Data);
VisitDecl(D);
- unsigned NumVars = D->varlist_size();
- unsigned NumClauses = D->clauselist_size();
- SmallVector<Expr *, 16> Vars;
- Vars.reserve(NumVars);
- for (unsigned i = 0; i != NumVars; ++i) {
- Vars.push_back(Record.readExpr());
- }
- D->setVars(Vars);
- SmallVector<OMPClause *, 8> Clauses;
- Clauses.reserve(NumClauses);
- for (unsigned I = 0; I != NumClauses; ++I)
- Clauses.push_back(Record.readOMPClause());
- D->setClauses(Clauses);
}
void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) {
+ Record.readOMPChildren(D->Data);
VisitDecl(D);
- unsigned NumClauses = D->clauselist_size();
- SmallVector<OMPClause *, 8> Clauses;
- Clauses.reserve(NumClauses);
- for (unsigned I = 0; I != NumClauses; ++I)
- Clauses.push_back(Record.readOMPClause());
- D->setClauses(Clauses);
}
void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
@@ -2710,18 +2707,10 @@ void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
}
void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
+ Record.readOMPChildren(D->Data);
VisitValueDecl(D);
- D->setLocation(readSourceLocation());
- Expr *MapperVarRefE = Record.readExpr();
- D->setMapperVarRef(MapperVarRefE);
D->VarName = Record.readDeclarationName();
D->PrevDeclInScope = readDeclID();
- unsigned NumClauses = D->clauselist_size();
- SmallVector<OMPClause *, 8> Clauses;
- Clauses.reserve(NumClauses);
- for (unsigned I = 0; I != NumClauses; ++I)
- Clauses.push_back(Record.readOMPClause());
- D->setClauses(Clauses);
}
void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
@@ -3545,6 +3534,19 @@ Decl *ASTReader::getMostRecentExistingDecl(Decl *D) {
return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
}
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+ Decl *Previous) {
+ InheritableAttr *NewAttr = nullptr;
+ ASTContext &Context = Reader.getContext();
+ const auto *IA = Previous->getAttr<MSInheritanceAttr>();
+
+ if (IA && !D->hasAttr<MSInheritanceAttr>()) {
+ NewAttr = cast<InheritableAttr>(IA->clone(Context));
+ NewAttr->setInherited(true);
+ D->addAttr(NewAttr);
+ }
+}
+
template<typename DeclT>
void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable<DeclT> *D,
@@ -3703,6 +3705,12 @@ void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D,
if (auto *TD = dyn_cast<TemplateDecl>(D))
inheritDefaultTemplateArguments(Reader.getContext(),
cast<TemplateDecl>(Previous), TD);
+
+ // If any of the declaration in the chain contains an Inheritable attribute,
+ // it needs to be added to all the declarations in the redeclarable chain.
+ // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+ // be extended for all inheritable attributes.
+ mergeInheritableAttributes(Reader, D, Previous);
}
template<typename DeclT>
@@ -3996,6 +4004,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
case DECL_MS_GUID:
D = MSGuidDecl::CreateDeserialized(Context, ID);
break;
+ case DECL_TEMPLATE_PARAM_OBJECT:
+ D = TemplateParamObjectDecl::CreateDeserialized(Context, ID);
+ break;
case DECL_CAPTURED:
D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt());
break;
@@ -4010,24 +4021,35 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
// locations.
D = ImportDecl::CreateDeserialized(Context, ID, Record.back());
break;
- case DECL_OMP_THREADPRIVATE:
- D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt());
+ case DECL_OMP_THREADPRIVATE: {
+ Record.skipInts(1);
+ unsigned NumChildren = Record.readInt();
+ Record.skipInts(1);
+ D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, NumChildren);
break;
+ }
case DECL_OMP_ALLOCATE: {
- unsigned NumVars = Record.readInt();
unsigned NumClauses = Record.readInt();
+ unsigned NumVars = Record.readInt();
+ Record.skipInts(1);
D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses);
break;
}
- case DECL_OMP_REQUIRES:
- D = OMPRequiresDecl::CreateDeserialized(Context, ID, Record.readInt());
+ case DECL_OMP_REQUIRES: {
+ unsigned NumClauses = Record.readInt();
+ Record.skipInts(2);
+ D = OMPRequiresDecl::CreateDeserialized(Context, ID, NumClauses);
break;
+ }
case DECL_OMP_DECLARE_REDUCTION:
D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID);
break;
- case DECL_OMP_DECLARE_MAPPER:
- D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, Record.readInt());
+ case DECL_OMP_DECLARE_MAPPER: {
+ unsigned NumClauses = Record.readInt();
+ Record.skipInts(2);
+ D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, NumClauses);
break;
+ }
case DECL_OMP_CAPTUREDEXPR:
D = OMPCapturedExprDecl::CreateDeserialized(Context, ID);
break;
@@ -4439,10 +4461,10 @@ void ASTDeclReader::UpdateDecl(Decl *D,
uint64_t Val = Record.readInt();
if (Val && !VD->getInit()) {
VD->setInit(Record.readExpr());
- if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
+ if (Val != 1) {
EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
- Eval->CheckedICE = true;
- Eval->IsICE = Val == 3;
+ Eval->HasConstantInitialization = (Val & 2) != 0;
+ Eval->HasConstantDestruction = (Val & 4) != 0;
}
}
break;
@@ -4667,12 +4689,11 @@ void ASTDeclReader::UpdateDecl(Decl *D,
}
case UPD_DECL_MARKED_OPENMP_DECLARETARGET: {
- OMPDeclareTargetDeclAttr::MapTypeTy MapType =
- static_cast<OMPDeclareTargetDeclAttr::MapTypeTy>(Record.readInt());
- OMPDeclareTargetDeclAttr::DevTypeTy DevType =
- static_cast<OMPDeclareTargetDeclAttr::DevTypeTy>(Record.readInt());
+ auto MapType = Record.readEnum<OMPDeclareTargetDeclAttr::MapTypeTy>();
+ auto DevType = Record.readEnum<OMPDeclareTargetDeclAttr::DevTypeTy>();
+ unsigned Level = Record.readInt();
D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(
- Reader.getContext(), MapType, DevType, readSourceRange(),
+ Reader.getContext(), MapType, DevType, Level, readSourceRange(),
AttributeCommonInfo::AS_Pragma));
break;
}