Skip to content

Commit 527e084

Browse files
committed
Implement serialization/deserialization of feature variables
1 parent de43ec3 commit 527e084

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
808808
bool isInvalid() const { return Kind == FeatureAvailKind::None; }
809809
};
810810

811-
std::map<StringRef, AvailabilityDomainInfo> AvailabilityDomainMap;
811+
std::map<StringRef, VarDecl *> AvailabilityDomainMap;
812812

813-
void addAvailabilityDomainMap(StringRef Name, AvailabilityDomainInfo Info) {
814-
AvailabilityDomainMap[Name] = Info;
813+
void addAvailabilityDomainMap(StringRef Name, VarDecl *VD) {
814+
AvailabilityDomainMap[Name] = VD;
815815
}
816816

817817
std::pair<DomainAvailabilityAttr *, bool>

clang/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ ASTContext::getFeatureAvailInfo(StringRef FeatureName) const {
910910

911911
auto I = AvailabilityDomainMap.find(FeatureName);
912912
if (I != AvailabilityDomainMap.end())
913-
return I->second;
913+
return getFeatureAvailInfo(I->second).second;
914914

915915
return {};
916916
}
@@ -13214,6 +13214,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1321413214
const auto *VD = cast<VarDecl>(D);
1321513215
assert(VD->isFileVarDecl() && "Expected file scoped var");
1321613216

13217+
// Variables annotated with availability_domain need to be deserialized.
13218+
if (VD->hasAttr<AvailabilityDomainAttr>())
13219+
return true;
13220+
1321713221
// If the decl is marked as `declare target to`, it should be emitted for the
1321813222
// host and for the device.
1321913223
if (LangOpts.OpenMP &&

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15649,11 +15649,8 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
1564915649
}
1565015650
}
1565115651

15652-
std::pair<StringRef, ASTContext::AvailabilityDomainInfo> ADInfo =
15653-
getASTContext().getFeatureAvailInfo(VD);
15654-
15655-
if (!ADInfo.first.empty())
15656-
getASTContext().addAvailabilityDomainMap(ADInfo.first, ADInfo.second);
15652+
if (auto *Attr = VD->getAttr<AvailabilityDomainAttr>())
15653+
getASTContext().addAvailabilityDomainMap(Attr->getName()->getName(), VD);
1565715654

1565815655
const DeclContext *DC = VD->getDeclContext();
1565915656
// If there's a #pragma GCC visibility in scope, and this isn't a class

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,10 @@ ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
16831683
}
16841684
}
16851685

1686+
if (auto *Attr = VD->getAttr<AvailabilityDomainAttr>())
1687+
Reader.getContext().addAvailabilityDomainMap(Attr->getName()->getName(),
1688+
VD);
1689+
16861690
return Redecl;
16871691
}
16881692

0 commit comments

Comments
 (0)