@@ -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,9 +523,10 @@ 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 );
526+ void verifyRangeLikeMetadata (const Value &V, const MDNode *Range, Type *Ty,
527+ RangeLikeMetadataKind Kind );
520528 void visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty);
529+ void visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range, Type *Ty);
521530 void visitDereferenceableMetadata (Instruction &I, MDNode *MD);
522531 void visitProfMetadata (Instruction &I, MDNode *MD);
523532 void visitCallStackMetadata (MDNode *MD);
@@ -760,8 +769,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
760769 // FIXME: Why is getMetadata on GlobalValue protected?
761770 if (const MDNode *AbsoluteSymbol =
762771 GO->getMetadata (LLVMContext::MD_absolute_symbol)) {
763- verifyRangeMetadata (*GO, AbsoluteSymbol, DL.getIntPtrType (GO->getType ()),
764- true );
772+ verifyRangeLikeMetadata (*GO, AbsoluteSymbol,
773+ DL.getIntPtrType (GO->getType ()),
774+ RangeLikeMetadataKind::AbsoluteSymbol);
765775 }
766776 }
767777
@@ -4136,8 +4146,8 @@ static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
41364146
41374147// / Verify !range and !absolute_symbol metadata. These have the same
41384148// / restrictions, except !absolute_symbol allows the full set.
4139- void Verifier::verifyRangeMetadata (const Value &I, const MDNode *Range,
4140- Type *Ty, bool IsAbsoluteSymbol ) {
4149+ void Verifier::verifyRangeLikeMetadata (const Value &I, const MDNode *Range,
4150+ Type *Ty, RangeLikeMetadataKind Kind ) {
41414151 unsigned NumOperands = Range->getNumOperands ();
41424152 Check (NumOperands % 2 == 0 , " Unfinished range!" , Range);
41434153 unsigned NumRanges = NumOperands / 2 ;
@@ -4154,8 +4164,14 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41544164
41554165 Check (High->getType () == Low->getType (), " Range pair types must match!" ,
41564166 &I);
4157- Check (High->getType () == Ty->getScalarType (),
4158- " Range types must match instruction type!" , &I);
4167+
4168+ if (Kind == RangeLikeMetadataKind::NoaliasAddrspace) {
4169+ Check (High->getType ()->isIntegerTy (32 ),
4170+ " noalias.addrspace type must be i32!" , &I);
4171+ } else {
4172+ Check (High->getType () == Ty->getScalarType (),
4173+ " Range types must match instruction type!" , &I);
4174+ }
41594175
41604176 APInt HighV = High->getValue ();
41614177 APInt LowV = Low->getValue ();
@@ -4166,7 +4182,9 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41664182 " The upper and lower limits cannot be the same value" , &I);
41674183
41684184 ConstantRange CurRange (LowV, HighV);
4169- Check (!CurRange.isEmptySet () && (IsAbsoluteSymbol || !CurRange.isFullSet ()),
4185+ Check (!CurRange.isEmptySet () &&
4186+ (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4187+ !CurRange.isFullSet ()),
41704188 " Range must not be empty!" , Range);
41714189 if (i != 0 ) {
41724190 Check (CurRange.intersectWith (LastRange).isEmptySet (),
@@ -4194,7 +4212,15 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
41944212void Verifier::visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty) {
41954213 assert (Range && Range == I.getMetadata (LLVMContext::MD_range) &&
41964214 " precondition violation" );
4197- verifyRangeMetadata (I, Range, Ty, false );
4215+ verifyRangeLikeMetadata (I, Range, Ty, RangeLikeMetadataKind::Range);
4216+ }
4217+
4218+ void Verifier::visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range,
4219+ Type *Ty) {
4220+ assert (Range && Range == I.getMetadata (LLVMContext::MD_noalias_addrspace) &&
4221+ " precondition violation" );
4222+ verifyRangeLikeMetadata (I, Range, Ty,
4223+ RangeLikeMetadataKind::NoaliasAddrspace);
41984224}
41994225
42004226void Verifier::checkAtomicMemAccessSize (Type *Ty, const Instruction *I) {
@@ -5187,6 +5213,13 @@ void Verifier::visitInstruction(Instruction &I) {
51875213 visitRangeMetadata (I, Range, I.getType ());
51885214 }
51895215
5216+ if (MDNode *Range = I.getMetadata (LLVMContext::MD_noalias_addrspace)) {
5217+ Check (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<AtomicRMWInst>(I) ||
5218+ isa<AtomicCmpXchgInst>(I) || isa<CallInst>(I),
5219+ " noalias.addrspace are only for memory operations!" , &I);
5220+ visitNoaliasAddrspaceMetadata (I, Range, I.getType ());
5221+ }
5222+
51905223 if (I.hasMetadata (LLVMContext::MD_invariant_group)) {
51915224 Check (isa<LoadInst>(I) || isa<StoreInst>(I),
51925225 " invariant.group metadata is only for loads and stores" , &I);
0 commit comments