@@ -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
@@ -4137,9 +4146,8 @@ static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
41374146
41384147// / Verify !range and !absolute_symbol metadata. These have the same
41394148// / restrictions, except !absolute_symbol allows the full set.
4140- void Verifier::verifyRangeMetadata (const Value &I, const MDNode *Range,
4141- Type *Ty, bool IsAbsoluteSymbol,
4142- bool IsAddrSpaceRange) {
4149+ void Verifier::verifyRangeLikeMetadata (const Value &I, const MDNode *Range,
4150+ Type *Ty, RangeLikeMetadataKind Kind) {
41434151 unsigned NumOperands = Range->getNumOperands ();
41444152 Check (NumOperands % 2 == 0 , " Unfinished range!" , Range);
41454153 unsigned NumRanges = NumOperands / 2 ;
@@ -4157,7 +4165,7 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41574165 Check (High->getType () == Low->getType (), " Range pair types must match!" ,
41584166 &I);
41594167
4160- if (IsAddrSpaceRange ) {
4168+ if (Kind == RangeLikeMetadataKind::NoaliasAddrspace ) {
41614169 Check (High->getType ()->isIntegerTy (32 ),
41624170 " noalias.addrspace type must be i32!" , &I);
41634171 } else {
@@ -4174,7 +4182,9 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41744182 " The upper and lower limits cannot be the same value" , &I);
41754183
41764184 ConstantRange CurRange (LowV, HighV);
4177- Check (!CurRange.isEmptySet () && (IsAbsoluteSymbol || !CurRange.isFullSet ()),
4185+ Check (!CurRange.isEmptySet () &&
4186+ (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4187+ !CurRange.isFullSet ()),
41784188 " Range must not be empty!" , Range);
41794189 if (i != 0 ) {
41804190 Check (CurRange.intersectWith (LastRange).isEmptySet (),
@@ -4202,14 +4212,15 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
42024212void Verifier::visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty) {
42034213 assert (Range && Range == I.getMetadata (LLVMContext::MD_range) &&
42044214 " precondition violation" );
4205- verifyRangeMetadata (I, Range, Ty, false , false );
4215+ verifyRangeLikeMetadata (I, Range, Ty, RangeLikeMetadataKind::Range );
42064216}
42074217
42084218void Verifier::visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range,
42094219 Type *Ty) {
42104220 assert (Range && Range == I.getMetadata (LLVMContext::MD_noalias_addrspace) &&
42114221 " precondition violation" );
4212- verifyRangeMetadata (I, Range, Ty, false , true );
4222+ verifyRangeLikeMetadata (I, Range, Ty,
4223+ RangeLikeMetadataKind::NoaliasAddrspace);
42134224}
42144225
42154226void Verifier::checkAtomicMemAccessSize (Type *Ty, const Instruction *I) {
0 commit comments