@@ -492,6 +492,14 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
492
492
// / Whether a metadata node is allowed to be, or contain, a DILocation.
493
493
enum class AreDebugLocsAllowed { No, Yes };
494
494
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
+
495
503
// Verification methods...
496
504
void visitGlobalValue (const GlobalValue &GV);
497
505
void visitGlobalVariable (const GlobalVariable &GV);
@@ -515,9 +523,10 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
515
523
void visitModuleFlagCGProfileEntry (const MDOperand &MDO);
516
524
void visitFunction (const Function &F);
517
525
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 );
520
528
void visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty);
529
+ void visitNoaliasAddrspaceMetadata (Instruction &I, MDNode *Range, Type *Ty);
521
530
void visitDereferenceableMetadata (Instruction &I, MDNode *MD);
522
531
void visitProfMetadata (Instruction &I, MDNode *MD);
523
532
void visitCallStackMetadata (MDNode *MD);
@@ -760,8 +769,9 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
760
769
// FIXME: Why is getMetadata on GlobalValue protected?
761
770
if (const MDNode *AbsoluteSymbol =
762
771
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);
765
775
}
766
776
}
767
777
@@ -4136,8 +4146,8 @@ static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
4136
4146
4137
4147
// / Verify !range and !absolute_symbol metadata. These have the same
4138
4148
// / 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 ) {
4141
4151
unsigned NumOperands = Range->getNumOperands ();
4142
4152
Check (NumOperands % 2 == 0 , " Unfinished range!" , Range);
4143
4153
unsigned NumRanges = NumOperands / 2 ;
@@ -4154,8 +4164,14 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
4154
4164
4155
4165
Check (High->getType () == Low->getType (), " Range pair types must match!" ,
4156
4166
&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
+ }
4159
4175
4160
4176
APInt HighV = High->getValue ();
4161
4177
APInt LowV = Low->getValue ();
@@ -4166,7 +4182,9 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
4166
4182
" The upper and lower limits cannot be the same value" , &I);
4167
4183
4168
4184
ConstantRange CurRange (LowV, HighV);
4169
- Check (!CurRange.isEmptySet () && (IsAbsoluteSymbol || !CurRange.isFullSet ()),
4185
+ Check (!CurRange.isEmptySet () &&
4186
+ (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4187
+ !CurRange.isFullSet ()),
4170
4188
" Range must not be empty!" , Range);
4171
4189
if (i != 0 ) {
4172
4190
Check (CurRange.intersectWith (LastRange).isEmptySet (),
@@ -4194,7 +4212,15 @@ void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range,
4194
4212
void Verifier::visitRangeMetadata (Instruction &I, MDNode *Range, Type *Ty) {
4195
4213
assert (Range && Range == I.getMetadata (LLVMContext::MD_range) &&
4196
4214
" 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);
4198
4224
}
4199
4225
4200
4226
void Verifier::checkAtomicMemAccessSize (Type *Ty, const Instruction *I) {
@@ -5187,6 +5213,13 @@ void Verifier::visitInstruction(Instruction &I) {
5187
5213
visitRangeMetadata (I, Range, I.getType ());
5188
5214
}
5189
5215
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
+
5190
5223
if (I.hasMetadata (LLVMContext::MD_invariant_group)) {
5191
5224
Check (isa<LoadInst>(I) || isa<StoreInst>(I),
5192
5225
" invariant.group metadata is only for loads and stores" , &I);
0 commit comments