@@ -531,6 +531,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
531531 void visitCallStackMetadata (MDNode *MD);
532532 void visitMemProfMetadata (Instruction &I, MDNode *MD);
533533 void visitCallsiteMetadata (Instruction &I, MDNode *MD);
534+ void visitCalleeTypeMetadata (Instruction &I, MDNode *MD);
534535 void visitDIAssignIDMetadata (Instruction &I, MDNode *MD);
535536 void visitMMRAMetadata (Instruction &I, MDNode *MD);
536537 void visitAnnotationMetadata (MDNode *Annotation);
@@ -5203,6 +5204,33 @@ void Verifier::visitCallsiteMetadata(Instruction &I, MDNode *MD) {
52035204 visitCallStackMetadata (MD);
52045205}
52055206
5207+ static inline bool isConstantIntMetadataOperand (const Metadata *MD) {
5208+ if (auto *VAL = dyn_cast<ValueAsMetadata>(MD))
5209+ return isa<ConstantInt>(VAL->getValue ());
5210+ return false ;
5211+ }
5212+
5213+ void Verifier::visitCalleeTypeMetadata (Instruction &I, MDNode *MD) {
5214+ Check (isa<CallBase>(I), " !callee_type metadata should only exist on calls" ,
5215+ &I);
5216+ for (Metadata *Op : MD->operands ()) {
5217+ Check (isa<MDNode>(Op),
5218+ " The callee_type metadata must be a list of type metadata nodes" , Op);
5219+ auto *TypeMD = cast<MDNode>(Op);
5220+ Check (TypeMD->getNumOperands () == 2 ,
5221+ " Well-formed generalized type metadata must contain exactly two "
5222+ " operands" ,
5223+ Op);
5224+ Check (isConstantIntMetadataOperand (TypeMD->getOperand (0 )) &&
5225+ mdconst::extract<ConstantInt>(TypeMD->getOperand (0 ))->isZero (),
5226+ " The first operand of type metadata for functions must be zero" , Op);
5227+ Check (TypeMD->hasGeneralizedMDString (),
5228+ " Only generalized type metadata can be part of the callee_type "
5229+ " metadata list" ,
5230+ Op);
5231+ }
5232+ }
5233+
52065234void Verifier::visitAnnotationMetadata (MDNode *Annotation) {
52075235 Check (isa<MDTuple>(Annotation), " annotation must be a tuple" );
52085236 Check (Annotation->getNumOperands () >= 1 ,
@@ -5480,6 +5508,9 @@ void Verifier::visitInstruction(Instruction &I) {
54805508 if (MDNode *MD = I.getMetadata (LLVMContext::MD_callsite))
54815509 visitCallsiteMetadata (I, MD);
54825510
5511+ if (MDNode *MD = I.getMetadata (LLVMContext::MD_callee_type))
5512+ visitCalleeTypeMetadata (I, MD);
5513+
54835514 if (MDNode *MD = I.getMetadata (LLVMContext::MD_DIAssignID))
54845515 visitDIAssignIDMetadata (I, MD);
54855516
0 commit comments