[llvm] [NFC][LLVM][Verifier] Use auto when assigning result of `dyn_cast` (PR #207343)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 3 01:02:13 PDT 2026
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/207343
None
>From 68fe3facda8cd1d2876e7ac371663169f8496bb6 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Fri, 3 Jul 2026 00:41:38 -0700
Subject: [PATCH] [NFC] Use auto when assigning result of `dyn_cast`
---
llvm/lib/IR/Verifier.cpp | 112 +++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 56 deletions(-)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 5f8b5e187bf14..8998086d825fa 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -568,7 +568,7 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
Check(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),
"Global is external, but doesn't have external or weak linkage!", &GV);
- if (const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
+ if (const auto *GO = dyn_cast<GlobalObject>(&GV)) {
if (const MDNode *Associated =
GO->getMetadata(LLVMContext::MD_associated)) {
Check(Associated->getNumOperands() == 1,
@@ -646,7 +646,7 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
"Only global variables can have appending linkage!", &GV);
if (GV.hasAppendingLinkage()) {
- const GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV);
+ const auto *GVar = dyn_cast<GlobalVariable>(&GV);
Check(GVar && GVar->getValueType()->isArrayTy(),
"Only global arrays can have appending linkage!", GVar);
}
@@ -678,7 +678,7 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
&GV);
forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool {
- if (const Instruction *I = dyn_cast<Instruction>(V)) {
+ if (const auto *I = dyn_cast<Instruction>(V)) {
if (!I->getParent() || !I->getParent()->getParent())
CheckFailed("Global is referenced by parentless instruction!", &GV, &M,
I);
@@ -687,7 +687,7 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
I->getParent()->getParent(),
I->getParent()->getParent()->getParent());
return false;
- } else if (const Function *F = dyn_cast<Function>(V)) {
+ } else if (const auto *F = dyn_cast<Function>(V)) {
if (F->getParent() != &M)
CheckFailed("Global is used by function in a different module", &GV, &M,
F, F->getParent());
@@ -733,8 +733,8 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
// Don't worry about emitting an error for it not being an array,
// visitGlobalValue will complain on appending non-array.
- if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
- StructType *STy = dyn_cast<StructType>(ATy->getElementType());
+ if (const auto *ATy = dyn_cast<ArrayType>(GVType)) {
+ const auto *STy = dyn_cast<StructType>(ATy->getElementType());
PointerType *FuncPtrTy =
PointerType::get(Context, DL.getProgramAddressSpace());
Check(STy && (STy->getNumElements() == 2 || STy->getNumElements() == 3) &&
@@ -757,12 +757,12 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
Check(GV.materialized_use_empty(),
"invalid uses of intrinsic global variable", &GV);
- if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
- PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
+ if (const auto *ATy = dyn_cast<ArrayType>(GVType)) {
+ const auto *PTy = dyn_cast<PointerType>(ATy->getElementType());
Check(PTy, "wrong type for intrinsic global variable", &GV);
if (GV.hasInitializer()) {
const Constant *Init = GV.getInitializer();
- const ConstantArray *InitArray = dyn_cast<ConstantArray>(Init);
+ const auto *InitArray = dyn_cast<ConstantArray>(Init);
Check(InitArray, "wrong initializer for intrinsic global variable",
Init);
for (Value *Op : InitArray->operands()) {
@@ -780,7 +780,7 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
// Visit any debug info attachments.
SmallVector<MDNode *, 1> MDs;
GV.getMetadata(LLVMContext::MD_dbg, MDs);
- for (auto *MD : MDs) {
+ for (MDNode *MD : MDs) {
if (auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
visitDIGlobalVariableExpression(*GVE);
else
@@ -1015,13 +1015,14 @@ void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) {
// If this was an instruction, bb, or argument, verify that it is in the
// function that we expect.
Function *ActualF = nullptr;
- if (Instruction *I = dyn_cast<Instruction>(L->getValue())) {
+ if (auto *I = dyn_cast<Instruction>(L->getValue())) {
Check(I->getParent(), "function-local metadata not in basic block", L, I);
ActualF = I->getParent()->getParent();
- } else if (BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
+ } else if (auto *BB = dyn_cast<BasicBlock>(L->getValue())) {
ActualF = BB->getParent();
- else if (Argument *A = dyn_cast<Argument>(L->getValue()))
+ } else if (auto *A = dyn_cast<Argument>(L->getValue())) {
ActualF = A->getParent();
+ }
assert(ActualF && "Unimplemented function local metadata case!");
Check(ActualF == F, "function-local metadata used in wrong function", L);
@@ -1908,7 +1909,7 @@ Verifier::visitModuleFlag(const MDNode *Op,
case Module::Require: {
// The value should itself be an MDNode with two operands, a flag ID (an
// MDString), and a value.
- MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2));
+ auto *Value = dyn_cast<MDNode>(Op->getOperand(2));
Check(Value && Value->getNumOperands() == 2,
"invalid value for 'require' module flag (expected metadata pair)",
Op->getOperand(2));
@@ -2448,7 +2449,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
"'alloc-variant-zeroed' must name a function with the same "
"signature");
- if (const Function *F = dyn_cast<Function>(V))
+ if (const auto *F = dyn_cast<Function>(V))
Check(F->getCallingConv() == Variant->getCallingConv(),
"'alloc-variant-zeroed' must name a function with the same "
"calling convention");
@@ -2804,7 +2805,7 @@ void Verifier::verifyStatepoint(const CallBase &Call) {
Type *TargetElemType = Call.getParamElementType(2);
Check(TargetElemType,
"gc.statepoint callee argument must have elementtype attribute", Call);
- FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
+ auto *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
Check(TargetFuncType,
"gc.statepoint callee elementtype must be function type", Call);
@@ -2880,7 +2881,7 @@ void Verifier::verifyStatepoint(const CallBase &Call) {
// gc.relocate calls which are tied to this statepoint and thus part
// of the same statepoint sequence
for (const User *U : Call.users()) {
- const CallInst *UserCall = dyn_cast<const CallInst>(U);
+ const auto *UserCall = dyn_cast<const CallInst>(U);
Check(UserCall, "illegal use of statepoint token", Call, U);
if (!UserCall)
continue;
@@ -3797,7 +3798,7 @@ void Verifier::visitCallBase(CallBase &Call) {
Check(verifyAttributeCount(Attrs, Call.arg_size()),
"Attribute after last parameter!", Call);
- Function *Callee =
+ auto *Callee =
dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
bool IsIntrinsic = Callee && Callee->isIntrinsic();
if (IsIntrinsic)
@@ -4375,7 +4376,7 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs);
Check(ElTy, "Invalid indices for GEP pointer type!", &GEP);
- PointerType *PtrTy = dyn_cast<PointerType>(GEP.getType()->getScalarType());
+ auto *PtrTy = dyn_cast<PointerType>(GEP.getType()->getScalarType());
Check(PtrTy && GEP.getResultElementType() == ElTy,
"GEP is not of right type for indices!", &GEP, ElTy);
@@ -4526,7 +4527,7 @@ void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) {
}
void Verifier::visitLoadInst(LoadInst &LI) {
- PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
+ auto *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
Check(PTy, "Load operand must be a pointer.", &LI);
Type *ElTy = LI.getType();
if (MaybeAlign A = LI.getAlign()) {
@@ -4555,7 +4556,7 @@ void Verifier::visitLoadInst(LoadInst &LI) {
}
void Verifier::visitStoreInst(StoreInst &SI) {
- PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
+ auto *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
Check(PTy, "Store operand must be a pointer.", &SI);
Type *ElTy = SI.getOperand(0)->getType();
if (MaybeAlign A = SI.getAlign()) {
@@ -5146,7 +5147,7 @@ void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
// If the we have an invalid invoke, don't try to compute the dominance.
// We already reject it in the invoke specific checks and the dominance
// computation doesn't handle multiple edges.
- if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
+ if (auto *II = dyn_cast<InvokeInst>(Op)) {
if (II->getNormalDest() == II->getUnwindDest())
return;
}
@@ -5195,17 +5196,17 @@ void Verifier::visitNofreeMetadata(Instruction &I, MDNode *MD) {
void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
auto GetBranchingTerminatorNumOperands = [&]() {
unsigned ExpectedNumOperands = 0;
- if (CondBrInst *BI = dyn_cast<CondBrInst>(&I))
+ if (auto *BI = dyn_cast<CondBrInst>(&I))
ExpectedNumOperands = BI->getNumSuccessors();
- else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I))
+ else if (auto *SI = dyn_cast<SwitchInst>(&I))
ExpectedNumOperands = SI->getNumSuccessors();
else if (isa<CallInst>(&I))
ExpectedNumOperands = 1;
- else if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(&I))
+ else if (auto *IBI = dyn_cast<IndirectBrInst>(&I))
ExpectedNumOperands = IBI->getNumDestinations();
else if (isa<SelectInst>(&I))
ExpectedNumOperands = 2;
- else if (CallBrInst *CI = dyn_cast<CallBrInst>(&I))
+ else if (auto *CI = dyn_cast<CallBrInst>(&I))
ExpectedNumOperands = CI->getNumSuccessors();
return ExpectedNumOperands;
};
@@ -5359,7 +5360,7 @@ void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) {
// Check each MIB
for (auto &MIBOp : MD->operands()) {
- MDNode *MIB = dyn_cast<MDNode>(MIBOp);
+ auto *MIB = dyn_cast<MDNode>(MIBOp);
// The first operand of an MIB should be the call stack metadata.
// There rest of the operands should be MDString tags, and there should be
// at least one.
@@ -5371,7 +5372,7 @@ void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) {
"!memprof MemInfoBlock first operand should not be null", MIB);
Check(isa<MDNode>(MIB->getOperand(0)),
"!memprof MemInfoBlock first operand should be an MDNode", MIB);
- MDNode *StackMD = dyn_cast<MDNode>(MIB->getOperand(0));
+ auto *StackMD = dyn_cast<MDNode>(MIB->getOperand(0));
visitCallStackMetadata(StackMD);
// The second MIB operand should be MDString.
@@ -5380,7 +5381,7 @@ void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) {
// Any remaining should be MDNode that are pairs of integers
for (unsigned I = 2; I < MIB->getNumOperands(); ++I) {
- MDNode *OpNode = dyn_cast<MDNode>(MIB->getOperand(I));
+ auto *OpNode = dyn_cast<MDNode>(MIB->getOperand(I));
Check(OpNode, "Not all !memprof MemInfoBlock operands 2 to N are MDNode",
MIB);
Check(OpNode->getNumOperands() == 2,
@@ -5455,7 +5456,7 @@ void Verifier::visitAliasScopeMetadata(const MDNode *MD) {
Check(isa<MDString>(MD->getOperand(2)),
"third scope operand must be string (if used)", MD);
- MDNode *Domain = dyn_cast<MDNode>(MD->getOperand(1));
+ auto *Domain = dyn_cast<MDNode>(MD->getOperand(1));
Check(Domain != nullptr, "second scope operand must be MDNode", MD);
unsigned NumDomainOps = Domain->getNumOperands();
@@ -5471,7 +5472,7 @@ void Verifier::visitAliasScopeMetadata(const MDNode *MD) {
void Verifier::visitAliasScopeListMetadata(const MDNode *MD) {
for (const MDOperand &Op : MD->operands()) {
- const MDNode *OpMD = dyn_cast<MDNode>(Op);
+ const auto *OpMD = dyn_cast<MDNode>(Op);
Check(OpMD != nullptr, "scope list must consist of MDNodes", MD);
visitAliasScopeMetadata(OpMD);
}
@@ -5488,7 +5489,7 @@ void Verifier::visitAccessGroupMetadata(const MDNode *MD) {
// ...or a list of access scopes.
for (const MDOperand &Op : MD->operands()) {
- const MDNode *OpMD = dyn_cast<MDNode>(Op);
+ const auto *OpMD = dyn_cast<MDNode>(Op);
Check(OpMD != nullptr, "Access scope list must consist of MDNodes", MD);
Check(IsValidAccessScope(OpMD),
"Access scope list contains invalid access scope", MD);
@@ -5643,7 +5644,7 @@ void Verifier::visitInstruction(Instruction &I) {
// themselves, actually have parent basic blocks. If the use is not an
// instruction, it is an error!
for (Use &U : I.uses()) {
- if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
+ if (auto *Used = dyn_cast<Instruction>(U.getUser()))
Check(Used->getParent() != nullptr,
"Instruction referencing"
" instruction not embedded in a basic block!",
@@ -5656,7 +5657,7 @@ void Verifier::visitInstruction(Instruction &I) {
// Get a pointer to the call base of the instruction if it is some form of
// call.
- const CallBase *CBI = dyn_cast<CallBase>(&I);
+ const auto *CBI = dyn_cast<CallBase>(&I);
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
Check(I.getOperand(i) != nullptr, "Instruction has null operand!", &I);
@@ -5667,7 +5668,7 @@ void Verifier::visitInstruction(Instruction &I) {
Check(false, "Instruction operands must be first-class values!", &I);
}
- if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
+ if (auto *F = dyn_cast<Function>(I.getOperand(i))) {
// This code checks whether the function is used as the operand of a
// clang_arc_attachedcall operand bundle.
auto IsAttachedCallOperand = [](Function *F, const CallBase *CBI,
@@ -5709,16 +5710,16 @@ void Verifier::visitInstruction(Instruction &I) {
&I);
Check(F->getParent() == &M, "Referencing function in another module!", &I,
&M, F, F->getParent());
- } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
+ } else if (auto *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
Check(OpBB->getParent() == BB->getParent(),
"Referring to a basic block in another function!", &I);
- } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
+ } else if (auto *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
Check(OpArg->getParent() == BB->getParent(),
"Referring to an argument in another function!", &I);
- } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
+ } else if (auto *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
Check(GV->getParent() == &M, "Referencing global in another module!", &I,
&M, GV, GV->getParent());
- } else if (Instruction *OpInst = dyn_cast<Instruction>(I.getOperand(i))) {
+ } else if (auto *OpInst = dyn_cast<Instruction>(I.getOperand(i))) {
Check(OpInst->getFunction() == BB->getParent(),
"Referring to an instruction in another function!", &I);
verifyDominatesUse(I, i);
@@ -6268,7 +6269,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
case Intrinsic::gcwrite:
case Intrinsic::gcread:
if (ID == Intrinsic::gcroot) {
- AllocaInst *AI =
+ auto *AI =
dyn_cast<AllocaInst>(Call.getArgOperand(0)->stripPointerCasts());
Check(AI, "llvm.gcroot parameter #1 must be an alloca.", Call);
Check(isa<Constant>(Call.getArgOperand(1)),
@@ -6326,7 +6327,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
}
case Intrinsic::localrecover: {
Value *FnArg = Call.getArgOperand(0)->stripPointerCasts();
- Function *Fn = dyn_cast<Function>(FnArg);
+ auto *Fn = dyn_cast<Function>(FnArg);
Check(Fn && !Fn->isDeclaration(),
"llvm.localrecover first "
"argument must be function defined in this module",
@@ -6378,8 +6379,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
// Check that this relocate is correctly tied to the statepoint
// This is case for relocate on the unwinding path of an invoke statepoint
- if (LandingPadInst *LandingPad =
- dyn_cast<LandingPadInst>(Call.getArgOperand(0))) {
+ if (auto *LandingPad = dyn_cast<LandingPadInst>(Call.getArgOperand(0))) {
const BasicBlock *InvokeBB =
LandingPad->getParent()->getUniquePredecessor();
@@ -6485,7 +6485,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
break;
}
case Intrinsic::experimental_get_vector_length: {
- ConstantInt *VF = cast<ConstantInt>(Call.getArgOperand(1));
+ auto *VF = cast<ConstantInt>(Call.getArgOperand(1));
Check(!VF->isNegative() && !VF->isZero(),
"get_vector_length: VF must be positive", Call);
break;
@@ -6580,7 +6580,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
break;
}
case Intrinsic::invariant_start: {
- ConstantInt *InvariantSize = dyn_cast<ConstantInt>(Call.getArgOperand(0));
+ auto *InvariantSize = dyn_cast<ConstantInt>(Call.getArgOperand(0));
Check(InvariantSize &&
(!InvariantSize->isNegative() || InvariantSize->isMinusOne()),
"invariant_start parameter must be -1, 0 or a positive number",
@@ -6678,7 +6678,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
break;
}
case Intrinsic::stepvector: {
- VectorType *VecTy = dyn_cast<VectorType>(Call.getType());
+ auto *VecTy = dyn_cast<VectorType>(Call.getType());
Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
VecTy->getScalarSizeInBits() >= 8,
"stepvector only supported for vectors of integers "
@@ -6691,9 +6691,9 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
Value *Op2 = Call.getArgOperand(1);
Value *Mask = Call.getArgOperand(2);
- VectorType *Op1Ty = dyn_cast<VectorType>(Op1->getType());
- VectorType *Op2Ty = dyn_cast<VectorType>(Op2->getType());
- VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
+ auto *Op1Ty = dyn_cast<VectorType>(Op1->getType());
+ auto *Op2Ty = dyn_cast<VectorType>(Op2->getType());
+ auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
Check(Op1Ty && Op2Ty && MaskTy, "Operands must be vectors.", &Call);
Check(isa<FixedVectorType>(Op2Ty),
@@ -6867,18 +6867,18 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
Type *T = Call.getParamAttr(0, Attribute::ElementType).getValueAsType();
for (unsigned I = 1; I < Call.arg_size(); ++I) {
Value *Index = Call.getOperand(I);
- ConstantInt *CI = dyn_cast<ConstantInt>(Index);
+ auto *CI = dyn_cast<ConstantInt>(Index);
Check(Index->getType()->isIntegerTy(),
"Index operand type must be an integer", &Call);
- if (ArrayType *AT = dyn_cast<ArrayType>(T)) {
+ if (auto *AT = dyn_cast<ArrayType>(T)) {
T = AT->getElementType();
- } else if (StructType *ST = dyn_cast<StructType>(T)) {
+ } else if (auto *ST = dyn_cast<StructType>(T)) {
Check(CI, "Indexing into a struct requires a constant int", &Call);
Check(CI->getZExtValue() < ST->getNumElements(),
"Indexing in a struct should be inbounds", &Call);
T = ST->getElementType(CI->getZExtValue());
- } else if (VectorType *VT = dyn_cast<VectorType>(T)) {
+ } else if (auto *VT = dyn_cast<VectorType>(T)) {
T = VT->getElementType();
} else {
CheckFailed("Reached a non-composite type with more indices to process",
@@ -6947,7 +6947,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end: {
Value *Ptr = Call.getArgOperand(0);
- IntrinsicInst *II = dyn_cast<IntrinsicInst>(Ptr);
+ auto *II = dyn_cast<IntrinsicInst>(Ptr);
Check(isa<AllocaInst>(Ptr) || isa<PoisonValue>(Ptr) ||
(II && II->getIntrinsicID() == Intrinsic::structured_alloca),
"llvm.lifetime.start/end can only be used on alloca or poison",
@@ -7899,8 +7899,8 @@ bool TBAAVerifier::visitTBAAMetadata(const Instruction *I, const MDNode *MD) {
"Old-style TBAA is no longer allowed, use struct-path TBAA instead",
I);
- MDNode *BaseNode = dyn_cast_or_null<MDNode>(MD->getOperand(0));
- MDNode *AccessType = dyn_cast_or_null<MDNode>(MD->getOperand(1));
+ auto *BaseNode = dyn_cast_or_null<MDNode>(MD->getOperand(0));
+ auto *AccessType = dyn_cast_or_null<MDNode>(MD->getOperand(1));
bool IsNewFormat = isNewFormatTBAATypeNode(AccessType);
More information about the llvm-commits
mailing list