Skip to content

Commit d01c11d

Browse files
[clang] Migrate away from PointerUnion::{is,get} (NFC) (#119724)
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 ea6e135 commit d01c11d

File tree

11 files changed

+30
-32
lines changed

11 files changed

+30
-32
lines changed

clang/include/clang/Basic/FileEntry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FileEntryRef {
6868
StringRef getNameAsRequested() const { return ME->first(); }
6969

7070
const FileEntry &getFileEntry() const {
71-
return *getBaseMapEntry().second->V.get<FileEntry *>();
71+
return *cast<FileEntry *>(getBaseMapEntry().second->V);
7272
}
7373

7474
// This function is used if the buffer size needs to be increased
@@ -361,7 +361,7 @@ bool FileEntryRef::isNamedPipe() const { return getFileEntry().isNamedPipe(); }
361361
void FileEntryRef::closeFile() const { getFileEntry().closeFile(); }
362362

363363
void FileEntryRef::updateFileEntryBufferSize(unsigned BufferSize) {
364-
getBaseMapEntry().second->V.get<FileEntry *>()->setSize(BufferSize);
364+
cast<FileEntry *>(getBaseMapEntry().second->V)->setSize(BufferSize);
365365
}
366366

367367
} // end namespace clang

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,15 +1012,15 @@ class Selector {
10121012
}
10131013

10141014
MultiKeywordSelector *getMultiKeywordSelector() const {
1015-
return InfoPtr.getPointer().get<MultiKeywordSelector *>();
1015+
return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
10161016
}
10171017

10181018
unsigned getIdentifierInfoFlag() const {
10191019
unsigned new_flags = InfoPtr.getInt();
10201020
// IMPORTANT NOTE: We have to reconstitute this data rather than use the
10211021
// value directly from the PointerIntPair. See the comments in `InfoPtr`
10221022
// for more details.
1023-
if (InfoPtr.getPointer().is<MultiKeywordSelector *>())
1023+
if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
10241024
new_flags |= MultiArg;
10251025
return new_flags;
10261026
}

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,17 @@ class ParsedAttr final
392392
}
393393

394394
bool isArgExpr(unsigned Arg) const {
395-
return Arg < NumArgs && getArg(Arg).is<Expr*>();
395+
return Arg < NumArgs && isa<Expr *>(getArg(Arg));
396396
}
397397

398-
Expr *getArgAsExpr(unsigned Arg) const {
399-
return getArg(Arg).get<Expr*>();
400-
}
398+
Expr *getArgAsExpr(unsigned Arg) const { return cast<Expr *>(getArg(Arg)); }
401399

402400
bool isArgIdent(unsigned Arg) const {
403-
return Arg < NumArgs && getArg(Arg).is<IdentifierLoc*>();
401+
return Arg < NumArgs && isa<IdentifierLoc *>(getArg(Arg));
404402
}
405403

406404
IdentifierLoc *getArgAsIdent(unsigned Arg) const {
407-
return getArg(Arg).get<IdentifierLoc*>();
405+
return cast<IdentifierLoc *>(getArg(Arg));
408406
}
409407

410408
const AvailabilityChange &getAvailabilityIntroduced() const {

clang/include/clang/Sema/SemaConcept.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ bool subsumes(const NormalForm &PDNF, const NormalForm &QCNF,
210210
bool Found = false;
211211
for (NormalFormConstraint Pia : Pi) {
212212
for (NormalFormConstraint Qjb : Qj) {
213-
if (Pia.is<FoldExpandedConstraint *>() &&
214-
Qjb.is<FoldExpandedConstraint *>()) {
215-
if (Pia.get<FoldExpandedConstraint *>()->subsumes(
216-
*Qjb.get<FoldExpandedConstraint *>(), E)) {
213+
if (isa<FoldExpandedConstraint *>(Pia) &&
214+
isa<FoldExpandedConstraint *>(Qjb)) {
215+
if (cast<FoldExpandedConstraint *>(Pia)->subsumes(
216+
*cast<FoldExpandedConstraint *>(Qjb), E)) {
217217
Found = true;
218218
break;
219219
}
220-
} else if (Pia.is<AtomicConstraint *>() &&
221-
Qjb.is<AtomicConstraint *>()) {
222-
if (E(*Pia.get<AtomicConstraint *>(),
223-
*Qjb.get<AtomicConstraint *>())) {
220+
} else if (isa<AtomicConstraint *>(Pia) &&
221+
isa<AtomicConstraint *>(Qjb)) {
222+
if (E(*cast<AtomicConstraint *>(Pia),
223+
*cast<AtomicConstraint *>(Qjb))) {
224224
Found = true;
225225
break;
226226
}

clang/include/clang/Sema/SemaInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ getDepthAndIndex(UnexpandedParameterPack UPP) {
7575
if (const auto *TTP = UPP.first.dyn_cast<const TemplateTypeParmType *>())
7676
return std::make_pair(TTP->getDepth(), TTP->getIndex());
7777

78-
return getDepthAndIndex(UPP.first.get<NamedDecl *>());
78+
return getDepthAndIndex(cast<NamedDecl *>(UPP.first));
7979
}
8080

8181
class TypoCorrectionConsumer : public VisibleDeclConsumer {

clang/include/clang/Sema/Template.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ enum class TemplateSubstitutionKind : char {
486486
const Decl *D = I->first;
487487
llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
488488
newScope->LocalDecls[D];
489-
if (I->second.is<Decl *>()) {
490-
Stored = I->second.get<Decl *>();
489+
if (auto *D2 = dyn_cast<Decl *>(I->second)) {
490+
Stored = D2;
491491
} else {
492-
DeclArgumentPack *OldPack = I->second.get<DeclArgumentPack *>();
492+
DeclArgumentPack *OldPack = cast<DeclArgumentPack *>(I->second);
493493
DeclArgumentPack *NewPack = new DeclArgumentPack(*OldPack);
494494
Stored = NewPack;
495495
newScope->ArgumentPacks.push_back(NewPack);

clang/lib/APINotes/APINotesManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ APINotesManager::findAPINotes(SourceLocation Loc) {
374374
++NumDirectoryCacheHits;
375375

376376
// We've been redirected to another directory for answers. Follow it.
377-
if (Known->second && Known->second.is<DirectoryEntryRef>()) {
377+
if (Known->second && isa<DirectoryEntryRef>(Known->second)) {
378378
DirsVisited.insert(*Dir);
379-
Dir = Known->second.get<DirectoryEntryRef>();
379+
Dir = cast<DirectoryEntryRef>(Known->second);
380380
continue;
381381
}
382382

clang/lib/Analysis/ThreadSafetyCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE,
326326
}
327327

328328
assert(I == 0);
329-
return Ctx->FunArgs.get<til::SExpr *>();
329+
return cast<til::SExpr *>(Ctx->FunArgs);
330330
}
331331
}
332332
// Map the param back to the param of the original function declaration

clang/lib/Basic/FileManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ llvm::Expected<FileEntryRef> FileManager::getFileRef(StringRef Filename,
324324
*SeenFileEntries
325325
.insert({Status.getName(), FileEntryRef::MapValue(*UFE, DirInfo)})
326326
.first;
327-
assert(Redirection.second->V.is<FileEntry *>() &&
327+
assert(isa<FileEntry *>(Redirection.second->V) &&
328328
"filename redirected to a non-canonical filename?");
329-
assert(Redirection.second->V.get<FileEntry *>() == UFE &&
329+
assert(cast<FileEntry *>(Redirection.second->V) == UFE &&
330330
"filename from getStatValue() refers to wrong file");
331331

332332
// Cache the redirection in the previously-inserted entry, still available
@@ -400,7 +400,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
400400
FileEntryRef::MapValue Value = *NamedFileEnt.second;
401401
if (LLVM_LIKELY(isa<FileEntry *>(Value.V)))
402402
return FileEntryRef(NamedFileEnt);
403-
return FileEntryRef(*Value.V.get<const FileEntryRef::MapEntry *>());
403+
return FileEntryRef(*cast<const FileEntryRef::MapEntry *>(Value.V));
404404
}
405405

406406
// We've not seen this before, or the file is cached as non-existent.
@@ -620,7 +620,7 @@ void FileManager::GetUniqueIDMapping(
620620

621621
for (const auto &Entry : SeenFileEntries) {
622622
// Only return files that exist and are not redirected.
623-
if (!Entry.getValue() || !Entry.getValue()->V.is<FileEntry *>())
623+
if (!Entry.getValue() || !isa<FileEntry *>(Entry.getValue()->V))
624624
continue;
625625
FileEntryRef FE(Entry);
626626
// Add this file if it's the first one with the UID, or if its name is

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,7 +4085,7 @@ static void emitDependData(CodeGenFunction &CGF, QualType &KmpDependInfoTy,
40854085
CGF.Builder.CreateConstGEP(DependenciesArray, *P), KmpDependInfoTy);
40864086
} else {
40874087
assert(E && "Expected a non-null expression");
4088-
LValue &PosLVal = *Pos.get<LValue *>();
4088+
LValue &PosLVal = *cast<LValue *>(Pos);
40894089
llvm::Value *Idx = CGF.EmitLoadOfScalar(PosLVal, E->getExprLoc());
40904090
Base = CGF.MakeAddrLValue(
40914091
CGF.Builder.CreateGEP(CGF, DependenciesArray, Idx), KmpDependInfoTy);
@@ -4113,7 +4113,7 @@ static void emitDependData(CodeGenFunction &CGF, QualType &KmpDependInfoTy,
41134113
if (unsigned *P = Pos.dyn_cast<unsigned *>()) {
41144114
++(*P);
41154115
} else {
4116-
LValue &PosLVal = *Pos.get<LValue *>();
4116+
LValue &PosLVal = *cast<LValue *>(Pos);
41174117
llvm::Value *Idx = CGF.EmitLoadOfScalar(PosLVal, E->getExprLoc());
41184118
Idx = CGF.Builder.CreateNUWAdd(Idx,
41194119
llvm::ConstantInt::get(Idx->getType(), 1));

clang/lib/Index/IndexDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
666666
Template = D->getSpecializedTemplateOrPartial();
667667
const Decl *SpecializationOf =
668668
isa<ClassTemplateDecl *>(Template)
669-
? (Decl *)Template.get<ClassTemplateDecl *>()
669+
? (Decl *)cast<ClassTemplateDecl *>(Template)
670670
: cast<ClassTemplatePartialSpecializationDecl *>(Template);
671671
if (!D->isThisDeclarationADefinition())
672672
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);

0 commit comments

Comments
 (0)