@@ -491,6 +491,14 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
491491 // / Whether a metadata node is allowed to be, or contain, a DILocation.
492492 enum class AreDebugLocsAllowed { No, Yes };
493493
494+ // / Metadata that should be treated as a range, with slightly different
495+ // / requirements.
496+ enum class RangeLikeMetadataKind {
497+ Range, // MD_range
498+ AbsoluteSymbol, // MD_absolute_symbol
499+ NoaliasAddrspace // MD_noalias_addrspace
500+ };
501+
494502 // Verification methods...
495503 void visitGlobalValue (const GlobalValue &GV);
496504 void visitGlobalVariable (const GlobalVariable &GV);
@@ -514,8 +522,8 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
514522 void visitModuleFlagCGProfileEntry (const MDOperand &MDO);
515523 void visitFunction (const Function &F);
516524 void visitBasicBlock (BasicBlock &BB);
517- void verifyRangeMetadata (const Value &V, const MDNode *Range, Type *Ty,
518- bool IsAbsoluteSymbol, bool IsAddrSpaceRange );
525+ void verifyRangeLikeMetadata (const Value &V, const MDNode *Range, Type *Ty,
526+ RangeLikeMetadataKind Kind );
519527 void visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty);
520528 void visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range, Type *Ty);
521529 void visitDereferenceableMetadata (Instruction &I, MDNode *MD);
@@ -760,8 +768,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
760768 // FIXME: Why is getMetadata on GlobalValue protected?
761769 if (const MDNode *AbsoluteSymbol =
762770 GO->getMetadata (LLVMContext::MD_absolute_symbol)) {
763- verifyRangeMetadata (*GO, AbsoluteSymbol, DL.getIntPtrType (GO->getType ()),
764- true , false );
771+ verifyRangeLikeMetadata (*GO, AbsoluteSymbol,
772+ DL.getIntPtrType (GO->getType ()),
773+ RangeLikeMetadataKind::AbsoluteSymbol);
765774 }
766775 }
767776
@@ -4130,9 +4139,8 @@ static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
41304139
41314140// / Verify !range and !absolute_symbol metadata. These have the same
41324141// / restrictions, except !absolute_symbol allows the full set.
4133- void Verifier::verifyRangeMetadata (const Value &I, const MDNode *Range,
4134- Type *Ty, bool IsAbsoluteSymbol,
4135- bool IsAddrSpaceRange) {
4142+ void Verifier::verifyRangeLikeMetadata (const Value &I, const MDNode *Range,
4143+ Type *Ty, RangeLikeMetadataKind Kind) {
41364144 unsigned NumOperands = Range->getNumOperands ();
41374145 Check (NumOperands % 2 == 0 , " Unfinished range!" , Range);
41384146 unsigned NumRanges = NumOperands / 2 ;
@@ -4150,7 +4158,7 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41504158 Check (High->getType () == Low->getType (), " Range pair types must match!" ,
41514159 &I);
41524160
4153- if (IsAddrSpaceRange ) {
4161+ if (Kind == RangeLikeMetadataKind::NoaliasAddrspace ) {
41544162 Check (High->getType ()->isIntegerTy (32 ),
41554163 " noalias.addrspace type must be i32!" , &I);
41564164 } else {
@@ -4167,7 +4175,9 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41674175 " The upper and lower limits cannot be the same value" , &I);
41684176
41694177 ConstantRange CurRange (LowV, HighV);
4170- Check (!CurRange.isEmptySet () && (IsAbsoluteSymbol || !CurRange.isFullSet ()),
4178+ Check (!CurRange.isEmptySet () &&
4179+ (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4180+ !CurRange.isFullSet ()),
41714181 " Range must not be empty!" , Range);
41724182 if (i != 0 ) {
41734183 Check (CurRange.intersectWith (LastRange).isEmptySet (),
@@ -4195,14 +4205,15 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41954205void Verifier::visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty) {
41964206 assert (Range && Range == I.getMetadata (LLVMContext::MD_range) &&
41974207 " precondition violation" );
4198- verifyRangeMetadata (I, Range, Ty, false , false );
4208+ verifyRangeLikeMetadata (I, Range, Ty, RangeLikeMetadataKind::Range );
41994209}
42004210
42014211void Verifier::visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range,
42024212 Type *Ty) {
42034213 assert (Range && Range == I.getMetadata (LLVMContext::MD_noalias_addrspace) &&
42044214 " precondition violation" );
4205- verifyRangeMetadata (I, Range, Ty, false , true );
4215+ verifyRangeLikeMetadata (I, Range, Ty,
4216+ RangeLikeMetadataKind::NoaliasAddrspace);
42064217}
42074218
42084219void Verifier::checkAtomicMemAccessSize (Type *Ty, const Instruction *I) {
0 commit comments