@@ -492,6 +492,14 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
492492 // / Whether a metadata node is allowed to be, or contain, a DILocation.
493493 enum class AreDebugLocsAllowed { No, Yes };
494494
495+ // / Metadata that should be treated as a range, with slightly different
496+ // / requirements.
497+ enum class RangeLikeMetadataKind {
498+ Range, // MD_range
499+ AbsoluteSymbol, // MD_absolute_symbol
500+ NoaliasAddrspace // MD_noalias_addrspace
501+ };
502+
495503 // Verification methods...
496504 void visitGlobalValue (const GlobalValue &GV);
497505 void visitGlobalVariable (const GlobalVariable &GV);
@@ -515,8 +523,8 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
515523 void visitModuleFlagCGProfileEntry (const MDOperand &MDO);
516524 void visitFunction (const Function &F);
517525 void visitBasicBlock (BasicBlock &BB);
518- void verifyRangeMetadata (const Value &V, const MDNode *Range, Type *Ty,
519- bool IsAbsoluteSymbol, bool IsAddrSpaceRange );
526+ void verifyRangeLikeMetadata (const Value &V, const MDNode *Range, Type *Ty,
527+ RangeLikeMetadataKind Kind );
520528 void visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty);
521529 void visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range, Type *Ty);
522530 void visitDereferenceableMetadata (Instruction &I, MDNode *MD);
@@ -761,8 +769,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
761769 // FIXME: Why is getMetadata on GlobalValue protected?
762770 if (const MDNode *AbsoluteSymbol =
763771 GO->getMetadata (LLVMContext::MD_absolute_symbol)) {
764- verifyRangeMetadata (*GO, AbsoluteSymbol, DL.getIntPtrType (GO->getType ()),
765- true , false );
772+ verifyRangeLikeMetadata (*GO, AbsoluteSymbol,
773+ DL.getIntPtrType (GO->getType ()),
774+ RangeLikeMetadataKind::AbsoluteSymbol);
766775 }
767776 }
768777
@@ -4131,9 +4140,8 @@ static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
41314140
41324141// / Verify !range and !absolute_symbol metadata. These have the same
41334142// / restrictions, except !absolute_symbol allows the full set.
4134- void Verifier::verifyRangeMetadata (const Value &I, const MDNode *Range,
4135- Type *Ty, bool IsAbsoluteSymbol,
4136- bool IsAddrSpaceRange) {
4143+ void Verifier::verifyRangeLikeMetadata (const Value &I, const MDNode *Range,
4144+ Type *Ty, RangeLikeMetadataKind Kind) {
41374145 unsigned NumOperands = Range->getNumOperands ();
41384146 Check (NumOperands % 2 == 0 , " Unfinished range!" , Range);
41394147 unsigned NumRanges = NumOperands / 2 ;
@@ -4151,7 +4159,7 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41514159 Check (High->getType () == Low->getType (), " Range pair types must match!" ,
41524160 &I);
41534161
4154- if (IsAddrSpaceRange ) {
4162+ if (Kind == RangeLikeMetadataKind::NoaliasAddrspace ) {
41554163 Check (High->getType ()->isIntegerTy (32 ),
41564164 " noalias.addrspace type must be i32!" , &I);
41574165 } else {
@@ -4168,7 +4176,9 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41684176 " The upper and lower limits cannot be the same value" , &I);
41694177
41704178 ConstantRange CurRange (LowV, HighV);
4171- Check (!CurRange.isEmptySet () && (IsAbsoluteSymbol || !CurRange.isFullSet ()),
4179+ Check (!CurRange.isEmptySet () &&
4180+ (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4181+ !CurRange.isFullSet ()),
41724182 " Range must not be empty!" , Range);
41734183 if (i != 0 ) {
41744184 Check (CurRange.intersectWith (LastRange).isEmptySet (),
@@ -4196,14 +4206,15 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41964206void Verifier::visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty) {
41974207 assert (Range && Range == I.getMetadata (LLVMContext::MD_range) &&
41984208 " precondition violation" );
4199- verifyRangeMetadata (I, Range, Ty, false , false );
4209+ verifyRangeLikeMetadata (I, Range, Ty, RangeLikeMetadataKind::Range );
42004210}
42014211
42024212void Verifier::visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range,
42034213 Type *Ty) {
42044214 assert (Range && Range == I.getMetadata (LLVMContext::MD_noalias_addrspace) &&
42054215 " precondition violation" );
4206- verifyRangeMetadata (I, Range, Ty, false , true );
4216+ verifyRangeLikeMetadata (I, Range, Ty,
4217+ RangeLikeMetadataKind::NoaliasAddrspace);
42074218}
42084219
42094220void Verifier::checkAtomicMemAccessSize (Type *Ty, const Instruction *I) {
0 commit comments