Skip to content

[Sema] Migrate away from PointerUnion::{is,get} (NFC) #117498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaAPINotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod AnyFunc,
Decl *D = FD;
ObjCMethodDecl *MD = nullptr;
if (!D) {
MD = AnyFunc.get<ObjCMethodDecl *>();
MD = cast<ObjCMethodDecl *>(AnyFunc);
D = MD;
}

Expand Down
16 changes: 8 additions & 8 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class ResultBuilder {
}

// Add the new element to the end of the vector.
DeclOrVector.get<DeclIndexPairVector *>()->push_back(
DeclIndexPair(ND, Index));
cast<DeclIndexPairVector *>(DeclOrVector)
->push_back(DeclIndexPair(ND, Index));
}

~ShadowMapEntry() {
Expand Down Expand Up @@ -659,13 +659,13 @@ class ResultBuilder::ShadowMapEntry::iterator {
: DeclOrIterator(Iterator), SingleDeclIndex(0) {}

iterator &operator++() {
if (DeclOrIterator.is<const NamedDecl *>()) {
if (isa<const NamedDecl *>(DeclOrIterator)) {
DeclOrIterator = (NamedDecl *)nullptr;
SingleDeclIndex = 0;
return *this;
}

const DeclIndexPair *I = DeclOrIterator.get<const DeclIndexPair *>();
const DeclIndexPair *I = cast<const DeclIndexPair *>(DeclOrIterator);
++I;
DeclOrIterator = I;
return *this;
Expand All @@ -681,7 +681,7 @@ class ResultBuilder::ShadowMapEntry::iterator {
if (const NamedDecl *ND = DeclOrIterator.dyn_cast<const NamedDecl *>())
return reference(ND, SingleDeclIndex);

return *DeclOrIterator.get<const DeclIndexPair *>();
return *cast<const DeclIndexPair *>(DeclOrIterator);
}

pointer operator->() const { return pointer(**this); }
Expand All @@ -705,15 +705,15 @@ ResultBuilder::ShadowMapEntry::begin() const {
if (const NamedDecl *ND = DeclOrVector.dyn_cast<const NamedDecl *>())
return iterator(ND, SingleDeclIndex);

return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin());
return iterator(cast<DeclIndexPairVector *>(DeclOrVector)->begin());
}

ResultBuilder::ShadowMapEntry::iterator
ResultBuilder::ShadowMapEntry::end() const {
if (DeclOrVector.is<const NamedDecl *>() || DeclOrVector.isNull())
if (isa<const NamedDecl *>(DeclOrVector) || DeclOrVector.isNull())
return iterator();

return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end());
return iterator(cast<DeclIndexPairVector *>(DeclOrVector)->end());
}

/// Compute the qualification required to get from the current context
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,7 @@ static void diagnoseUnsatisfiedConstraintExpr(
return;
}

diagnoseWellFormedUnsatisfiedConstraintExpr(S,
Record.template get<Expr *>(), First);
diagnoseWellFormedUnsatisfiedConstraintExpr(S, cast<Expr *>(Record), First);
}

void
Expand Down Expand Up @@ -1557,12 +1556,12 @@ NormalizedConstraint::NormalizedConstraint(ASTContext &C,

NormalizedConstraint &NormalizedConstraint::getLHS() const {
assert(isCompound() && "getLHS called on a non-compound constraint.");
return Constraint.get<CompoundConstraint>().getPointer()->LHS;
return cast<CompoundConstraint>(Constraint).getPointer()->LHS;
}

NormalizedConstraint &NormalizedConstraint::getRHS() const {
assert(isCompound() && "getRHS called on a non-compound constraint.");
return Constraint.get<CompoundConstraint>().getPointer()->RHS;
return cast<CompoundConstraint>(Constraint).getPointer()->RHS;
}

std::optional<NormalizedConstraint>
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17276,7 +17276,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo *>())
ED->setIntegerTypeSourceInfo(TI);
else
ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0));
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
QualType EnumTy = ED->getIntegerType();
ED->setPromotionType(Context.isPromotableIntegerType(EnumTy)
? Context.getPromotedIntegerType(EnumTy)
Expand Down Expand Up @@ -17909,7 +17909,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo*>())
ED->setIntegerTypeSourceInfo(TI);
else
ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0));
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
QualType EnumTy = ED->getIntegerType();
ED->setPromotionType(Context.isPromotableIntegerType(EnumTy)
? Context.getPromotedIntegerType(EnumTy)
Expand Down Expand Up @@ -19925,7 +19925,7 @@ static void CheckForDuplicateEnumValues(Sema &S, ArrayRef<Decl *> Elements,
continue;
}

ECDVector *Vec = Entry.get<ECDVector*>();
ECDVector *Vec = cast<ECDVector *>(Entry);
// Make sure constants are not added more than once.
if (*Vec->begin() == ECD)
continue;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D,
auto DiagnoseType = [&](unsigned Index, AttributeArgumentNType T) {
SourceLocation Loc = [&]() {
auto Union = AL.getArg(Index - 1);
if (Union.is<Expr *>())
return Union.get<Expr *>()->getBeginLoc();
return Union.get<IdentifierLoc *>()->Loc;
if (auto *E = dyn_cast<Expr *>(Union))
return E->getBeginLoc();
return cast<IdentifierLoc *>(Union)->Loc;
}();

S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9218,7 +9218,7 @@ struct SpecialMemberVisitor {
if (auto *B = Subobj.dyn_cast<CXXBaseSpecifier*>())
return B->getBaseTypeLoc();
else
return Subobj.get<FieldDecl*>()->getLocation();
return cast<FieldDecl *>(Subobj)->getLocation();
}

enum BasesToVisit {
Expand Down Expand Up @@ -9369,7 +9369,7 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
<< /*IsField*/ true << Field << DiagKind << IsDtorCallInCtor
<< /*IsObjCPtr*/ false;
} else {
CXXBaseSpecifier *Base = Subobj.get<CXXBaseSpecifier*>();
CXXBaseSpecifier *Base = cast<CXXBaseSpecifier *>(Subobj);
S.Diag(Base->getBeginLoc(),
diag::note_deleted_special_member_class_subobject)
<< llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
Expand Down Expand Up @@ -17487,7 +17487,7 @@ DeclResult Sema::ActOnTemplatedFriendTag(
if (getDepthAndIndex(U).first >= FriendDeclDepth) {
auto *ND = U.first.dyn_cast<NamedDecl *>();
if (!ND)
ND = U.first.get<const TemplateTypeParmType *>()->getDecl();
ND = cast<const TemplateTypeParmType *>(U.first)->getDecl();
Diag(U.second, diag::friend_template_decl_malformed_pack_expansion)
<< ND->getDeclName() << SourceRange(SS.getBeginLoc(), EllipsisLoc);
return true;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
if (auto *actualTypeDecl = typeDecl.dyn_cast<TypeDecl *>())
type = Context.getTypeDeclType(actualTypeDecl);
else
type = Context.getObjCInterfaceType(typeDecl.get<ObjCInterfaceDecl *>());
type = Context.getObjCInterfaceType(cast<ObjCInterfaceDecl *>(typeDecl));
TypeSourceInfo *parsedTSInfo = Context.getTrivialTypeSourceInfo(type, loc);
ParsedType parsedType = SemaRef.CreateParsedType(type, parsedTSInfo);
DS.SetTypeSpecType(DeclSpec::TST_typename, loc, prevSpec, diagID,
Expand Down
14 changes: 6 additions & 8 deletions clang/lib/Sema/SemaFunctionEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class Analyzer {
CompleteFunctionAnalysis *completedAnalysisForDecl(const Decl *D) const {
if (FuncAnalysisPtr AP = lookup(D);
isa_and_nonnull<CompleteFunctionAnalysis *>(AP))
return AP.get<CompleteFunctionAnalysis *>();
return cast<CompleteFunctionAnalysis *>(AP);
return nullptr;
}

Expand All @@ -528,12 +528,10 @@ class Analyzer {
OS << item.first << " " << CI.getNameForDiagnostic(SemaRef) << " : ";
if (AP.isNull()) {
OS << "null\n";
} else if (isa<CompleteFunctionAnalysis *>(AP)) {
auto *CFA = AP.get<CompleteFunctionAnalysis *>();
} else if (auto *CFA = dyn_cast<CompleteFunctionAnalysis *>(AP)) {
OS << CFA << " ";
CFA->dump(OS);
} else if (isa<PendingFunctionAnalysis *>(AP)) {
auto *PFA = AP.get<PendingFunctionAnalysis *>();
} else if (auto *PFA = dyn_cast<PendingFunctionAnalysis *>(AP)) {
OS << PFA << " ";
PFA->dump(SemaRef, OS);
} else
Expand Down Expand Up @@ -1376,10 +1374,10 @@ class Analyzer {
Analyzer::AnalysisMap::~AnalysisMap() {
for (const auto &Item : *this) {
FuncAnalysisPtr AP = Item.second;
if (isa<PendingFunctionAnalysis *>(AP))
delete AP.get<PendingFunctionAnalysis *>();
if (auto *PFA = dyn_cast<PendingFunctionAnalysis *>(AP))
delete PFA;
else
delete AP.get<CompleteFunctionAnalysis *>();
delete cast<CompleteFunctionAnalysis *>(AP);
}
}

Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,10 +1611,10 @@ const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData(
continue;
const ReductionData &ReductionData = I->ReductionMap.lookup(D);
if (!ReductionData.ReductionOp ||
ReductionData.ReductionOp.is<const Expr *>())
isa<const Expr *>(ReductionData.ReductionOp))
return DSAVarData();
SR = ReductionData.ReductionRange;
BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>();
BOK = cast<ReductionData::BOKPtrType>(ReductionData.ReductionOp);
assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
"expression for the descriptor is not "
"set.");
Expand All @@ -1638,10 +1638,10 @@ const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData(
continue;
const ReductionData &ReductionData = I->ReductionMap.lookup(D);
if (!ReductionData.ReductionOp ||
!ReductionData.ReductionOp.is<const Expr *>())
!isa<const Expr *>(ReductionData.ReductionOp))
return DSAVarData();
SR = ReductionData.ReductionRange;
ReductionRef = ReductionData.ReductionOp.get<const Expr *>();
ReductionRef = cast<const Expr *>(ReductionData.ReductionOp);
assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
"expression for the descriptor is not "
"set.");
Expand Down
12 changes: 6 additions & 6 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
if (Partial->isMemberSpecialization())
return Response::Done();
} else {
VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
VarTemplateDecl *Tmpl = cast<VarTemplateDecl *>(Specialized);
if (!SkipForSpecialization)
Result.addOuterTemplateArguments(
Tmpl, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
Expand Down Expand Up @@ -2458,7 +2458,7 @@ TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,

TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
} else {
TransformedDecl = Found->get<Decl*>();
TransformedDecl = cast<Decl *>(*Found);
}

// We have either an unexpanded pack or a specific expansion.
Expand Down Expand Up @@ -2827,7 +2827,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(),
std::move(*TransRetReq));
return RebuildExprRequirement(
TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(),
cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
}

Expand Down Expand Up @@ -4053,7 +4053,7 @@ getPatternForClassTemplateSpecialization(
llvm::PointerUnion<ClassTemplateDecl *,
ClassTemplatePartialSpecializationDecl *>
Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
if (!isa<ClassTemplatePartialSpecializationDecl *>(Specialized)) {
// Find best matching specialization.
ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();

Expand Down Expand Up @@ -4664,14 +4664,14 @@ void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) {
} else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
Pack->push_back(cast<VarDecl>(Inst));
} else {
assert(Stored.get<Decl *>() == Inst && "Already instantiated this local");
assert(cast<Decl *>(Stored) == Inst && "Already instantiated this local");
}
}

void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D,
VarDecl *Inst) {
D = getCanonicalParmVarDecl(D);
DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
DeclArgumentPack *Pack = cast<DeclArgumentPack *>(LocalDecls[D]);
Pack->push_back(Inst);
}

Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3720,8 +3720,8 @@ Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl(
auto *PrevDeclInScope = D->getPrevDeclInScope();
if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
PrevDeclInScope = cast<OMPDeclareReductionDecl>(
SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope)
->get<Decl *>());
cast<Decl *>(*SemaRef.CurrentInstantiationScope->findInstantiationOf(
PrevDeclInScope)));
}
auto DRD = SemaRef.OpenMP().ActOnOpenMPDeclareReductionDirectiveStart(
/*S=*/nullptr, Owner, D->getDeclName(), ReductionTypes, D->getAccess(),
Expand Down Expand Up @@ -3807,8 +3807,8 @@ TemplateDeclInstantiator::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
auto *PrevDeclInScope = D->getPrevDeclInScope();
if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
PrevDeclInScope = cast<OMPDeclareMapperDecl>(
SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope)
->get<Decl *>());
cast<Decl *>(*SemaRef.CurrentInstantiationScope->findInstantiationOf(
PrevDeclInScope)));
}
bool IsCorrect = true;
SmallVector<OMPClause *, 6> Clauses;
Expand Down Expand Up @@ -6186,7 +6186,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
assert(PackIdx != -1 &&
"found declaration pack but not pack expanding");
typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]);
return cast<NamedDecl>((*cast<DeclArgumentPack *>(*Found))[PackIdx]);
}
}

Expand Down
20 changes: 10 additions & 10 deletions clang/lib/Sema/SemaTemplateVariadic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
return TTPD && TTPD->getTypeForDecl() == TTPT;
}
return declaresSameEntity(Pack.first.get<NamedDecl *>(), LocalPack);
return declaresSameEntity(cast<NamedDecl *>(Pack.first), LocalPack);
};
if (llvm::any_of(CSI->LocalPacks, DeclaresThisPack))
ParamPackReferences.push_back(Pack);
Expand Down Expand Up @@ -423,7 +423,7 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
= Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
Name = TTP->getIdentifier();
else
Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
Name = cast<NamedDecl *>(Unexpanded[I].first)->getIdentifier();

if (Name && NamesKnown.insert(Name).second)
Names.push_back(Name);
Expand Down Expand Up @@ -770,7 +770,7 @@ bool Sema::CheckParameterPacksForExpansion(
Index = TTP->getIndex();
Name = TTP->getIdentifier();
} else {
NamedDecl *ND = ParmPack.first.get<NamedDecl *>();
NamedDecl *ND = cast<NamedDecl *>(ParmPack.first);
if (isa<VarDecl>(ND))
IsVarDeclPack = true;
else
Expand All @@ -787,10 +787,10 @@ bool Sema::CheckParameterPacksForExpansion(

llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
CurrentInstantiationScope->findInstantiationOf(
ParmPack.first.get<NamedDecl *>());
if (Instantiation->is<DeclArgumentPack *>()) {
cast<NamedDecl *>(ParmPack.first));
if (isa<DeclArgumentPack *>(*Instantiation)) {
// We could expand this function parameter pack.
NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
NewPackSize = cast<DeclArgumentPack *>(*Instantiation)->size();
} else {
// We can't expand this function parameter pack, so we can't expand
// the pack expansion.
Expand Down Expand Up @@ -895,20 +895,20 @@ std::optional<unsigned> Sema::getNumArgumentsInExpansionFromUnexpanded(
Depth = TTP->getDepth();
Index = TTP->getIndex();
} else {
NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
NamedDecl *ND = cast<NamedDecl *>(Unexpanded[I].first);
if (isa<VarDecl>(ND)) {
// Function parameter pack or init-capture pack.
typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;

llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
CurrentInstantiationScope->findInstantiationOf(
Unexpanded[I].first.get<NamedDecl *>());
if (Instantiation->is<Decl *>())
cast<NamedDecl *>(Unexpanded[I].first));
if (isa<Decl *>(*Instantiation))
// The pattern refers to an unexpanded pack. We're not ready to expand
// this pack yet.
return std::nullopt;

unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
unsigned Size = cast<DeclArgumentPack *>(*Instantiation)->size();
assert((!Result || *Result == Size) && "inconsistent pack sizes");
Result = Size;
continue;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14453,7 +14453,7 @@ TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req)
Req->getNoexceptLoc(),
std::move(*TransRetReq));
return getDerived().RebuildExprRequirement(
TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(),
cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
}

Expand Down
Loading