Skip to content

Commit 1e3e199

Browse files
[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
1 parent 2f02b5a commit 1e3e199

13 files changed

+54
-57
lines changed

clang/lib/Sema/SemaAPINotes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static void ProcessAPINotes(Sema &S, FunctionOrMethod AnyFunc,
482482
Decl *D = FD;
483483
ObjCMethodDecl *MD = nullptr;
484484
if (!D) {
485-
MD = AnyFunc.get<ObjCMethodDecl *>();
485+
MD = cast<ObjCMethodDecl *>(AnyFunc);
486486
D = MD;
487487
}
488488

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class ResultBuilder {
131131
}
132132

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

138138
~ShadowMapEntry() {
@@ -659,13 +659,13 @@ class ResultBuilder::ShadowMapEntry::iterator {
659659
: DeclOrIterator(Iterator), SingleDeclIndex(0) {}
660660

661661
iterator &operator++() {
662-
if (DeclOrIterator.is<const NamedDecl *>()) {
662+
if (isa<const NamedDecl *>(DeclOrIterator)) {
663663
DeclOrIterator = (NamedDecl *)nullptr;
664664
SingleDeclIndex = 0;
665665
return *this;
666666
}
667667

668-
const DeclIndexPair *I = DeclOrIterator.get<const DeclIndexPair *>();
668+
const DeclIndexPair *I = cast<const DeclIndexPair *>(DeclOrIterator);
669669
++I;
670670
DeclOrIterator = I;
671671
return *this;
@@ -681,7 +681,7 @@ class ResultBuilder::ShadowMapEntry::iterator {
681681
if (const NamedDecl *ND = DeclOrIterator.dyn_cast<const NamedDecl *>())
682682
return reference(ND, SingleDeclIndex);
683683

684-
return *DeclOrIterator.get<const DeclIndexPair *>();
684+
return *cast<const DeclIndexPair *>(DeclOrIterator);
685685
}
686686

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

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

711711
ResultBuilder::ShadowMapEntry::iterator
712712
ResultBuilder::ShadowMapEntry::end() const {
713-
if (DeclOrVector.is<const NamedDecl *>() || DeclOrVector.isNull())
713+
if (isa<const NamedDecl *>(DeclOrVector) || DeclOrVector.isNull())
714714
return iterator();
715715

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

719719
/// Compute the qualification required to get from the current context

clang/lib/Sema/SemaConcept.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,7 @@ static void diagnoseUnsatisfiedConstraintExpr(
13841384
return;
13851385
}
13861386

1387-
diagnoseWellFormedUnsatisfiedConstraintExpr(S,
1388-
Record.template get<Expr *>(), First);
1387+
diagnoseWellFormedUnsatisfiedConstraintExpr(S, cast<Expr *>(Record), First);
13891388
}
13901389

13911390
void
@@ -1557,12 +1556,12 @@ NormalizedConstraint::NormalizedConstraint(ASTContext &C,
15571556

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

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

15681567
std::optional<NormalizedConstraint>

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17276,7 +17276,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1727617276
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo *>())
1727717277
ED->setIntegerTypeSourceInfo(TI);
1727817278
else
17279-
ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0));
17279+
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
1728017280
QualType EnumTy = ED->getIntegerType();
1728117281
ED->setPromotionType(Context.isPromotableIntegerType(EnumTy)
1728217282
? Context.getPromotedIntegerType(EnumTy)
@@ -17909,7 +17909,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1790917909
if (TypeSourceInfo *TI = EnumUnderlying.dyn_cast<TypeSourceInfo*>())
1791017910
ED->setIntegerTypeSourceInfo(TI);
1791117911
else
17912-
ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0));
17912+
ED->setIntegerType(QualType(cast<const Type *>(EnumUnderlying), 0));
1791317913
QualType EnumTy = ED->getIntegerType();
1791417914
ED->setPromotionType(Context.isPromotableIntegerType(EnumTy)
1791517915
? Context.getPromotedIntegerType(EnumTy)
@@ -19925,7 +19925,7 @@ static void CheckForDuplicateEnumValues(Sema &S, ArrayRef<Decl *> Elements,
1992519925
continue;
1992619926
}
1992719927

19928-
ECDVector *Vec = Entry.get<ECDVector*>();
19928+
ECDVector *Vec = cast<ECDVector *>(Entry);
1992919929
// Make sure constants are not added more than once.
1993019930
if (*Vec->begin() == ECD)
1993119931
continue;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D,
776776
auto DiagnoseType = [&](unsigned Index, AttributeArgumentNType T) {
777777
SourceLocation Loc = [&]() {
778778
auto Union = AL.getArg(Index - 1);
779-
if (Union.is<Expr *>())
780-
return Union.get<Expr *>()->getBeginLoc();
781-
return Union.get<IdentifierLoc *>()->Loc;
779+
if (auto *E = dyn_cast<Expr *>(Union))
780+
return E->getBeginLoc();
781+
return cast<IdentifierLoc *>(Union)->Loc;
782782
}();
783783

784784
S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9218,7 +9218,7 @@ struct SpecialMemberVisitor {
92189218
if (auto *B = Subobj.dyn_cast<CXXBaseSpecifier*>())
92199219
return B->getBaseTypeLoc();
92209220
else
9221-
return Subobj.get<FieldDecl*>()->getLocation();
9221+
return cast<FieldDecl *>(Subobj)->getLocation();
92229222
}
92239223

92249224
enum BasesToVisit {
@@ -9369,7 +9369,7 @@ bool SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
93699369
<< /*IsField*/ true << Field << DiagKind << IsDtorCallInCtor
93709370
<< /*IsObjCPtr*/ false;
93719371
} else {
9372-
CXXBaseSpecifier *Base = Subobj.get<CXXBaseSpecifier*>();
9372+
CXXBaseSpecifier *Base = cast<CXXBaseSpecifier *>(Subobj);
93739373
S.Diag(Base->getBeginLoc(),
93749374
diag::note_deleted_special_member_class_subobject)
93759375
<< llvm::to_underlying(getEffectiveCSM()) << MD->getParent()
@@ -17493,7 +17493,7 @@ DeclResult Sema::ActOnTemplatedFriendTag(
1749317493
if (getDepthAndIndex(U).first >= FriendDeclDepth) {
1749417494
auto *ND = U.first.dyn_cast<NamedDecl *>();
1749517495
if (!ND)
17496-
ND = U.first.get<const TemplateTypeParmType *>()->getDecl();
17496+
ND = cast<const TemplateTypeParmType *>(U.first)->getDecl();
1749717497
Diag(U.second, diag::friend_template_decl_malformed_pack_expansion)
1749817498
<< ND->getDeclName() << SourceRange(SS.getBeginLoc(), EllipsisLoc);
1749917499
return true;

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
15871587
if (auto *actualTypeDecl = typeDecl.dyn_cast<TypeDecl *>())
15881588
type = Context.getTypeDeclType(actualTypeDecl);
15891589
else
1590-
type = Context.getObjCInterfaceType(typeDecl.get<ObjCInterfaceDecl *>());
1590+
type = Context.getObjCInterfaceType(cast<ObjCInterfaceDecl *>(typeDecl));
15911591
TypeSourceInfo *parsedTSInfo = Context.getTrivialTypeSourceInfo(type, loc);
15921592
ParsedType parsedType = SemaRef.CreateParsedType(type, parsedTSInfo);
15931593
DS.SetTypeSpecType(DeclSpec::TST_typename, loc, prevSpec, diagID,

clang/lib/Sema/SemaFunctionEffects.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class Analyzer {
516516
CompleteFunctionAnalysis *completedAnalysisForDecl(const Decl *D) const {
517517
if (FuncAnalysisPtr AP = lookup(D);
518518
isa_and_nonnull<CompleteFunctionAnalysis *>(AP))
519-
return AP.get<CompleteFunctionAnalysis *>();
519+
return cast<CompleteFunctionAnalysis *>(AP);
520520
return nullptr;
521521
}
522522

@@ -528,12 +528,10 @@ class Analyzer {
528528
OS << item.first << " " << CI.getNameForDiagnostic(SemaRef) << " : ";
529529
if (AP.isNull()) {
530530
OS << "null\n";
531-
} else if (isa<CompleteFunctionAnalysis *>(AP)) {
532-
auto *CFA = AP.get<CompleteFunctionAnalysis *>();
531+
} else if (auto *CFA = dyn_cast<CompleteFunctionAnalysis *>(AP)) {
533532
OS << CFA << " ";
534533
CFA->dump(OS);
535-
} else if (isa<PendingFunctionAnalysis *>(AP)) {
536-
auto *PFA = AP.get<PendingFunctionAnalysis *>();
534+
} else if (auto *PFA = dyn_cast<PendingFunctionAnalysis *>(AP)) {
537535
OS << PFA << " ";
538536
PFA->dump(SemaRef, OS);
539537
} else
@@ -1376,10 +1374,10 @@ class Analyzer {
13761374
Analyzer::AnalysisMap::~AnalysisMap() {
13771375
for (const auto &Item : *this) {
13781376
FuncAnalysisPtr AP = Item.second;
1379-
if (isa<PendingFunctionAnalysis *>(AP))
1380-
delete AP.get<PendingFunctionAnalysis *>();
1377+
if (auto *PFA = dyn_cast<PendingFunctionAnalysis *>(AP))
1378+
delete PFA;
13811379
else
1382-
delete AP.get<CompleteFunctionAnalysis *>();
1380+
delete cast<CompleteFunctionAnalysis *>(AP);
13831381
}
13841382
}
13851383

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,10 +1611,10 @@ const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData(
16111611
continue;
16121612
const ReductionData &ReductionData = I->ReductionMap.lookup(D);
16131613
if (!ReductionData.ReductionOp ||
1614-
ReductionData.ReductionOp.is<const Expr *>())
1614+
isa<const Expr *>(ReductionData.ReductionOp))
16151615
return DSAVarData();
16161616
SR = ReductionData.ReductionRange;
1617-
BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>();
1617+
BOK = cast<ReductionData::BOKPtrType>(ReductionData.ReductionOp);
16181618
assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
16191619
"expression for the descriptor is not "
16201620
"set.");
@@ -1638,10 +1638,10 @@ const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData(
16381638
continue;
16391639
const ReductionData &ReductionData = I->ReductionMap.lookup(D);
16401640
if (!ReductionData.ReductionOp ||
1641-
!ReductionData.ReductionOp.is<const Expr *>())
1641+
!isa<const Expr *>(ReductionData.ReductionOp))
16421642
return DSAVarData();
16431643
SR = ReductionData.ReductionRange;
1644-
ReductionRef = ReductionData.ReductionOp.get<const Expr *>();
1644+
ReductionRef = cast<const Expr *>(ReductionData.ReductionOp);
16451645
assert(I->TaskgroupReductionRef && "taskgroup reduction reference "
16461646
"expression for the descriptor is not "
16471647
"set.");

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
198198
if (Partial->isMemberSpecialization())
199199
return Response::Done();
200200
} else {
201-
VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
201+
VarTemplateDecl *Tmpl = cast<VarTemplateDecl *>(Specialized);
202202
if (!SkipForSpecialization)
203203
Result.addOuterTemplateArguments(
204204
Tmpl, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
@@ -2458,7 +2458,7 @@ TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
24582458

24592459
TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
24602460
} else {
2461-
TransformedDecl = Found->get<Decl*>();
2461+
TransformedDecl = cast<Decl *>(*Found);
24622462
}
24632463

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

@@ -4053,7 +4053,7 @@ getPatternForClassTemplateSpecialization(
40534053
llvm::PointerUnion<ClassTemplateDecl *,
40544054
ClassTemplatePartialSpecializationDecl *>
40554055
Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
4056-
if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
4056+
if (!isa<ClassTemplatePartialSpecializationDecl *>(Specialized)) {
40574057
// Find best matching specialization.
40584058
ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
40594059

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

46714671
void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D,
46724672
VarDecl *Inst) {
46734673
D = getCanonicalParmVarDecl(D);
4674-
DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
4674+
DeclArgumentPack *Pack = cast<DeclArgumentPack *>(LocalDecls[D]);
46754675
Pack->push_back(Inst);
46764676
}
46774677

0 commit comments

Comments
 (0)