97#include "llvm/IR/IntrinsicsAArch64.h"
98#include "llvm/IR/IntrinsicsAMDGPU.h"
99#include "llvm/IR/IntrinsicsARM.h"
100#include "llvm/IR/IntrinsicsNVPTX.h"
101#include "llvm/IR/IntrinsicsWebAssembly.h"
143 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
144 "scopes are not dominating"));
167 *
OS <<
"; ModuleID = '" << M->getModuleIdentifier() <<
"'\n";
180 V.printAsOperand(*
OS,
true,
MST);
185 void Write(
const DbgRecord *DR) {
201 *
OS <<
"declare_value";
222 template <
class T>
void Write(
const MDTupleTypedArrayWrapper<T> &MD) {
226 void Write(
const NamedMDNode *NMD) {
239 void Write(
const Comdat *
C) {
245 void Write(
const APInt *AI) {
251 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
257 *
OS <<
A->getAsString() <<
'\n';
261 void Write(
const AttributeSet *AS) {
268 void Write(
const AttributeList *AL) {
274 void Write(Printable
P) { *
OS <<
P <<
'\n'; }
276 template <
typename T>
void Write(ArrayRef<T> Vs) {
277 for (
const T &V : Vs)
281 template <
typename T1,
typename... Ts>
282 void WriteTs(
const T1 &
V1,
const Ts &... Vs) {
287 template <
typename... Ts>
void WriteTs() {}
296 *
OS << Message <<
'\n';
304 template <
typename T1,
typename... Ts>
314 *
OS << Message <<
'\n';
320 template <
typename T1,
typename... Ts>
352 Type *LandingPadResultTy;
359 bool HasDebugInfo =
false;
402 SawFrameEscape(
false), TBAAVerifyHelper(this) {
403 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
406 bool hasBrokenDebugInfo()
const {
return BrokenDebugInfo; }
408 bool verify(
const Function &
F) {
409 llvm::TimeTraceScope timeScope(
"Verifier");
411 "An instance of this class only works with a specific module!");
421 for (
const BasicBlock &BB :
F) {
422 if (!BB.empty() && BB.back().isTerminator())
426 *OS <<
"Basic Block in function '" <<
F.getName()
427 <<
"' does not have terminator!\n";
428 BB.printAsOperand(*OS,
true, MST);
436 DT.recalculate(
const_cast<Function &
>(
F));
438 auto FailureCB = [
this](
const Twine &Message) {
439 this->CheckFailed(Message);
441 ConvergenceVerifyHelper.initialize(OS, FailureCB,
F);
446 verifySiblingFuncletUnwinds();
448 if (ConvergenceVerifyHelper.sawTokens())
449 ConvergenceVerifyHelper.verify(DT);
451 InstsInThisBlock.clear();
453 LandingPadResultTy =
nullptr;
454 SawFrameEscape =
false;
455 SiblingFuncletInfo.clear();
456 verifyNoAliasScopeDecl();
457 NoAliasScopeDecls.clear();
467 for (
const Function &
F : M)
468 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
469 DeoptimizeDeclarations.push_back(&
F);
473 verifyFrameRecoverIndices();
474 for (
const GlobalVariable &GV :
M.globals())
475 visitGlobalVariable(GV);
477 for (
const GlobalAlias &GA :
M.aliases())
478 visitGlobalAlias(GA);
480 for (
const GlobalIFunc &GI :
M.ifuncs())
481 visitGlobalIFunc(GI);
483 for (
const NamedMDNode &NMD :
M.named_metadata())
484 visitNamedMDNode(NMD);
486 for (
const StringMapEntry<Comdat> &SMEC :
M.getComdatSymbolTable())
487 visitComdat(SMEC.getValue());
491 visitModuleCommandLines();
492 visitModuleErrnoTBAA();
494 verifyCompileUnits();
496 verifyDeoptimizeCallingConvs();
497 DISubprogramAttachments.clear();
503 enum class AreDebugLocsAllowed {
No,
Yes };
507 enum class RangeLikeMetadataKind {
514 void visitGlobalValue(
const GlobalValue &GV);
515 void visitGlobalVariable(
const GlobalVariable &GV);
516 void visitGlobalAlias(
const GlobalAlias &GA);
517 void visitGlobalIFunc(
const GlobalIFunc &GI);
518 void visitAliaseeSubExpr(
const GlobalAlias &
A,
const Constant &
C);
519 void visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias *> &Visited,
520 const GlobalAlias &
A,
const Constant &
C);
521 void visitNamedMDNode(
const NamedMDNode &NMD);
522 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
523 void visitMetadataAsValue(
const MetadataAsValue &MD, Function *
F);
524 void visitValueAsMetadata(
const ValueAsMetadata &MD, Function *
F);
525 void visitDIArgList(
const DIArgList &AL, Function *
F);
526 void visitComdat(
const Comdat &
C);
527 void visitModuleIdents();
528 void visitModuleCommandLines();
529 void visitModuleErrnoTBAA();
530 void visitModuleFlags();
531 void visitModuleFlag(
const MDNode *
Op,
532 DenseMap<const MDString *, const MDNode *> &SeenIDs,
533 SmallVectorImpl<const MDNode *> &Requirements);
534 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
535 void visitFunction(
const Function &
F);
536 void visitBasicBlock(BasicBlock &BB);
537 void verifyRangeLikeMetadata(
const Value &V,
const MDNode *
Range,
Type *Ty,
538 RangeLikeMetadataKind Kind);
539 void visitRangeMetadata(Instruction &
I, MDNode *
Range,
Type *Ty);
540 void visitNoFPClassMetadata(Instruction &
I, MDNode *
Range,
Type *Ty);
541 void visitNoaliasAddrspaceMetadata(Instruction &
I, MDNode *
Range,
Type *Ty);
542 void visitDereferenceableMetadata(Instruction &
I, MDNode *MD);
543 void visitNofreeMetadata(Instruction &
I, MDNode *MD);
544 void visitProfMetadata(Instruction &
I, MDNode *MD);
545 void visitCallStackMetadata(MDNode *MD);
546 void visitMemProfMetadata(Instruction &
I, MDNode *MD);
547 void visitCallsiteMetadata(Instruction &
I, MDNode *MD);
548 void visitCalleeTypeMetadata(Instruction &
I, MDNode *MD);
549 void visitDIAssignIDMetadata(Instruction &
I, MDNode *MD);
550 void visitMMRAMetadata(Instruction &
I, MDNode *MD);
551 void visitAnnotationMetadata(MDNode *Annotation);
552 void visitAliasScopeMetadata(
const MDNode *MD);
553 void visitAliasScopeListMetadata(
const MDNode *MD);
554 void visitAccessGroupMetadata(
const MDNode *MD);
555 void visitCapturesMetadata(Instruction &
I,
const MDNode *Captures);
556 void visitAllocTokenMetadata(Instruction &
I, MDNode *MD);
557 void visitInlineHistoryMetadata(Instruction &
I, MDNode *MD);
558 void visitMemCacheHintMetadata(Instruction &
I, MDNode *MD);
560#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
561#include "llvm/IR/Metadata.def"
562 void visitDIType(
const DIType &
N);
563 void visitDIScope(
const DIScope &
N);
587 void checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V);
592 void visitPHINode(
PHINode &PN);
601 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
602 void visitCallInst(CallInst &CI);
603 void visitInvokeInst(InvokeInst &
II);
604 void visitGetElementPtrInst(GetElementPtrInst &
GEP);
605 void visitLoadInst(LoadInst &LI);
606 void visitStoreInst(StoreInst &SI);
607 void verifyDominatesUse(Instruction &
I,
unsigned i);
608 void visitInstruction(Instruction &
I);
609 void visitTerminator(Instruction &
I);
610 void visitCondBrInst(CondBrInst &BI);
611 void visitReturnInst(ReturnInst &RI);
612 void visitSwitchInst(SwitchInst &SI);
613 void visitIndirectBrInst(IndirectBrInst &BI);
614 void visitCallBrInst(CallBrInst &CBI);
615 void visitSelectInst(SelectInst &SI);
616 void visitUserOp1(Instruction &
I);
617 void visitUserOp2(Instruction &
I) { visitUserOp1(
I); }
619 void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI);
620 void visitVPIntrinsic(VPIntrinsic &VPI);
621 void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI);
622 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
623 void visitAtomicRMWInst(AtomicRMWInst &RMWI);
624 void visitFenceInst(FenceInst &FI);
625 void visitAllocaInst(AllocaInst &AI);
626 void visitExtractValueInst(ExtractValueInst &EVI);
627 void visitInsertValueInst(InsertValueInst &IVI);
628 void visitEHPadPredecessors(Instruction &
I);
629 void visitLandingPadInst(LandingPadInst &LPI);
630 void visitResumeInst(ResumeInst &RI);
631 void visitCatchPadInst(CatchPadInst &CPI);
632 void visitCatchReturnInst(CatchReturnInst &CatchReturn);
633 void visitCleanupPadInst(CleanupPadInst &CPI);
634 void visitFuncletPadInst(FuncletPadInst &FPI);
635 void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
636 void visitCleanupReturnInst(CleanupReturnInst &CRI);
638 void verifySwiftErrorCall(CallBase &
Call,
const Value *SwiftErrorVal);
639 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
640 void verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs, StringRef
Context);
641 void verifyMustTailCall(CallInst &CI);
642 bool verifyAttributeCount(AttributeList Attrs,
unsigned Params);
643 void verifyAttributeTypes(AttributeSet Attrs,
const Value *V);
644 void verifyParameterAttrs(AttributeSet Attrs,
Type *Ty,
const Value *V);
645 void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr,
647 void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
648 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
649 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
650 void verifyAMDGPUReqdWorkGroupSize(
const Function &
F);
651 void verifyUnknownProfileMetadata(MDNode *MD);
652 void visitConstantExprsRecursively(
const Constant *EntryC);
653 void visitConstantExpr(
const ConstantExpr *CE);
654 void visitConstantPtrAuth(
const ConstantPtrAuth *CPA);
655 void verifyInlineAsmCall(
const CallBase &
Call);
656 void verifyStatepoint(
const CallBase &
Call);
657 void verifyFrameRecoverIndices();
658 void verifySiblingFuncletUnwinds();
660 void verifyFragmentExpression(
const DbgVariableRecord &
I);
661 template <
typename ValueOrMetadata>
662 void verifyFragmentExpression(
const DIVariable &V,
664 ValueOrMetadata *
Desc);
665 void verifyFnArgs(
const DbgVariableRecord &DVR);
666 void verifyNotEntryValue(
const DbgVariableRecord &
I);
669 void verifyCompileUnits();
673 void verifyDeoptimizeCallingConvs();
675 void verifyAttachedCallBundle(
const CallBase &
Call,
676 const OperandBundleUse &BU);
679 void verifyNoAliasScopeDecl();
685#define Check(C, ...) \
688 CheckFailed(__VA_ARGS__); \
695#define CheckDI(C, ...) \
698 DebugInfoCheckFailed(__VA_ARGS__); \
706 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
707 "Instruction has invalid DebugMarker", &
I);
709 "PHI Node must not have any attached DbgRecords", &
I);
712 "DbgRecord had invalid DebugMarker", &
I, &DR);
715 visitMDNode(*
Loc, AreDebugLocsAllowed::Yes);
720 verifyFragmentExpression(*DVR);
721 verifyNotEntryValue(*DVR);
728void Verifier::visit(Instruction &
I) {
730 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
731 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
743 while (!WorkList.
empty()) {
745 if (!Visited.
insert(Cur).second)
752void Verifier::visitGlobalValue(
const GlobalValue &GV) {
754 "Global is external, but doesn't have external or weak linkage!", &GV);
757 if (
const MDNode *Associated =
758 GO->getMetadata(LLVMContext::MD_associated)) {
759 Check(Associated->getNumOperands() == 1,
760 "associated metadata must have one operand", &GV, Associated);
761 const Metadata *
Op = Associated->getOperand(0).get();
762 Check(
Op,
"associated metadata must have a global value", GO, Associated);
765 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
768 "associated value must be pointer typed", GV, Associated);
770 const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases();
772 "associated metadata must point to a GlobalObject", GO, Stripped);
773 Check(Stripped != GO,
774 "global values should not associate to themselves", GO,
780 if (
const MDNode *AbsoluteSymbol =
781 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
782 verifyRangeLikeMetadata(*GO, AbsoluteSymbol,
783 DL.getIntPtrType(GO->getType()),
784 RangeLikeMetadataKind::AbsoluteSymbol);
787 if (GO->hasMetadata(LLVMContext::MD_implicit_ref)) {
788 Check(!GO->isDeclaration(),
789 "ref metadata must not be placed on a declaration", GO);
792 GO->getMetadata(LLVMContext::MD_implicit_ref, MDs);
793 for (
const MDNode *MD : MDs) {
794 Check(MD->getNumOperands() == 1,
"ref metadata must have one operand",
798 Check(VM,
"ref metadata must be ValueAsMetadata", GO, MD);
801 "ref value must be pointer typed", GV, MD);
805 "ref metadata must point to a GlobalObject", GO, Stripped);
806 Check(Stripped != GO,
"values should not reference themselves", GO,
812 if (
auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) {
813 Check(Props->getNumOperands() == 2,
814 "elf_section_properties metadata must have two operands", GO,
816 if (Props->getNumOperands() == 2) {
818 Check(
Type,
"type field must be ConstantAsMetadata", GO, Props);
820 Check(TypeInt,
"type field must be ConstantInt", GO, Props);
823 Check(Entsize,
"entsize field must be ConstantAsMetadata", GO, Props);
825 Check(EntsizeInt,
"entsize field must be ConstantInt", GO, Props);
831 "Only global variables can have appending linkage!", &GV);
836 "Only global arrays can have appending linkage!", GVar);
840 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
844 "dllexport GlobalValue must have default or protected visibility",
849 "dllimport GlobalValue must have default visibility", &GV);
850 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
856 "Global is marked as dllimport, but not external", &GV);
861 "GlobalValue with local linkage or non-default "
862 "visibility must be dso_local!",
867 if (!
I->getParent() || !
I->getParent()->getParent())
868 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
870 else if (
I->getParent()->getParent()->getParent() != &M)
871 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
872 I->getParent()->getParent(),
873 I->getParent()->getParent()->getParent());
876 if (
F->getParent() != &M)
877 CheckFailed(
"Global is used by function in a different module", &GV, &M,
885void Verifier::visitGlobalVariable(
const GlobalVariable &GV) {
889 Check(
A->value() <= Value::MaximumAlignment,
890 "huge alignment values are unsupported", &GV);
895 "Global variable initializer type does not match global "
899 "Global variable initializer must be sized", &GV);
905 "'common' global must have a zero initializer!", &GV);
908 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
913 GV.
getName() ==
"llvm.global_dtors")) {
915 "invalid linkage for intrinsic global variable", &GV);
917 "invalid uses of intrinsic global variable", &GV);
924 PointerType::get(
Context,
DL.getProgramAddressSpace());
928 "wrong type for intrinsic global variable", &GV);
930 "the third field of the element type is mandatory, "
931 "specify ptr null to migrate from the obsoleted 2-field form");
939 GV.
getName() ==
"llvm.compiler.used")) {
941 "invalid linkage for intrinsic global variable", &GV);
943 "invalid uses of intrinsic global variable", &GV);
947 Check(PTy,
"wrong type for intrinsic global variable", &GV);
951 Check(InitArray,
"wrong initializer for intrinsic global variable",
957 Twine(
"invalid ") + GV.
getName() +
" member", V);
959 Twine(
"members of ") + GV.
getName() +
" must be named", V);
968 for (
auto *MD : MDs) {
970 visitDIGlobalVariableExpression(*GVE);
972 CheckDI(
false,
"!dbg attachment of global variable must be a "
973 "DIGlobalVariableExpression");
983 "Global @" + GV.
getName() +
" has illegal target extension type",
992 "Global variable is too large to fit into the address space", &GV,
996 visitGlobalValue(GV);
1003 visitGlobalValue(GV);
1006void Verifier::visitAliaseeSubExpr(
const GlobalAlias &GA,
const Constant &
C) {
1007 SmallPtrSet<const GlobalAlias*, 4> Visited;
1009 visitAliaseeSubExpr(Visited, GA,
C);
1012void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl<const GlobalAlias*> &Visited,
1013 const GlobalAlias &GA,
const Constant &
C) {
1017 "available_externally alias must point to available_externally "
1028 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
1030 Check(!GA2->isInterposable(),
1031 "Alias cannot point to an interposable alias", &GA);
1040 visitConstantExprsRecursively(CE);
1042 for (
const Use &U :
C.operands()) {
1045 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
1047 visitAliaseeSubExpr(Visited, GA, *C2);
1051void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
1053 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
1054 "weak_odr, external, or available_externally linkage!",
1057 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
1059 "Alias and aliasee types should match!", &GA);
1062 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
1064 visitAliaseeSubExpr(GA, *Aliasee);
1066 visitGlobalValue(GA);
1069void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
1070 visitGlobalValue(GI);
1074 for (
const auto &
I : MDs) {
1075 CheckDI(
I.first != LLVMContext::MD_dbg,
1076 "an ifunc may not have a !dbg attachment", &GI);
1077 Check(
I.first != LLVMContext::MD_prof,
1078 "an ifunc may not have a !prof attachment", &GI);
1079 visitMDNode(*
I.second, AreDebugLocsAllowed::No);
1083 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
1084 "weak_odr, or external linkage!",
1089 Check(Resolver,
"IFunc must have a Function resolver", &GI);
1091 "IFunc resolver must be a definition", &GI);
1098 "IFunc resolver must return a pointer", &GI);
1101 "IFunc resolver has incorrect type", &GI);
1104void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1109 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1110 for (
const MDNode *MD : NMD.
operands()) {
1111 if (NMD.
getName() ==
"llvm.dbg.cu")
1117 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1121void Verifier::visitMDNode(
const MDNode &BaseMD,
1122 AreDebugLocsAllowed AllowLocs) {
1125 if (!MDNodes.
insert(&BaseMD).second)
1128 std::queue<const MDNode *> Worklist;
1129 Worklist.push(&BaseMD);
1131 while (!Worklist.empty()) {
1132 const MDNode *CurrentMD = Worklist.front();
1135 "MDNode context does not match Module context!", CurrentMD);
1140 case Metadata::MDTupleKind:
1142#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1143 case Metadata::CLASS##Kind: \
1144 visit##CLASS(cast<CLASS>(*CurrentMD)); \
1146#include "llvm/IR/Metadata.def"
1155 "DILocation not allowed within this metadata node", CurrentMD,
1163 visitValueAsMetadata(*V,
nullptr);
1177 "Expected second operand to be an integer constant of type i32 or "
1185 Check(CurrentMD->
isResolved(),
"All nodes should be resolved!", CurrentMD);
1189void Verifier::visitValueAsMetadata(
const ValueAsMetadata &MD, Function *
F) {
1192 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1198 Check(
F,
"function-local metadata used outside a function", L);
1204 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1210 assert(ActualF &&
"Unimplemented function local metadata case!");
1212 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1215void Verifier::visitDIArgList(
const DIArgList &AL, Function *
F) {
1216 for (
const ValueAsMetadata *VAM :
AL.getArgs())
1217 visitValueAsMetadata(*VAM,
F);
1220void Verifier::visitMetadataAsValue(
const MetadataAsValue &MDV, Function *
F) {
1223 visitMDNode(*
N, AreDebugLocsAllowed::No);
1229 if (!MDNodes.
insert(MD).second)
1233 visitValueAsMetadata(*V,
F);
1236 visitDIArgList(*AL,
F);
1244void Verifier::visitDILocation(
const DILocation &
N) {
1246 "location requires a valid scope", &
N,
N.getRawScope());
1247 if (
auto *IA =
N.getRawInlinedAt())
1250 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1253void Verifier::visitGenericDINode(
const GenericDINode &
N) {
1257void Verifier::visitDIScope(
const DIScope &
N) {
1258 if (
auto *
F =
N.getRawFile())
1262void Verifier::visitDIType(
const DIType &
N) {
1265 CheckDI(
N.getRawFile() ||
N.getLine() == 0,
"line specified with no file", &
N,
1269void Verifier::visitDISubrangeType(
const DISubrangeType &
N) {
1272 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1275 auto *LBound =
N.getRawLowerBound();
1279 "LowerBound must be signed constant or DIVariable or DIExpression or "
1282 auto *UBound =
N.getRawUpperBound();
1286 "UpperBound must be signed constant or DIVariable or DIExpression or "
1289 auto *Stride =
N.getRawStride();
1292 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1293 auto *Bias =
N.getRawBias();
1296 "Bias must be signed constant or DIVariable or DIExpression", &
N);
1298 auto *
Size =
N.getRawSizeInBits();
1300 "SizeInBits must be a constant");
1303void Verifier::visitDISubrange(
const DISubrange &
N) {
1304 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1305 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1306 "Subrange can have any one of count or upperBound", &
N);
1307 auto *CBound =
N.getRawCountNode();
1310 "Count must be signed constant or DIVariable or DIExpression", &
N);
1311 auto Count =
N.getCount();
1314 "invalid subrange count", &
N);
1315 auto *LBound =
N.getRawLowerBound();
1318 "LowerBound must be signed constant or DIVariable or DIExpression",
1320 auto *UBound =
N.getRawUpperBound();
1323 "UpperBound must be signed constant or DIVariable or DIExpression",
1325 auto *Stride =
N.getRawStride();
1328 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1331void Verifier::visitDIGenericSubrange(
const DIGenericSubrange &
N) {
1332 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1333 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1334 "GenericSubrange can have any one of count or upperBound", &
N);
1335 auto *CBound =
N.getRawCountNode();
1337 "Count must be signed constant or DIVariable or DIExpression", &
N);
1338 auto *LBound =
N.getRawLowerBound();
1339 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1341 "LowerBound must be signed constant or DIVariable or DIExpression",
1343 auto *UBound =
N.getRawUpperBound();
1345 "UpperBound must be signed constant or DIVariable or DIExpression",
1347 auto *Stride =
N.getRawStride();
1348 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1350 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1353void Verifier::visitDIEnumerator(
const DIEnumerator &
N) {
1354 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1357void Verifier::visitDIBasicType(
const DIBasicType &
N) {
1360 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1361 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1362 N.getTag() == dwarf::DW_TAG_string_type,
1365 auto *
Size =
N.getRawSizeInBits();
1367 "SizeInBits must be a constant");
1370void Verifier::visitDIFixedPointType(
const DIFixedPointType &
N) {
1371 visitDIBasicType(
N);
1373 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type,
"invalid tag", &
N);
1374 CheckDI(
N.getEncoding() == dwarf::DW_ATE_signed_fixed ||
1375 N.getEncoding() == dwarf::DW_ATE_unsigned_fixed,
1376 "invalid encoding", &
N);
1380 "invalid kind", &
N);
1382 N.getFactorRaw() == 0,
1383 "factor should be 0 for rationals", &
N);
1385 (
N.getNumeratorRaw() == 0 &&
N.getDenominatorRaw() == 0),
1386 "numerator and denominator should be 0 for non-rationals", &
N);
1389void Verifier::visitDIStringType(
const DIStringType &
N) {
1392 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1393 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1397void Verifier::visitDIDerivedType(
const DIDerivedType &
N) {
1401 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1402 N.getTag() == dwarf::DW_TAG_pointer_type ||
1403 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1404 N.getTag() == dwarf::DW_TAG_reference_type ||
1405 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1406 N.getTag() == dwarf::DW_TAG_const_type ||
1407 N.getTag() == dwarf::DW_TAG_immutable_type ||
1408 N.getTag() == dwarf::DW_TAG_volatile_type ||
1409 N.getTag() == dwarf::DW_TAG_restrict_type ||
1410 N.getTag() == dwarf::DW_TAG_atomic_type ||
1411 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1412 N.getTag() == dwarf::DW_TAG_member ||
1413 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1414 N.getTag() == dwarf::DW_TAG_inheritance ||
1415 N.getTag() == dwarf::DW_TAG_friend ||
1416 N.getTag() == dwarf::DW_TAG_set_type ||
1417 N.getTag() == dwarf::DW_TAG_template_alias,
1419 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1420 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1421 N.getRawExtraData());
1422 }
else if (
N.getTag() == dwarf::DW_TAG_template_alias) {
1424 N.getRawExtraData());
1425 }
else if (
N.getTag() == dwarf::DW_TAG_inheritance ||
1426 N.getTag() == dwarf::DW_TAG_member ||
1427 N.getTag() == dwarf::DW_TAG_variable) {
1428 auto *ExtraData =
N.getRawExtraData();
1429 auto IsValidExtraData = [&]() {
1430 if (ExtraData ==
nullptr)
1436 if (Tuple->getNumOperands() != 1)
1443 "extraData must be ConstantAsMetadata, MDString, DIObjCProperty, "
1444 "or MDTuple with single ConstantAsMetadata operand",
1448 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1449 if (
auto *
T =
N.getRawBaseType()) {
1454 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1455 (Subrange &&
Subrange->getTag() == dwarf::DW_TAG_subrange_type) ||
1456 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1457 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1458 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1459 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1460 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1461 "invalid set base type", &
N,
T);
1466 N.getRawBaseType());
1468 if (
N.getDWARFAddressSpace()) {
1469 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1470 N.getTag() == dwarf::DW_TAG_reference_type ||
1471 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1472 "DWARF address space only applies to pointer or reference types",
1476 auto *
Size =
N.getRawSizeInBits();
1479 "SizeInBits must be a constant or DIVariable or DIExpression");
1484 return ((Flags & DINode::FlagLValueReference) &&
1485 (Flags & DINode::FlagRValueReference)) ||
1486 ((Flags & DINode::FlagTypePassByValue) &&
1487 (Flags & DINode::FlagTypePassByReference));
1490void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1492 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1499void Verifier::visitDICompositeType(
const DICompositeType &
N) {
1503 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1504 N.getTag() == dwarf::DW_TAG_structure_type ||
1505 N.getTag() == dwarf::DW_TAG_union_type ||
1506 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1507 N.getTag() == dwarf::DW_TAG_class_type ||
1508 N.getTag() == dwarf::DW_TAG_variant_part ||
1509 N.getTag() == dwarf::DW_TAG_variant ||
1510 N.getTag() == dwarf::DW_TAG_namelist,
1514 N.getRawBaseType());
1517 "invalid composite elements", &
N,
N.getRawElements());
1519 N.getRawVTableHolder());
1521 "invalid reference flags", &
N);
1522 unsigned DIBlockByRefStruct = 1 << 4;
1523 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1524 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1526 "DISubprogram contains null entry in `elements` field", &
N);
1529 const DINodeArray
Elements =
N.getElements();
1531 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1532 "invalid vector, expected one element of type subrange", &
N);
1535 if (
auto *Params =
N.getRawTemplateParams())
1536 visitTemplateParams(
N, *Params);
1538 if (
auto *
D =
N.getRawDiscriminator()) {
1540 "discriminator can only appear on variant part");
1543 if (
N.getRawDataLocation()) {
1544 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1545 "dataLocation can only appear in array type");
1548 if (
N.getRawAssociated()) {
1549 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1550 "associated can only appear in array type");
1553 if (
N.getRawAllocated()) {
1554 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1555 "allocated can only appear in array type");
1558 if (
N.getRawRank()) {
1559 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1560 "rank can only appear in array type");
1563 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1564 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1567 auto *
Size =
N.getRawSizeInBits();
1570 "SizeInBits must be a constant or DIVariable or DIExpression");
1573void Verifier::visitDISubroutineType(
const DISubroutineType &
N) {
1575 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1576 if (
auto *Types =
N.getRawTypeArray()) {
1578 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1579 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1583 "invalid reference flags", &
N);
1586void Verifier::visitDIFile(
const DIFile &
N) {
1587 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1588 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1590 CheckDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last,
1591 "invalid checksum kind", &
N);
1593 switch (Checksum->Kind) {
1604 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1606 "invalid checksum", &
N);
1610void Verifier::visitDICompileUnit(
const DICompileUnit &
N) {
1611 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1612 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1618 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1622 "invalid emission kind", &
N);
1625 "invalid language dialect", &
N);
1627 if (
auto *Array =
N.getRawEnumTypes()) {
1629 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1631 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1632 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1634 "function-local enum in a DICompileUnit's enum list", &
N,
1635 N.getEnumTypes(),
Op);
1638 if (
auto *Array =
N.getRawRetainedTypes()) {
1640 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1644 "invalid retained type", &
N,
Op);
1647 if (
auto *Array =
N.getRawGlobalVariables()) {
1649 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1651 "invalid global variable ref", &
N,
Op);
1654 if (
auto *Array =
N.getRawImportedEntities()) {
1656 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1658 CheckDI(IE,
"invalid imported entity ref", &
N,
Op);
1660 "function-local imports are not allowed in a DICompileUnit's "
1661 "imported entities list",
1665 if (
auto *Array =
N.getRawMacros()) {
1674void Verifier::visitDISubprogram(
const DISubprogram &
N) {
1675 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1677 if (
auto *
F =
N.getRawFile())
1680 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1681 auto *
T =
N.getRawType();
1682 CheckDI(
T,
"DISubprogram requires a non-null type", &
N);
1684 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1685 N.getRawContainingType());
1686 if (
auto *Params =
N.getRawTemplateParams())
1687 visitTemplateParams(
N, *Params);
1688 if (
auto *S =
N.getRawDeclaration())
1690 "invalid subprogram declaration", &
N, S);
1691 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1693 CheckDI(Node,
"invalid retained nodes list", &
N, RawNode);
1695 DenseMap<unsigned, DILocalVariable *>
Args;
1697 CheckDI(
Op,
"nullptr in retained nodes", &
N, Node);
1699 auto True = [](
const Metadata *) {
return true; };
1700 auto False = [](
const Metadata *) {
return false; };
1701 bool IsTypeCorrect = DISubprogram::visitRetainedNode<bool>(
1702 Op, True, True, True, True, False);
1704 "invalid retained nodes, expected DILocalVariable, DILabel, "
1705 "DIImportedEntity or DIType",
1712 "invalid retained nodes, retained node is not local", &
N, Node,
1715 DISubprogram *RetainedNodeSP = RetainedNodeScope->getSubprogram();
1716 DICompileUnit *RetainedNodeUnit =
1717 RetainedNodeSP ? RetainedNodeSP->getUnit() :
nullptr;
1719 RetainedNodeSP == &
N,
1720 "invalid retained nodes, retained node does not belong to subprogram",
1721 &
N, Node, RetainedNode, RetainedNodeScope, RetainedNodeSP,
1727 if (
unsigned ArgNum = DV->getArg()) {
1729 CheckDI(Inserted || DV == ArgI->second,
1730 "invalid retained nodes, more than one local variable with the "
1731 "same argument index",
1732 &
N,
N.getUnit(), Node, RetainedNode, Args[ArgNum]);
1737 "invalid reference flags", &
N);
1739 auto *
Unit =
N.getRawUnit();
1740 if (
N.isDefinition()) {
1742 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1743 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1748 if (CT && CT->getRawIdentifier() &&
1749 M.getContext().isODRUniquingDebugTypes())
1751 "definition subprograms cannot be nested within DICompositeType "
1752 "when enabling ODR",
1756 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1758 "subprogram declaration must not have a declaration field");
1761 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1763 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1769 if (
N.areAllCallsDescribed())
1771 "DIFlagAllCallsDescribed must be attached to a definition");
1774void Verifier::visitDILexicalBlockBase(
const DILexicalBlockBase &
N) {
1775 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1777 "invalid local scope", &
N,
N.getRawScope());
1779 CheckDI(
SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1782void Verifier::visitDILexicalBlock(
const DILexicalBlock &
N) {
1783 visitDILexicalBlockBase(
N);
1786 "cannot have column info without line info", &
N);
1789void Verifier::visitDILexicalBlockFile(
const DILexicalBlockFile &
N) {
1790 visitDILexicalBlockBase(
N);
1793void Verifier::visitDICommonBlock(
const DICommonBlock &
N) {
1794 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1795 if (
auto *S =
N.getRawScope())
1797 if (
auto *S =
N.getRawDecl())
1801void Verifier::visitDINamespace(
const DINamespace &
N) {
1802 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1803 if (
auto *S =
N.getRawScope())
1807void Verifier::visitDIMacro(
const DIMacro &
N) {
1810 "invalid macinfo type", &
N);
1811 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1812 if (!
N.getValue().empty()) {
1813 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1817void Verifier::visitDIMacroFile(
const DIMacroFile &
N) {
1819 "invalid macinfo type", &
N);
1820 if (
auto *
F =
N.getRawFile())
1823 if (
auto *Array =
N.getRawElements()) {
1825 for (
Metadata *
Op :
N.getElements()->operands()) {
1831void Verifier::visitDIModule(
const DIModule &
N) {
1832 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1833 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1836void Verifier::visitDITemplateParameter(
const DITemplateParameter &
N) {
1840void Verifier::visitDITemplateTypeParameter(
const DITemplateTypeParameter &
N) {
1841 visitDITemplateParameter(
N);
1843 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1847void Verifier::visitDITemplateValueParameter(
1848 const DITemplateValueParameter &
N) {
1849 visitDITemplateParameter(
N);
1851 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1852 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1853 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1857void Verifier::visitDIVariable(
const DIVariable &
N) {
1858 if (
auto *S =
N.getRawScope())
1860 if (
auto *
F =
N.getRawFile())
1864void Verifier::visitDIGlobalVariable(
const DIGlobalVariable &
N) {
1868 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1871 if (
N.isDefinition())
1872 CheckDI(
N.getType(),
"missing global variable type", &
N);
1873 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1875 "invalid static data member declaration", &
N, Member);
1879void Verifier::visitDILocalVariable(
const DILocalVariable &
N) {
1884 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1886 "local variable requires a valid scope", &
N,
N.getRawScope());
1887 if (
auto Ty =
N.getType())
1891void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1892 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1893 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1896void Verifier::visitDILabel(
const DILabel &
N) {
1897 if (
auto *S =
N.getRawScope())
1899 if (
auto *
F =
N.getRawFile())
1902 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1904 "label requires a valid scope", &
N,
N.getRawScope());
1907void Verifier::visitDIExpression(
const DIExpression &
N) {
1908 CheckDI(
N.isValid(),
"invalid expression", &
N);
1911void Verifier::visitDIGlobalVariableExpression(
1912 const DIGlobalVariableExpression &GVE) {
1915 visitDIGlobalVariable(*Var);
1917 visitDIExpression(*Expr);
1918 if (
auto Fragment = Expr->getFragmentInfo())
1919 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1923void Verifier::visitDIObjCProperty(
const DIObjCProperty &
N) {
1924 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1925 if (
auto *
T =
N.getRawType())
1927 if (
auto *
F =
N.getRawFile())
1931void Verifier::visitDIImportedEntity(
const DIImportedEntity &
N) {
1932 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1933 N.getTag() == dwarf::DW_TAG_imported_declaration,
1935 if (
auto *S =
N.getRawScope())
1941void Verifier::visitComdat(
const Comdat &
C) {
1944 if (
TT.isOSBinFormatCOFF())
1945 if (
const GlobalValue *GV =
M.getNamedValue(
C.getName()))
1950void Verifier::visitModuleIdents() {
1951 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1957 for (
const MDNode *
N : Idents->
operands()) {
1958 Check(
N->getNumOperands() == 1,
1959 "incorrect number of operands in llvm.ident metadata",
N);
1961 (
"invalid value for llvm.ident metadata entry operand"
1962 "(the operand should be a string)"),
1967void Verifier::visitModuleCommandLines() {
1968 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1975 for (
const MDNode *
N : CommandLines->
operands()) {
1976 Check(
N->getNumOperands() == 1,
1977 "incorrect number of operands in llvm.commandline metadata",
N);
1979 (
"invalid value for llvm.commandline metadata entry operand"
1980 "(the operand should be a string)"),
1985void Verifier::visitModuleErrnoTBAA() {
1986 const NamedMDNode *ErrnoTBAA =
M.getNamedMetadata(
"llvm.errno.tbaa");
1991 "llvm.errno.tbaa must have at least one operand", ErrnoTBAA);
1993 for (
const MDNode *
N : ErrnoTBAA->
operands())
1997void Verifier::visitModuleFlags() {
1998 const NamedMDNode *
Flags =
M.getModuleFlagsMetadata();
2002 DenseMap<const MDString*, const MDNode*> SeenIDs;
2004 uint64_t PAuthABIPlatform = -1;
2005 uint64_t PAuthABIVersion = -1;
2006 for (
const MDNode *MDN :
Flags->operands()) {
2007 visitModuleFlag(MDN, SeenIDs, Requirements);
2008 if (MDN->getNumOperands() != 3)
2011 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
2012 if (
const auto *PAP =
2014 PAuthABIPlatform = PAP->getZExtValue();
2015 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
2016 if (
const auto *PAV =
2018 PAuthABIVersion = PAV->getZExtValue();
2023 if ((PAuthABIPlatform == uint64_t(-1)) != (PAuthABIVersion == uint64_t(-1)))
2024 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
2025 "'aarch64-elf-pauthabi-version' module flags must be present");
2028 for (
const MDNode *Requirement : Requirements) {
2030 const Metadata *ReqValue = Requirement->getOperand(1);
2032 const MDNode *
Op = SeenIDs.
lookup(Flag);
2034 CheckFailed(
"invalid requirement on flag, flag is not present in module",
2039 if (
Op->getOperand(2) != ReqValue) {
2040 CheckFailed((
"invalid requirement on flag, "
2041 "flag does not have the required value"),
2049Verifier::visitModuleFlag(
const MDNode *
Op,
2050 DenseMap<const MDString *, const MDNode *> &SeenIDs,
2051 SmallVectorImpl<const MDNode *> &Requirements) {
2055 "incorrect number of operands in module flag",
Op);
2056 Module::ModFlagBehavior MFB;
2057 if (!Module::isValidModFlagBehavior(
Op->getOperand(0), MFB)) {
2059 "invalid behavior operand in module flag (expected constant integer)",
2062 "invalid behavior operand in module flag (unexpected constant)",
2066 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
2072 case Module::Warning:
2073 case Module::Override:
2079 Check(V &&
V->getValue().isNonNegative(),
2080 "invalid value for 'min' module flag (expected constant non-negative "
2088 "invalid value for 'max' module flag (expected constant integer)",
2093 case Module::Require: {
2098 "invalid value for 'require' module flag (expected metadata pair)",
2101 (
"invalid value for 'require' module flag "
2102 "(first value operand should be a string)"),
2103 Value->getOperand(0));
2111 case Module::Append:
2112 case Module::AppendUnique: {
2115 "invalid value for 'append'-type module flag "
2116 "(expected a metadata node)",
2123 if (MFB != Module::Require) {
2126 "module flag identifiers must be unique (or of 'require' type)",
ID);
2129 if (
ID->getString() ==
"wchar_size") {
2132 Check(
Value,
"wchar_size metadata requires constant integer argument");
2135 if (
ID->getString() ==
"Linker Options") {
2139 Check(
M.getNamedMetadata(
"llvm.linker.options"),
2140 "'Linker Options' named metadata no longer supported");
2143 if (
ID->getString() ==
"SemanticInterposition") {
2144 ConstantInt *
Value =
2147 "SemanticInterposition metadata requires constant integer argument");
2150 if (
ID->getString() ==
"amdgpu.buffer.oob.mode" ||
2151 ID->getString() ==
"amdgpu.tbuffer.oob.mode") {
2152 Check(MFB == Module::Max,
2153 "'" +
ID->getString() +
2154 "' module flag must use 'max' merge behaviour");
2155 ConstantInt *
Value =
2158 "' module flag must have a constant integer value");
2161 "'" +
ID->getString() +
"' module flag must be 0, 1, or 2");
2165 if (
ID->getString() ==
"CG Profile") {
2166 for (
const MDOperand &MDO :
cast<MDNode>(
Op->getOperand(2))->operands())
2167 visitModuleFlagCGProfileEntry(MDO);
2171void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
2172 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
2177 "expected a Function or null", FuncMDO);
2180 Check(Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
2181 CheckFunction(
Node->getOperand(0));
2182 CheckFunction(
Node->getOperand(1));
2185 "expected an integer constant",
Node->getOperand(2));
2188void Verifier::verifyAttributeTypes(AttributeSet Attrs,
const Value *V) {
2191 if (
A.isStringAttribute()) {
2192#define GET_ATTR_NAMES
2193#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
2194#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
2195 if (A.getKindAsString() == #DISPLAY_NAME) { \
2196 auto V = A.getValueAsString(); \
2197 if (!(V.empty() || V == "true" || V == "false")) \
2198 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
2202#include "llvm/IR/Attributes.inc"
2206 if (
A.isIntAttribute() != Attribute::isIntAttrKind(
A.getKindAsEnum())) {
2207 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
2216void Verifier::verifyParameterAttrs(AttributeSet Attrs,
Type *Ty,
2218 if (!
Attrs.hasAttributes())
2221 verifyAttributeTypes(Attrs, V);
2224 Check(Attr.isStringAttribute() ||
2225 Attribute::canUseAsParamAttr(Attr.getKindAsEnum()),
2226 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
2229 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
2230 unsigned AttrCount =
2231 Attrs.getNumAttributes() -
Attrs.hasAttribute(Attribute::Range);
2232 Check(AttrCount == 1,
2233 "Attribute 'immarg' is incompatible with other attributes except the "
2234 "'range' attribute",
2240 unsigned AttrCount = 0;
2241 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
2242 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
2243 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
2244 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
2245 Attrs.hasAttribute(Attribute::InReg);
2246 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
2247 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
2248 Check(AttrCount <= 1,
2249 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
2250 "'byref', and 'sret' are incompatible!",
2253 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
2254 Attrs.hasAttribute(Attribute::ReadOnly)),
2256 "'inalloca and readonly' are incompatible!",
2259 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
2260 Attrs.hasAttribute(Attribute::Returned)),
2262 "'sret and returned' are incompatible!",
2265 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
2266 Attrs.hasAttribute(Attribute::SExt)),
2268 "'zeroext and signext' are incompatible!",
2271 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2272 Attrs.hasAttribute(Attribute::ReadOnly)),
2274 "'readnone and readonly' are incompatible!",
2277 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
2278 Attrs.hasAttribute(Attribute::WriteOnly)),
2280 "'readnone and writeonly' are incompatible!",
2283 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
2284 Attrs.hasAttribute(Attribute::WriteOnly)),
2286 "'readonly and writeonly' are incompatible!",
2289 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
2290 Attrs.hasAttribute(Attribute::AlwaysInline)),
2292 "'noinline and alwaysinline' are incompatible!",
2295 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2296 Attrs.hasAttribute(Attribute::ReadNone)),
2297 "Attributes writable and readnone are incompatible!", V);
2299 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2300 Attrs.hasAttribute(Attribute::ReadOnly)),
2301 "Attributes writable and readonly are incompatible!", V);
2303 AttributeMask IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty, Attrs);
2305 if (!Attr.isStringAttribute() &&
2306 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2307 CheckFailed(
"Attribute '" + Attr.getAsString() +
2308 "' applied to incompatible type!", V);
2314 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2315 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2316 Check(AttrAlign.
value() <= Value::MaximumAlignment,
2317 "huge alignment values are unsupported", V);
2319 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2321 SmallPtrSet<Type *, 4> Visited;
2323 "Attribute 'byval' does not support unsized types!", V);
2327 "'byval' argument has illegal target extension type", V);
2328 Check(
DL.getTypeAllocSize(ByValTy).getKnownMinValue() < (1ULL << 32),
2329 "huge 'byval' arguments are unsupported", V);
2331 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2332 SmallPtrSet<Type *, 4> Visited;
2333 Check(
Attrs.getByRefType()->isSized(&Visited),
2334 "Attribute 'byref' does not support unsized types!", V);
2335 Check(
DL.getTypeAllocSize(
Attrs.getByRefType()).getKnownMinValue() <
2337 "huge 'byref' arguments are unsupported", V);
2339 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2340 SmallPtrSet<Type *, 4> Visited;
2341 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2342 "Attribute 'inalloca' does not support unsized types!", V);
2343 Check(
DL.getTypeAllocSize(
Attrs.getInAllocaType()).getKnownMinValue() <
2345 "huge 'inalloca' arguments are unsupported", V);
2347 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2348 SmallPtrSet<Type *, 4> Visited;
2349 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2350 "Attribute 'preallocated' does not support unsized types!", V);
2352 DL.getTypeAllocSize(
Attrs.getPreallocatedType()).getKnownMinValue() <
2354 "huge 'preallocated' arguments are unsupported", V);
2358 if (
Attrs.hasAttribute(Attribute::Initializes)) {
2359 auto Inits =
Attrs.getAttribute(Attribute::Initializes).getInitializes();
2360 Check(!Inits.empty(),
"Attribute 'initializes' does not support empty list",
2363 "Attribute 'initializes' does not support unordered ranges", V);
2366 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2367 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2368 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2371 "Invalid value for 'nofpclass' test mask", V);
2373 if (
Attrs.hasAttribute(Attribute::Range)) {
2374 const ConstantRange &CR =
2375 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2377 "Range bit width must match type bit width!", V);
2381void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr,
2383 if (
Attrs.hasFnAttr(Attr)) {
2384 StringRef S =
Attrs.getFnAttr(Attr).getValueAsString();
2387 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2393void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
2394 const Value *V,
bool IsIntrinsic,
2396 if (
Attrs.isEmpty())
2399 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2401 "Attribute list does not match Module context!", &Attrs, V);
2402 for (
const auto &AttrSet : Attrs) {
2403 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(
Context),
2404 "Attribute set does not match Module context!", &AttrSet, V);
2405 for (
const auto &
A : AttrSet) {
2407 "Attribute does not match Module context!", &
A, V);
2412 bool SawNest =
false;
2413 bool SawReturned =
false;
2414 bool SawSRet =
false;
2415 bool SawSwiftSelf =
false;
2416 bool SawSwiftAsync =
false;
2417 bool SawSwiftError =
false;
2420 AttributeSet RetAttrs =
Attrs.getRetAttrs();
2423 Attribute::canUseAsRetAttr(
RetAttr.getKindAsEnum()),
2424 "Attribute '" +
RetAttr.getAsString() +
2425 "' does not apply to function return values",
2428 unsigned MaxParameterWidth = 0;
2429 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2432 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2433 if (
Size > MaxParameterWidth)
2434 MaxParameterWidth =
Size;
2438 GetMaxParameterWidth(FT->getReturnType());
2439 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2442 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2443 Type *Ty = FT->getParamType(i);
2444 AttributeSet ArgAttrs =
Attrs.getParamAttrs(i);
2448 "immarg attribute only applies to intrinsics", V);
2451 "Attribute 'elementtype' can only be applied to intrinsics"
2456 verifyParameterAttrs(ArgAttrs, Ty, V);
2457 GetMaxParameterWidth(Ty);
2460 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2465 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2467 "Incompatible argument and return types for 'returned' attribute",
2473 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2474 Check(i == 0 || i == 1,
2475 "Attribute 'sret' is not on first or second parameter!", V);
2480 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2481 SawSwiftSelf =
true;
2485 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2486 SawSwiftAsync =
true;
2490 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2491 SawSwiftError =
true;
2495 Check(i == FT->getNumParams() - 1,
2496 "inalloca isn't on the last parameter!", V);
2500 if (!
Attrs.hasFnAttrs())
2503 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2506 Attribute::canUseAsFnAttr(
FnAttr.getKindAsEnum()),
2507 "Attribute '" +
FnAttr.getAsString() +
2508 "' does not apply to functions!",
2511 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2512 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2513 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2515 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2517 "Attribute 'optnone' requires 'noinline'!", V);
2519 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2520 "Attributes 'optsize and optnone' are incompatible!", V);
2523 "Attributes 'minsize and optnone' are incompatible!", V);
2525 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2526 "Attributes 'optdebug and optnone' are incompatible!", V);
2529 Check(!(
Attrs.hasFnAttr(Attribute::SanitizeRealtime) &&
2530 Attrs.hasFnAttr(Attribute::SanitizeRealtimeBlocking)),
2532 "'sanitize_realtime and sanitize_realtime_blocking' are incompatible!",
2535 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2536 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2537 "Attributes 'optsize and optdebug' are incompatible!", V);
2540 "Attributes 'minsize and optdebug' are incompatible!", V);
2543 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2544 isModSet(
Attrs.getMemoryEffects().getModRef(IRMemLocation::ArgMem)),
2545 "Attribute writable and memory without argmem: write are incompatible!",
2548 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2549 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2550 "Attributes 'aarch64_pstate_sm_enabled and "
2551 "aarch64_pstate_sm_compatible' are incompatible!",
2555 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2556 Attrs.hasFnAttr(
"aarch64_inout_za") +
2557 Attrs.hasFnAttr(
"aarch64_out_za") +
2558 Attrs.hasFnAttr(
"aarch64_preserves_za") +
2559 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2560 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2561 "'aarch64_inout_za', 'aarch64_preserves_za' and "
2562 "'aarch64_za_state_agnostic' are mutually exclusive",
2566 Attrs.hasFnAttr(
"aarch64_in_zt0") +
2567 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2568 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2569 Attrs.hasFnAttr(
"aarch64_preserves_zt0") +
2570 Attrs.hasFnAttr(
"aarch64_za_state_agnostic")) <= 1,
2571 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2572 "'aarch64_inout_zt0', 'aarch64_preserves_zt0' and "
2573 "'aarch64_za_state_agnostic' are mutually exclusive",
2576 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2579 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2582 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2583 auto CheckParam = [&](StringRef
Name,
unsigned ParamNo) {
2584 if (ParamNo >= FT->getNumParams()) {
2585 CheckFailed(
"'allocsize' " + Name +
" argument is out of bounds", V);
2589 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2590 CheckFailed(
"'allocsize' " + Name +
2591 " argument must refer to an integer parameter",
2599 if (!CheckParam(
"element size",
Args->first))
2602 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2606 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2609 K & (AllocFnKind::Alloc | AllocFnKind::Realloc | AllocFnKind::Free);
2611 {AllocFnKind::Alloc, AllocFnKind::Realloc, AllocFnKind::Free},
2614 "'allockind()' requires exactly one of alloc, realloc, and free");
2615 if ((
Type == AllocFnKind::Free) &&
2616 ((K & (AllocFnKind::Uninitialized | AllocFnKind::Zeroed |
2617 AllocFnKind::Aligned)) != AllocFnKind::Unknown))
2618 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2619 "or aligned modifiers.");
2620 AllocFnKind ZeroedUninit = AllocFnKind::Uninitialized | AllocFnKind::Zeroed;
2621 if ((K & ZeroedUninit) == ZeroedUninit)
2622 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2626 StringRef S =
A.getValueAsString();
2627 Check(!S.
empty(),
"'alloc-variant-zeroed' must not be empty");
2635 "'alloc-variant-zeroed' must name a function belonging to the "
2636 "same 'alloc-family'");
2639 (
Variant->getFnAttribute(Attribute::AllocKind).getAllocKind() &
2640 AllocFnKind::Zeroed) != AllocFnKind::Unknown,
2641 "'alloc-variant-zeroed' must name a function with "
2642 "'allockind(\"zeroed\")'");
2645 "'alloc-variant-zeroed' must name a function with the same "
2650 "'alloc-variant-zeroed' must name a function with the same "
2651 "calling convention");
2655 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2656 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2658 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2660 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2661 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2662 if (VScaleMax && VScaleMin > VScaleMax)
2663 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2665 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2668 if (
Attribute FPAttr =
Attrs.getFnAttr(
"frame-pointer"); FPAttr.isValid()) {
2669 StringRef
FP = FPAttr.getValueAsString();
2670 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none" &&
FP !=
"reserved" &&
2671 FP !=
"non-leaf-no-reserve")
2672 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2675 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2676 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2677 if (
Attrs.hasFnAttr(
"patchable-function-entry-section"))
2678 Check(!
Attrs.getFnAttr(
"patchable-function-entry-section")
2681 "\"patchable-function-entry-section\" must not be empty");
2682 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2684 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2685 StringRef S =
A.getValueAsString();
2686 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2687 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2690 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2691 StringRef S =
A.getValueAsString();
2692 if (S !=
"a_key" && S !=
"b_key")
2693 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2695 if (
auto AA =
Attrs.getFnAttr(
"sign-return-address"); !AA.isValid()) {
2697 "'sign-return-address-key' present without `sign-return-address`");
2701 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2702 StringRef S =
A.getValueAsString();
2703 if (S !=
"" && S !=
"true" && S !=
"false")
2705 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2708 if (
auto A =
Attrs.getFnAttr(
"branch-protection-pauth-lr");
A.isValid()) {
2709 StringRef S =
A.getValueAsString();
2710 if (S !=
"" && S !=
"true" && S !=
"false")
2712 "invalid value for 'branch-protection-pauth-lr' attribute: " + S, V);
2715 if (
auto A =
Attrs.getFnAttr(
"guarded-control-stack");
A.isValid()) {
2716 StringRef S =
A.getValueAsString();
2717 if (S !=
"" && S !=
"true" && S !=
"false")
2718 CheckFailed(
"invalid value for 'guarded-control-stack' attribute: " + S,
2722 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2723 StringRef S =
A.getValueAsString();
2726 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2729 if (
auto A =
Attrs.getFnAttr(
"modular-format");
A.isValid()) {
2730 StringRef S =
A.getValueAsString();
2734 "modular-format attribute requires at least 5 arguments", V);
2735 unsigned UpperBound = FT->getNumParams() + (FT->isVarArg() ? 1 : 0);
2737 Check(!Args[1].getAsInteger(10, FormatIdx),
2738 "modular-format attribute format string index is not an integer", V);
2739 Check(FormatIdx > 0,
2740 "modular-format attribute format string index must be greater than 0",
2742 Check(FormatIdx <= UpperBound,
2743 "modular-format attribute format string index is out of bounds", V);
2744 unsigned FirstArgIdx;
2745 Check(!Args[2].getAsInteger(10, FirstArgIdx),
2746 "modular-format attribute first arg index is not an integer", V);
2747 Check(FirstArgIdx <= UpperBound,
2748 "modular-format attribute first arg index is out of bounds", V);
2750 "modular-format attribute modular implementation function name "
2754 "modular-format attribute implementation name cannot be empty", V);
2757 if (
auto A =
Attrs.getFnAttr(
"target-features");
A.isValid()) {
2758 StringRef S =
A.getValueAsString();
2760 for (
auto FeatureFlag :
split(S,
',')) {
2761 if (FeatureFlag.empty())
2763 "target-features attribute should not contain an empty string");
2765 Check(FeatureFlag[0] ==
'+' || FeatureFlag[0] ==
'-',
2766 "target feature '" + FeatureFlag +
2767 "' must start with a '+' or '-'",
2773void Verifier::verifyUnknownProfileMetadata(MDNode *MD) {
2775 "'unknown' !prof should have a single additional operand", MD);
2778 "'unknown' !prof should have an additional operand of type "
2781 "the 'unknown' !prof operand should not be an empty string");
2784void Verifier::verifyFunctionMetadata(
2785 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2786 for (
const auto &Pair : MDs) {
2787 if (Pair.first == LLVMContext::MD_prof) {
2788 MDNode *MD = Pair.second;
2790 "!prof annotations should have no less than 2 operands", MD);
2795 verifyUnknownProfileMetadata(MD);
2800 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2803 "expected string with name of the !prof annotation", MD);
2808 "first operand should be 'function_entry_count'"
2809 " or 'synthetic_function_entry_count'",
2813 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2816 "expected integer argument to function_entry_count", MD);
2817 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2818 MDNode *MD = Pair.second;
2820 "!kcfi_type must have exactly one operand", MD);
2821 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2824 "expected a constant operand for !kcfi_type", MD);
2827 "expected a constant integer operand for !kcfi_type", MD);
2829 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2830 }
else if (Pair.first ==
Context.getMDKindID(
"reqd_work_group_size")) {
2831 MDNode *MD = Pair.second;
2833 "reqd_work_group_size must have exactly three operands", MD);
2837 uint64_t Product = 1;
2838 for (
unsigned I = 0;
I != 3; ++
I) {
2840 Check(
C,
"reqd_work_group_size operands must be integer constants", MD);
2844 const APInt &
Value =
C->getValue();
2846 "reqd_work_group_size operands must fit in 64 bits", MD);
2847 if (
Value.getActiveBits() > 64)
2850 uint64_t Dim =
Value.getZExtValue();
2851 Check(Dim == 0 || Product <= std::numeric_limits<uint64_t>::max() / Dim,
2852 "reqd_work_group_size product must fit in 64 bits", MD);
2853 if (Dim != 0 && Product > std::numeric_limits<uint64_t>::max() / Dim)
2861void Verifier::verifyAMDGPUReqdWorkGroupSize(
const Function &
F) {
2869 uint64_t Product = 1;
2872 if (!
C ||
C->getValue().getActiveBits() > 64)
2874 uint64_t Dim =
C->getZExtValue();
2875 if (Dim != 0 && Product > std::numeric_limits<uint64_t>::max() / Dim)
2880 Attribute FlatWorkGroupSize =
F.getFnAttribute(
"amdgpu-flat-work-group-size");
2881 if (!FlatWorkGroupSize.
isValid()) {
2882 CheckFailed(
"reqd_work_group_size requires amdgpu-flat-work-group-size", &
F,
2888 CheckFailed(
"amdgpu-flat-work-group-size must be a string attribute", &
F);
2893 std::pair<StringRef, StringRef> Values = AttrValue.
split(
',');
2896 bool Parsed = !Values.second.contains(
',') &&
2900 CheckFailed(
"amdgpu-flat-work-group-size must be a pair of unsigned "
2906 Check(Min == Product && Max == Product,
2907 "amdgpu-flat-work-group-size must equal the product of "
2908 "reqd_work_group_size operands",
2909 &
F, ReqdWorkGroupSize);
2912void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2916 if (!ConstantExprVisited.
insert(EntryC).second)
2920 Stack.push_back(EntryC);
2922 while (!
Stack.empty()) {
2927 visitConstantExpr(CE);
2930 visitConstantPtrAuth(CPA);
2935 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2941 for (
const Use &U :
C->operands()) {
2945 if (!ConstantExprVisited.
insert(OpC).second)
2947 Stack.push_back(OpC);
2952void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2953 if (
CE->getOpcode() == Instruction::BitCast)
2956 "Invalid bitcast", CE);
2957 else if (
CE->getOpcode() == Instruction::PtrToAddr)
2958 checkPtrToAddr(
CE->getOperand(0)->getType(),
CE->getType(), *CE);
2961void Verifier::visitConstantPtrAuth(
const ConstantPtrAuth *CPA) {
2963 "signed ptrauth constant base pointer must have pointer type");
2966 "signed ptrauth constant must have same type as its base pointer");
2969 "signed ptrauth constant key must be i32 constant integer");
2972 "signed ptrauth constant address discriminator must be a pointer");
2975 "signed ptrauth constant discriminator must be i64 constant integer");
2978 "signed ptrauth constant deactivation symbol must be a pointer");
2982 "signed ptrauth constant deactivation symbol must be a global value "
2986bool Verifier::verifyAttributeCount(AttributeList Attrs,
unsigned Params) {
2989 return Attrs.getNumAttrSets() <= Params + 2;
2992void Verifier::verifyInlineAsmCall(
const CallBase &
Call) {
2995 unsigned LabelNo = 0;
2996 for (
const InlineAsm::ConstraintInfo &CI :
IA->ParseConstraints()) {
3006 if (CI.isIndirect) {
3009 "Operand for indirect constraint must have pointer type", &
Call);
3012 "Operand for indirect constraint must have elementtype attribute",
3016 "Elementtype attribute can only be applied for indirect "
3025 Check(LabelNo == CallBr->getNumIndirectDests(),
3026 "Number of label constraints does not match number of callbr dests",
3029 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
3035void Verifier::verifyStatepoint(
const CallBase &
Call) {
3040 "gc.statepoint must read and write all memory to preserve "
3041 "reordering restrictions required by safepoint semantics",
3044 const int64_t NumPatchBytes =
3047 Check(NumPatchBytes >= 0,
3048 "gc.statepoint number of patchable bytes must be "
3053 Check(TargetElemType,
3054 "gc.statepoint callee argument must have elementtype attribute",
Call);
3056 Check(TargetFuncType,
3057 "gc.statepoint callee elementtype must be function type",
Call);
3060 Check(NumCallArgs >= 0,
3061 "gc.statepoint number of arguments to underlying call "
3064 const int NumParams = (int)TargetFuncType->getNumParams();
3065 if (TargetFuncType->isVarArg()) {
3066 Check(NumCallArgs >= NumParams,
3067 "gc.statepoint mismatch in number of vararg call args",
Call);
3070 Check(TargetFuncType->getReturnType()->isVoidTy(),
3071 "gc.statepoint doesn't support wrapping non-void "
3072 "vararg functions yet",
3075 Check(NumCallArgs == NumParams,
3076 "gc.statepoint mismatch in number of call args",
Call);
3078 const uint64_t
Flags
3080 Check((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0,
3081 "unknown flag used in gc.statepoint flags argument",
Call);
3086 for (
int i = 0; i < NumParams; i++) {
3087 Type *ParamType = TargetFuncType->getParamType(i);
3089 Check(ArgType == ParamType,
3090 "gc.statepoint call argument does not match wrapped "
3094 if (TargetFuncType->isVarArg()) {
3095 AttributeSet ArgAttrs =
Attrs.getParamAttrs(5 + i);
3097 "Attribute 'sret' cannot be used for vararg call arguments!",
Call);
3101 const int EndCallArgsInx = 4 + NumCallArgs;
3105 "gc.statepoint number of transition arguments "
3106 "must be constant integer",
3108 const int NumTransitionArgs =
3110 Check(NumTransitionArgs == 0,
3111 "gc.statepoint w/inline transition bundle is deprecated",
Call);
3112 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
3116 "gc.statepoint number of deoptimization arguments "
3117 "must be constant integer",
3120 Check(NumDeoptArgs == 0,
3121 "gc.statepoint w/inline deopt operands is deprecated",
Call);
3123 const int ExpectedNumArgs = 7 + NumCallArgs;
3125 "gc.statepoint too many arguments",
Call);
3132 Check(UserCall,
"illegal use of statepoint token",
Call, U);
3136 "gc.result or gc.relocate are the only value uses "
3137 "of a gc.statepoint",
3141 "gc.result connected to wrong gc.statepoint",
Call, UserCall);
3144 "gc.relocate connected to wrong gc.statepoint",
Call, UserCall);
3158void Verifier::verifyFrameRecoverIndices() {
3159 for (
auto &Counts : FrameEscapeInfo) {
3161 unsigned EscapedObjectCount = Counts.second.first;
3162 unsigned MaxRecoveredIndex = Counts.second.second;
3163 Check(MaxRecoveredIndex <= EscapedObjectCount,
3164 "all indices passed to llvm.localrecover must be less than the "
3165 "number of arguments passed to llvm.localescape in the parent "
3174 UnwindDest =
II->getUnwindDest();
3176 UnwindDest = CSI->getUnwindDest();
3182void Verifier::verifySiblingFuncletUnwinds() {
3183 llvm::TimeTraceScope timeScope(
"Verifier verify sibling funclet unwinds");
3184 SmallPtrSet<Instruction *, 8> Visited;
3185 SmallPtrSet<Instruction *, 8>
Active;
3186 for (
const auto &Pair : SiblingFuncletInfo) {
3188 if (Visited.
count(PredPad))
3194 if (
Active.count(SuccPad)) {
3197 SmallVector<Instruction *, 8> CycleNodes;
3200 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
3201 if (CycleTerminator != CyclePad)
3204 }
while (CyclePad != SuccPad);
3205 Check(
false,
"EH pads can't handle each other's exceptions",
3209 if (!Visited.
insert(SuccPad).second)
3213 auto TermI = SiblingFuncletInfo.find(PredPad);
3214 if (TermI == SiblingFuncletInfo.end())
3227void Verifier::visitFunction(
const Function &
F) {
3228 visitGlobalValue(
F);
3231 FunctionType *FT =
F.getFunctionType();
3232 unsigned NumArgs =
F.arg_size();
3235 "Function context does not match Module context!", &
F);
3237 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
3238 Check(FT->getNumParams() == NumArgs,
3239 "# formal arguments must match # of arguments for function type!", &
F,
3241 Check(
F.getReturnType()->isFirstClassType() ||
3242 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
3243 "Functions cannot return aggregate values!", &
F);
3245 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
3246 "Invalid struct return type!", &
F);
3248 if (MaybeAlign
A =
F.getAlign()) {
3249 Check(
A->value() <= Value::MaximumAlignment,
3250 "huge alignment values are unsupported", &
F);
3253 AttributeList
Attrs =
F.getAttributes();
3255 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
3256 "Attribute after last parameter!", &
F);
3258 bool IsIntrinsic =
F.isIntrinsic();
3261 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
3267 "Attribute 'builtin' can only be applied to a callsite.", &
F);
3269 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
3270 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
3272 if (
Attrs.hasFnAttr(Attribute::Naked))
3273 for (
const Argument &Arg :
F.args())
3274 Check(Arg.use_empty(),
"cannot use argument of naked function", &Arg);
3279 switch (
F.getCallingConv()) {
3281 case CallingConv::C:
3283 case CallingConv::X86_INTR: {
3284 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
3285 "Calling convention parameter requires byval", &
F);
3288 case CallingConv::AMDGPU_KERNEL:
3289 case CallingConv::SPIR_KERNEL:
3290 case CallingConv::AMDGPU_CS_Chain:
3291 case CallingConv::AMDGPU_CS_ChainPreserve:
3292 Check(
F.getReturnType()->isVoidTy(),
3293 "Calling convention requires void return type", &
F);
3295 case CallingConv::AMDGPU_VS:
3296 case CallingConv::AMDGPU_HS:
3297 case CallingConv::AMDGPU_GS:
3298 case CallingConv::AMDGPU_PS:
3299 case CallingConv::AMDGPU_CS:
3300 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
3301 if (
F.getCallingConv() != CallingConv::SPIR_KERNEL) {
3302 const unsigned StackAS =
DL.getAllocaAddrSpace();
3304 for (
const Argument &Arg :
F.args()) {
3305 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
3306 "Calling convention disallows byval", &
F);
3307 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
3308 "Calling convention disallows preallocated", &
F);
3309 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
3310 "Calling convention disallows inalloca", &
F);
3312 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
3315 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
3316 "Calling convention disallows stack byref", &
F);
3324 case CallingConv::Fast:
3325 case CallingConv::Cold:
3326 case CallingConv::Intel_OCL_BI:
3327 case CallingConv::PTX_Kernel:
3328 case CallingConv::PTX_Device:
3330 "Calling convention does not support varargs or "
3331 "perfect forwarding!",
3334 case CallingConv::AMDGPU_Gfx_WholeWave:
3335 Check(!
F.arg_empty() &&
F.arg_begin()->getType()->isIntegerTy(1),
3336 "Calling convention requires first argument to be i1", &
F);
3337 Check(!
F.arg_begin()->hasInRegAttr(),
3338 "Calling convention requires first argument to not be inreg", &
F);
3340 "Calling convention does not support varargs or "
3341 "perfect forwarding!",
3348 for (
const Argument &Arg :
F.args()) {
3349 Check(Arg.getType() == FT->getParamType(i),
3350 "Argument value does not match function argument type!", &Arg,
3351 FT->getParamType(i));
3352 Check(Arg.getType()->isFirstClassType(),
3353 "Function arguments must have first-class types!", &Arg);
3355 Check(!Arg.getType()->isMetadataTy(),
3356 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
3357 Check(!Arg.getType()->isTokenLikeTy(),
3358 "Function takes token but isn't an intrinsic", &Arg, &
F);
3359 Check(!Arg.getType()->isX86_AMXTy(),
3360 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
3364 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
3365 verifySwiftErrorValue(&Arg);
3371 Check(!
F.getReturnType()->isTokenLikeTy(),
3372 "Function returns a token but isn't an intrinsic", &
F);
3373 Check(!
F.getReturnType()->isX86_AMXTy(),
3374 "Function returns a x86_amx but isn't an intrinsic", &
F);
3379 F.getAllMetadata(MDs);
3380 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
3381 verifyFunctionMetadata(MDs);
3382 verifyAMDGPUReqdWorkGroupSize(
F);
3385 if (
F.hasPersonalityFn()) {
3388 Check(Per->getParent() ==
F.getParent(),
3389 "Referencing personality function in another module!", &
F,
3390 F.getParent(), Per, Per->getParent());
3394 BlockEHFuncletColors.
clear();
3396 if (
F.isMaterializable()) {
3398 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
3400 }
else if (
F.isDeclaration()) {
3401 for (
const auto &
I : MDs) {
3403 CheckDI(
I.first != LLVMContext::MD_dbg ||
3405 "function declaration may only have a unique !dbg attachment",
3407 Check(
I.first != LLVMContext::MD_prof,
3408 "function declaration may not have a !prof attachment", &
F);
3411 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
3413 Check(!
F.hasPersonalityFn(),
3414 "Function declaration shouldn't have a personality routine", &
F);
3418 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
3423 "Entry block to function must not have predecessors!", Entry);
3426 if (
Entry->hasAddressTaken()) {
3428 "blockaddress may not be used with the entry block!", Entry);
3431 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
3432 NumKCFIAttachments = 0;
3434 for (
const auto &
I : MDs) {
3436 auto AllowLocs = AreDebugLocsAllowed::No;
3440 case LLVMContext::MD_dbg: {
3441 ++NumDebugAttachments;
3442 CheckDI(NumDebugAttachments == 1,
3443 "function must have a single !dbg attachment", &
F,
I.second);
3445 "function !dbg attachment must be a subprogram", &
F,
I.second);
3447 "function definition may only have a distinct !dbg attachment",
3451 const Function *&AttachedTo = DISubprogramAttachments[
SP];
3452 CheckDI(!AttachedTo || AttachedTo == &
F,
3453 "DISubprogram attached to more than one function", SP, &
F);
3455 AllowLocs = AreDebugLocsAllowed::Yes;
3458 case LLVMContext::MD_prof:
3459 ++NumProfAttachments;
3460 Check(NumProfAttachments == 1,
3461 "function must have a single !prof attachment", &
F,
I.second);
3463 case LLVMContext::MD_kcfi_type:
3464 ++NumKCFIAttachments;
3465 Check(NumKCFIAttachments == 1,
3466 "function must have a single !kcfi_type attachment", &
F,
3472 visitMDNode(*
I.second, AllowLocs);
3480 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
3482 if (
F.hasAddressTaken(&U,
false,
true,
false,
3484 Check(
false,
"Invalid user of intrinsic instruction!", U);
3488 switch (
F.getIntrinsicID()) {
3489 case Intrinsic::experimental_gc_get_pointer_base: {
3490 FunctionType *FT =
F.getFunctionType();
3491 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3493 "gc.get.pointer.base must return a pointer",
F);
3494 Check(FT->getParamType(0) ==
F.getReturnType(),
3495 "gc.get.pointer.base operand and result must be of the same type",
F);
3498 case Intrinsic::experimental_gc_get_pointer_offset: {
3499 FunctionType *FT =
F.getFunctionType();
3500 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
3502 "gc.get.pointer.offset operand must be a pointer",
F);
3503 Check(
F.getReturnType()->isIntegerTy(),
3504 "gc.get.pointer.offset must return integer",
F);
3509 auto *
N =
F.getSubprogram();
3510 HasDebugInfo = (
N !=
nullptr);
3518 SmallPtrSet<const MDNode *, 32> Seen;
3530 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
3532 DILocalScope *
Scope =
DL->getInlinedAtScope();
3533 Check(Scope,
"Failed to find DILocalScope",
DL);
3535 if (!Seen.
insert(Scope).second)
3538 DISubprogram *
SP =
Scope->getSubprogram();
3542 if ((Scope != SP) && !Seen.
insert(SP).second)
3546 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3550 for (
auto &
I : BB) {
3551 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3553 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3556 if (BrokenDebugInfo)
3563void Verifier::visitBasicBlock(BasicBlock &BB) {
3564 InstsInThisBlock.
clear();
3565 ConvergenceVerifyHelper.
visit(BB);
3576 for (
const PHINode &PN : BB.
phis()) {
3577 Check(PN.getNumIncomingValues() == Preds.size(),
3578 "PHINode should have one entry for each predecessor of its "
3579 "parent basic block!",
3584 Values.
reserve(PN.getNumIncomingValues());
3585 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3587 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3590 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3595 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3596 Values[i].second == Values[i - 1].second,
3597 "PHI node has multiple entries for the same basic block with "
3598 "different incoming values!",
3599 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3603 Check(Values[i].first == Preds[i],
3604 "PHI node entries do not match predecessors!", &PN,
3605 Values[i].first, Preds[i]);
3613 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3617 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3621void Verifier::visitTerminator(Instruction &
I) {
3623 Check(&
I ==
I.getParent()->getTerminator(),
3624 "Terminator found in the middle of a basic block!",
I.getParent());
3625 visitInstruction(
I);
3628void Verifier::visitCondBrInst(CondBrInst &BI) {
3630 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3631 visitTerminator(BI);
3634void Verifier::visitReturnInst(ReturnInst &RI) {
3637 if (
F->getReturnType()->isVoidTy())
3639 "Found return instr that returns non-void in Function of void "
3641 &RI,
F->getReturnType());
3644 "Function return type does not match operand "
3645 "type of return inst!",
3646 &RI,
F->getReturnType());
3650 visitTerminator(RI);
3653void Verifier::visitSwitchInst(SwitchInst &SI) {
3654 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3657 Type *SwitchTy =
SI.getCondition()->getType();
3658 SmallPtrSet<ConstantInt*, 32>
Constants;
3659 for (
auto &Case :
SI.cases()) {
3661 "Case value is not a constant integer.", &SI);
3662 Check(Case.getCaseValue()->getType() == SwitchTy,
3663 "Switch constants must all be same type as switch value!", &SI);
3665 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3668 visitTerminator(SI);
3671void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
3673 "Indirectbr operand must have pointer type!", &BI);
3676 "Indirectbr destinations must all have pointer type!", &BI);
3678 visitTerminator(BI);
3681void Verifier::visitCallBrInst(CallBrInst &CBI) {
3684 "Callbr: indirect function / invalid signature");
3686 "Callbr for intrinsics currently doesn't support operand bundles");
3689 case Intrinsic::amdgcn_kill: {
3691 "Callbr amdgcn_kill only supports one indirect dest");
3695 Intrinsic::amdgcn_unreachable),
3696 "Callbr amdgcn_kill indirect dest needs to be unreachable");
3701 "Callbr currently only supports asm-goto and selected intrinsics");
3706 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3708 verifyInlineAsmCall(CBI);
3710 visitTerminator(CBI);
3713void Verifier::visitSelectInst(SelectInst &SI) {
3716 "Invalid operands for select instruction!", &SI);
3718 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3719 "Select values must have same type as select instruction!", &SI);
3720 visitInstruction(SI);
3726void Verifier::visitUserOp1(Instruction &
I) {
3727 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3730void Verifier::visitTruncInst(TruncInst &
I) {
3732 Type *SrcTy =
I.getOperand(0)->getType();
3733 Type *DestTy =
I.getType();
3742 "trunc source and destination must both be a vector or neither", &
I);
3743 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3745 visitInstruction(
I);
3748void Verifier::visitZExtInst(ZExtInst &
I) {
3750 Type *SrcTy =
I.getOperand(0)->getType();
3751 Type *DestTy =
I.getType();
3757 "zext source and destination must both be a vector or neither", &
I);
3761 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3763 visitInstruction(
I);
3766void Verifier::visitSExtInst(SExtInst &
I) {
3768 Type *SrcTy =
I.getOperand(0)->getType();
3769 Type *DestTy =
I.getType();
3778 "sext source and destination must both be a vector or neither", &
I);
3779 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3781 visitInstruction(
I);
3784void Verifier::visitFPTruncInst(FPTruncInst &
I) {
3786 Type *SrcTy =
I.getOperand(0)->getType();
3787 Type *DestTy =
I.getType();
3795 "fptrunc source and destination must both be a vector or neither", &
I);
3796 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3798 visitInstruction(
I);
3801void Verifier::visitFPExtInst(FPExtInst &
I) {
3803 Type *SrcTy =
I.getOperand(0)->getType();
3804 Type *DestTy =
I.getType();
3813 "fpext source and destination must both be a vector or neither", &
I);
3814 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3816 visitInstruction(
I);
3819void Verifier::visitUIToFPInst(UIToFPInst &
I) {
3821 Type *SrcTy =
I.getOperand(0)->getType();
3822 Type *DestTy =
I.getType();
3827 Check(SrcVec == DstVec,
3828 "UIToFP source and dest must both be vector or scalar", &
I);
3830 "UIToFP source must be integer or integer vector", &
I);
3834 if (SrcVec && DstVec)
3837 "UIToFP source and dest vector length mismatch", &
I);
3839 visitInstruction(
I);
3842void Verifier::visitSIToFPInst(SIToFPInst &
I) {
3844 Type *SrcTy =
I.getOperand(0)->getType();
3845 Type *DestTy =
I.getType();
3850 Check(SrcVec == DstVec,
3851 "SIToFP source and dest must both be vector or scalar", &
I);
3853 "SIToFP source must be integer or integer vector", &
I);
3857 if (SrcVec && DstVec)
3860 "SIToFP source and dest vector length mismatch", &
I);
3862 visitInstruction(
I);
3865void Verifier::visitFPToUIInst(FPToUIInst &
I) {
3867 Type *SrcTy =
I.getOperand(0)->getType();
3868 Type *DestTy =
I.getType();
3873 Check(SrcVec == DstVec,
3874 "FPToUI source and dest must both be vector or scalar", &
I);
3877 "FPToUI result must be integer or integer vector", &
I);
3879 if (SrcVec && DstVec)
3882 "FPToUI source and dest vector length mismatch", &
I);
3884 visitInstruction(
I);
3887void Verifier::visitFPToSIInst(FPToSIInst &
I) {
3889 Type *SrcTy =
I.getOperand(0)->getType();
3890 Type *DestTy =
I.getType();
3895 Check(SrcVec == DstVec,
3896 "FPToSI source and dest must both be vector or scalar", &
I);
3899 "FPToSI result must be integer or integer vector", &
I);
3901 if (SrcVec && DstVec)
3904 "FPToSI source and dest vector length mismatch", &
I);
3906 visitInstruction(
I);
3909void Verifier::checkPtrToAddr(
Type *SrcTy,
Type *DestTy,
const Value &V) {
3918 Check(VSrc->getElementCount() == VDest->getElementCount(),
3919 "PtrToAddr vector length mismatch", V);
3922 Type *AddrTy =
DL.getAddressType(SrcTy);
3923 Check(AddrTy == DestTy,
"PtrToAddr result must be address width", V);
3926void Verifier::visitPtrToAddrInst(PtrToAddrInst &
I) {
3927 checkPtrToAddr(
I.getOperand(0)->getType(),
I.getType(),
I);
3928 visitInstruction(
I);
3931void Verifier::visitPtrToIntInst(PtrToIntInst &
I) {
3933 Type *SrcTy =
I.getOperand(0)->getType();
3934 Type *DestTy =
I.getType();
3945 Check(VSrc->getElementCount() == VDest->getElementCount(),
3946 "PtrToInt Vector length mismatch", &
I);
3949 visitInstruction(
I);
3952void Verifier::visitIntToPtrInst(IntToPtrInst &
I) {
3954 Type *SrcTy =
I.getOperand(0)->getType();
3955 Type *DestTy =
I.getType();
3965 Check(VSrc->getElementCount() == VDest->getElementCount(),
3966 "IntToPtr Vector length mismatch", &
I);
3968 visitInstruction(
I);
3971void Verifier::visitBitCastInst(BitCastInst &
I) {
3974 "Invalid bitcast", &
I);
3975 visitInstruction(
I);
3978void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &
I) {
3979 Type *SrcTy =
I.getOperand(0)->getType();
3980 Type *DestTy =
I.getType();
3987 "AddrSpaceCast must be between different address spaces", &
I);
3989 Check(SrcVTy->getElementCount() ==
3991 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3992 visitInstruction(
I);
3997void Verifier::visitPHINode(PHINode &PN) {
4004 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
4013 "PHI node operands are not the same type as the result!", &PN);
4018 visitInstruction(PN);
4021void Verifier::visitCallBase(CallBase &
Call) {
4023 "Called function must be a pointer!",
Call);
4027 if (FTy->isVarArg())
4029 "Called function requires more parameters than were provided!",
Call);
4032 "Incorrect number of arguments passed to called function!",
Call);
4035 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
4037 "Call parameter type does not match function signature!",
4043 "Attribute after last parameter!",
Call);
4050 "Intrinsic called with incompatible signature",
Call);
4054 "calling convention does not permit calls",
Call);
4060 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
4063 Align ABIAlign =
DL.getABITypeAlign(Ty);
4064 Check(ABIAlign.
value() <= Value::MaximumAlignment,
4065 "Incorrect alignment of " + Message +
" to called function!",
Call);
4069 VerifyTypeAlign(FTy->getReturnType(),
"return type");
4070 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
4071 Type *Ty = FTy->getParamType(i);
4072 VerifyTypeAlign(Ty,
"argument passed");
4076 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
4080 "speculatable attribute may not apply to call sites",
Call);
4083 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
4085 "preallocated as a call site attribute can only be on "
4086 "llvm.call.preallocated.arg");
4089 Check(!
Attrs.hasFnAttr(Attribute::DenormalFPEnv),
4090 "denormal_fpenv attribute may not apply to call sites",
Call);
4101 Check(AI->isUsedWithInAlloca(),
4102 "inalloca argument for call has mismatched alloca", AI,
Call);
4108 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
4112 Check(AI->isSwiftError(),
4113 "swifterror argument for call has mismatched alloca", AI,
Call);
4117 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
4118 SwiftErrorArg,
Call);
4119 Check(ArgI->hasSwiftErrorAttr(),
4120 "swifterror argument for call has mismatched parameter", ArgI,
4124 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
4127 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
4136 "immarg operand has non-immediate parameter", ArgVal,
Call);
4142 const ConstantRange &CR =
4145 "immarg value " + Twine(CI->getValue().getSExtValue()) +
4158 Check(hasOB != isMustTail,
4159 "preallocated operand either requires a preallocated bundle or "
4160 "the call to be musttail (but not both)",
4165 if (FTy->isVarArg()) {
4167 bool SawNest =
false;
4168 bool SawReturned =
false;
4170 for (
unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
4171 if (
Attrs.hasParamAttr(Idx, Attribute::Nest))
4173 if (
Attrs.hasParamAttr(Idx, Attribute::Returned))
4178 for (
unsigned Idx = FTy->getNumParams(); Idx <
Call.
arg_size(); ++Idx) {
4180 AttributeSet ArgAttrs =
Attrs.getParamAttrs(Idx);
4181 verifyParameterAttrs(ArgAttrs, Ty, &
Call);
4184 Check(!SawNest,
"More than one parameter has attribute nest!",
Call);
4189 Check(!SawReturned,
"More than one parameter has attribute returned!",
4192 "Incompatible argument and return types for 'returned' "
4202 "Attribute 'sret' cannot be used for vararg call arguments!",
4207 "inalloca isn't on the last argument!",
Call);
4213 for (
Type *ParamTy : FTy->params()) {
4214 Check(!ParamTy->isMetadataTy(),
4215 "Function has metadata parameter but isn't an intrinsic",
Call);
4216 Check(!ParamTy->isTokenLikeTy(),
4217 "Function has token parameter but isn't an intrinsic",
Call);
4223 Check(!FTy->getReturnType()->isTokenLikeTy(),
4224 "Return type cannot be token for indirect call!");
4225 Check(!FTy->getReturnType()->isX86_AMXTy(),
4226 "Return type cannot be x86_amx for indirect call!");
4230 visitIntrinsicCall(
ID,
Call);
4235 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
4236 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
4237 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
4238 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
4239 FoundAttachedCallBundle =
false;
4244 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles",
Call);
4245 FoundDeoptBundle =
true;
4247 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
4249 FoundGCTransitionBundle =
true;
4251 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles",
Call);
4252 FoundFuncletBundle =
true;
4254 "Expected exactly one funclet bundle operand",
Call);
4256 "Funclet bundle operands should correspond to a FuncletPadInst",
4259 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
4261 FoundCFGuardTargetBundle =
true;
4263 "Expected exactly one cfguardtarget bundle operand",
Call);
4265 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles",
Call);
4266 FoundPtrauthBundle =
true;
4268 "Expected exactly two ptrauth bundle operands",
Call);
4270 BU.
Inputs[0]->getType()->isIntegerTy(32),
4271 "Ptrauth bundle key operand must be an i32 constant",
Call);
4273 "Ptrauth bundle discriminator operand must be an i64",
Call);
4275 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles",
Call);
4276 FoundKCFIBundle =
true;
4277 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
4280 BU.
Inputs[0]->getType()->isIntegerTy(32),
4281 "Kcfi bundle operand must be an i32 constant",
Call);
4283 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
4285 FoundPreallocatedBundle =
true;
4287 "Expected exactly one preallocated bundle operand",
Call);
4290 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
4291 "\"preallocated\" argument must be a token from "
4292 "llvm.call.preallocated.setup",
4295 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles",
Call);
4296 FoundGCLiveBundle =
true;
4298 Check(!FoundAttachedCallBundle,
4299 "Multiple \"clang.arc.attachedcall\" operand bundles",
Call);
4300 FoundAttachedCallBundle =
true;
4301 verifyAttachedCallBundle(
Call, BU);
4307 "Direct call cannot have a ptrauth bundle",
Call);
4319 "inlinable function call in a function with "
4320 "debug info must have a !dbg location",
4324 verifyInlineAsmCall(
Call);
4328 visitInstruction(
Call);
4331void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
4334 Twine(
"inalloca attribute not allowed in ") +
Context);
4336 Twine(
"inreg attribute not allowed in ") +
Context);
4337 Check(!
Attrs.contains(Attribute::SwiftError),
4338 Twine(
"swifterror attribute not allowed in ") +
Context);
4339 Check(!
Attrs.contains(Attribute::Preallocated),
4340 Twine(
"preallocated attribute not allowed in ") +
Context);
4342 Twine(
"byref attribute not allowed in ") +
Context);
4347 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
4348 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
4349 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
4351 AttrBuilder Copy(
C);
4352 for (
auto AK : ABIAttrs) {
4353 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
4355 Copy.addAttribute(Attr);
4359 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
4360 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
4361 Attrs.hasParamAttr(
I, Attribute::ByRef)))
4362 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
4366void Verifier::verifyMustTailCall(CallInst &CI) {
4370 FunctionType *CallerTy =
F->getFunctionType();
4372 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
4373 "cannot guarantee tail call due to mismatched varargs", &CI);
4374 Check(CallerTy->getReturnType() == CalleeTy->getReturnType(),
4375 "cannot guarantee tail call due to mismatched return types", &CI);
4379 "cannot guarantee tail call due to mismatched calling conv", &CI);
4387 Check(Ret,
"musttail call must precede a ret", &CI);
4390 "musttail call result must be returned", Ret);
4392 AttributeList CallerAttrs =
F->getAttributes();
4397 CI.
getCallingConv() == CallingConv::Tail ?
"tailcc" :
"swifttailcc";
4401 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4403 SmallString<32>
Context{CCName, StringRef(
" musttail caller")};
4404 verifyTailCCMustTailAttrs(ABIAttrs,
Context);
4406 for (
unsigned I = 0,
E = CalleeTy->getNumParams();
I !=
E; ++
I) {
4408 SmallString<32>
Context{CCName, StringRef(
" musttail callee")};
4409 verifyTailCCMustTailAttrs(ABIAttrs,
Context);
4412 Check(!CallerTy->isVarArg(), Twine(
"cannot guarantee ") + CCName +
4413 " tail call for varargs function");
4419 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
4420 "cannot guarantee tail call due to mismatched parameter counts", &CI);
4421 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4422 Check(CallerTy->getParamType(
I) == CalleeTy->getParamType(
I),
4423 "cannot guarantee tail call due to mismatched parameter types",
4430 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
4433 Check(CallerABIAttrs == CalleeABIAttrs,
4434 "cannot guarantee tail call due to mismatched ABI impacting "
4435 "function attributes",
4440void Verifier::visitCallInst(CallInst &CI) {
4444 verifyMustTailCall(CI);
4447void Verifier::visitInvokeInst(InvokeInst &
II) {
4453 II.getUnwindDest()->isEHPad(),
4454 "The unwind destination does not have an exception handling instruction!",
4457 visitTerminator(
II);
4462void Verifier::visitUnaryOperator(UnaryOperator &U) {
4463 Check(
U.getType() ==
U.getOperand(0)->getType(),
4464 "Unary operators must have same type for"
4465 "operands and result!",
4468 switch (
U.getOpcode()) {
4471 case Instruction::FNeg:
4472 Check(
U.getType()->isFPOrFPVectorTy(),
4473 "FNeg operator only works with float types!", &U);
4479 visitInstruction(U);
4485void Verifier::visitBinaryOperator(BinaryOperator &
B) {
4486 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
4487 "Both operands to a binary operator are not of the same type!", &
B);
4489 switch (
B.getOpcode()) {
4492 case Instruction::Add:
4493 case Instruction::Sub:
4494 case Instruction::Mul:
4495 case Instruction::SDiv:
4496 case Instruction::UDiv:
4497 case Instruction::SRem:
4498 case Instruction::URem:
4499 Check(
B.getType()->isIntOrIntVectorTy(),
4500 "Integer arithmetic operators only work with integral types!", &
B);
4501 Check(
B.getType() ==
B.getOperand(0)->getType(),
4502 "Integer arithmetic operators must have same type "
4503 "for operands and result!",
4508 case Instruction::FAdd:
4509 case Instruction::FSub:
4510 case Instruction::FMul:
4511 case Instruction::FDiv:
4512 case Instruction::FRem:
4513 Check(
B.getType()->isFPOrFPVectorTy(),
4514 "Floating-point arithmetic operators only work with "
4515 "floating-point types!",
4517 Check(
B.getType() ==
B.getOperand(0)->getType(),
4518 "Floating-point arithmetic operators must have same type "
4519 "for operands and result!",
4523 case Instruction::And:
4524 case Instruction::Or:
4525 case Instruction::Xor:
4526 Check(
B.getType()->isIntOrIntVectorTy(),
4527 "Logical operators only work with integral types!", &
B);
4528 Check(
B.getType() ==
B.getOperand(0)->getType(),
4529 "Logical operators must have same type for operands and result!", &
B);
4531 case Instruction::Shl:
4532 case Instruction::LShr:
4533 case Instruction::AShr:
4534 Check(
B.getType()->isIntOrIntVectorTy(),
4535 "Shifts only work with integral types!", &
B);
4536 Check(
B.getType() ==
B.getOperand(0)->getType(),
4537 "Shift return type must be same as operands!", &
B);
4543 visitInstruction(
B);
4546void Verifier::visitICmpInst(ICmpInst &IC) {
4550 Check(Op0Ty == Op1Ty,
4551 "Both operands to ICmp instruction are not of the same type!", &IC);
4554 "Invalid operand types for ICmp instruction", &IC);
4558 visitInstruction(IC);
4561void Verifier::visitFCmpInst(FCmpInst &FC) {
4563 Type *Op0Ty =
FC.getOperand(0)->getType();
4564 Type *Op1Ty =
FC.getOperand(1)->getType();
4565 Check(Op0Ty == Op1Ty,
4566 "Both operands to FCmp instruction are not of the same type!", &FC);
4571 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4573 visitInstruction(FC);
4576void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
4578 "Invalid extractelement operands!", &EI);
4579 visitInstruction(EI);
4582void Verifier::visitInsertElementInst(InsertElementInst &IE) {
4585 "Invalid insertelement operands!", &IE);
4586 visitInstruction(IE);
4589void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
4592 "Invalid shufflevector operands!", &SV);
4593 visitInstruction(SV);
4596void Verifier::visitGetElementPtrInst(GetElementPtrInst &
GEP) {
4598 GEP.getModule()->getModuleFlag(
"require-logical-pointer")))
4599 Check(!MD->getZExtValue(),
4600 "Non-logical getelementptr disallowed for this module.");
4602 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4605 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4606 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4610 "getelementptr cannot target structure that contains scalable vector"
4615 SmallVector<Value *, 16> Idxs(
GEP.indices());
4617 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4618 "GEP indexes must be integers", &
GEP);
4621 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4625 Check(PtrTy &&
GEP.getResultElementType() == ElTy,
4626 "GEP is not of right type for indices!", &
GEP, ElTy);
4630 ElementCount GEPWidth = GEPVTy->getElementCount();
4631 if (
GEP.getPointerOperandType()->isVectorTy())
4635 "Vector GEP result width doesn't match operand's", &
GEP);
4636 for (
Value *Idx : Idxs) {
4637 Type *IndexTy = Idx->getType();
4639 ElementCount IndexWidth = IndexVTy->getElementCount();
4640 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4643 "All GEP indices should be of integer type");
4650 GTI != GTE; ++GTI) {
4651 if (GTI.isVector()) {
4652 Type *ElemTy = GTI.getIndexedType();
4653 Check(
DL.typeSizeEqualsStoreSize(ElemTy),
4654 "GEP into vector with non-byte-addressable element type", &
GEP);
4658 Check(
GEP.getAddressSpace() == PtrTy->getAddressSpace(),
4659 "GEP address space doesn't match type", &
GEP);
4661 visitInstruction(
GEP);
4665 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4670void Verifier::verifyRangeLikeMetadata(
const Value &
I,
const MDNode *
Range,
4671 Type *Ty, RangeLikeMetadataKind Kind) {
4672 unsigned NumOperands =
Range->getNumOperands();
4673 Check(NumOperands % 2 == 0,
"Unfinished range!",
Range);
4674 unsigned NumRanges = NumOperands / 2;
4675 Check(NumRanges >= 1,
"It should have at least one range!",
Range);
4677 ConstantRange LastRange(1,
true);
4678 for (
unsigned i = 0; i < NumRanges; ++i) {
4681 Check(
Low,
"The lower limit must be an integer!",
Low);
4686 Check(
High->getType() ==
Low->getType(),
"Range pair types must match!",
4689 if (Kind == RangeLikeMetadataKind::NoaliasAddrspace) {
4691 "noalias.addrspace type must be i32!", &
I);
4694 "Range types must match instruction type!", &
I);
4697 APInt HighV =
High->getValue();
4698 APInt LowV =
Low->getValue();
4703 "The upper and lower limits cannot be the same value", &
I);
4705 ConstantRange CurRange(LowV, HighV);
4706 Check(!CurRange.isEmptySet() &&
4707 (Kind == RangeLikeMetadataKind::AbsoluteSymbol ||
4708 !CurRange.isFullSet()),
4709 "Range must not be empty!",
Range);
4711 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4712 "Intervals are overlapping",
Range);
4713 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4718 LastRange = ConstantRange(LowV, HighV);
4720 if (NumRanges > 2) {
4725 ConstantRange FirstRange(FirstLow, FirstHigh);
4726 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4727 "Intervals are overlapping",
Range);
4733void Verifier::visitRangeMetadata(Instruction &
I, MDNode *
Range,
Type *Ty) {
4735 "precondition violation");
4736 verifyRangeLikeMetadata(
I,
Range, Ty, RangeLikeMetadataKind::Range);
4739void Verifier::visitNoFPClassMetadata(Instruction &
I, MDNode *NoFPClass,
4741 Check(AttributeFuncs::isNoFPClassCompatibleType(Ty),
4742 "nofpclass only applies to floating-point typed loads",
I);
4745 "nofpclass must have exactly one entry", NoFPClass);
4746 ConstantInt *MaskVal =
4749 "nofpclass entry must be a constant i32", NoFPClass);
4751 Check(Val != 0,
"'nofpclass' must have at least one test bit set", NoFPClass,
4755 "Invalid value for 'nofpclass' test mask", NoFPClass,
I);
4758void Verifier::visitNoaliasAddrspaceMetadata(Instruction &
I, MDNode *
Range,
4761 "precondition violation");
4762 verifyRangeLikeMetadata(
I,
Range, Ty,
4763 RangeLikeMetadataKind::NoaliasAddrspace);
4766void Verifier::checkAtomicMemAccessSize(
Type *Ty,
const Instruction *
I) {
4767 unsigned Size =
DL.getTypeSizeInBits(Ty).getFixedValue();
4768 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4770 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4773void Verifier::visitLoadInst(LoadInst &LI) {
4775 Check(PTy,
"Load operand must be a pointer.", &LI);
4778 Check(
A->value() <= Value::MaximumAlignment,
4779 "huge alignment values are unsupported", &LI);
4781 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4784 LI.
getOrdering() != AtomicOrdering::AcquireRelease,
4785 "Load cannot have Release ordering", &LI);
4789 "atomic load operand must have integer, byte, pointer, floating "
4790 "point, or vector type!",
4793 checkAtomicMemAccessSize(ElTy, &LI);
4796 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4799 visitInstruction(LI);
4802void Verifier::visitStoreInst(StoreInst &SI) {
4804 Check(PTy,
"Store operand must be a pointer.", &SI);
4805 Type *ElTy =
SI.getOperand(0)->getType();
4806 if (MaybeAlign
A =
SI.getAlign()) {
4807 Check(
A->value() <= Value::MaximumAlignment,
4808 "huge alignment values are unsupported", &SI);
4810 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4811 if (
SI.isAtomic()) {
4812 Check(
SI.getOrdering() != AtomicOrdering::Acquire &&
4813 SI.getOrdering() != AtomicOrdering::AcquireRelease,
4814 "Store cannot have Acquire ordering", &SI);
4818 "atomic store operand must have integer, byte, pointer, floating "
4819 "point, or vector type!",
4821 checkAtomicMemAccessSize(ElTy, &SI);
4824 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4826 visitInstruction(SI);
4830void Verifier::verifySwiftErrorCall(CallBase &
Call,
4831 const Value *SwiftErrorVal) {
4833 if (
I.value() == SwiftErrorVal) {
4835 "swifterror value when used in a callsite should be marked "
4836 "with swifterror attribute",
4837 SwiftErrorVal,
Call);
4842void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4845 for (
const User *U : SwiftErrorVal->
users()) {
4848 "swifterror value can only be loaded and stored from, or "
4849 "as a swifterror argument!",
4853 Check(StoreI->getOperand(1) == SwiftErrorVal,
4854 "swifterror value should be the second operand when used "
4858 verifySwiftErrorCall(*
const_cast<CallBase *
>(
Call), SwiftErrorVal);
4862void Verifier::visitAllocaInst(AllocaInst &AI) {
4865 Check(!MD->getZExtValue(),
4866 "Non-logical alloca disallowed for this module.");
4869 SmallPtrSet<Type*, 4> Visited;
4870 Check(Ty->
isSized(&Visited),
"Cannot allocate unsized type", &AI);
4874 "Alloca has illegal target extension type", &AI);
4876 "Alloca array size must have integer type", &AI);
4878 Check(
A->value() <= Value::MaximumAlignment,
4879 "huge alignment values are unsupported", &AI);
4885 "swifterror alloca must not be array allocation", &AI);
4886 verifySwiftErrorValue(&AI);
4889 if (
TT.isAMDGPU()) {
4891 "alloca on amdgpu must be in addrspace(5)", &AI);
4894 visitInstruction(AI);
4897void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
4900 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4901 checkAtomicMemAccessSize(ElTy, &CXI);
4902 visitInstruction(CXI);
4905void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
4907 "atomicrmw instructions cannot be unordered.", &RMWI);
4910 Type *ScalarTy = ElTy;
4913 Check(VecTy,
"atomicrmw elementwise operand must have fixed vector type!",
4916 ScalarTy = VecTy->getElementType();
4923 " operand must have integer or floating point type!",
4928 " operand must have floating-point or fixed vector of "
4935 " operand must have integer type!",
4938 checkAtomicMemAccessSize(ElTy, &RMWI);
4940 "Invalid binary operation!", &RMWI);
4941 visitInstruction(RMWI);
4944void Verifier::visitFenceInst(FenceInst &FI) {
4946 Check(Ordering == AtomicOrdering::Acquire ||
4947 Ordering == AtomicOrdering::Release ||
4948 Ordering == AtomicOrdering::AcquireRelease ||
4949 Ordering == AtomicOrdering::SequentiallyConsistent,
4950 "fence instructions may only have acquire, release, acq_rel, or "
4951 "seq_cst ordering.",
4953 visitInstruction(FI);
4956void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
4959 "Invalid ExtractValueInst operands!", &EVI);
4961 visitInstruction(EVI);
4964void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
4968 "Invalid InsertValueInst operands!", &IVI);
4970 visitInstruction(IVI);
4975 return FPI->getParentPad();
4980void Verifier::visitEHPadPredecessors(Instruction &
I) {
4986 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4994 Check(
II &&
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4995 "Block containing LandingPadInst must be jumped to "
4996 "only by the unwind edge of an invoke.",
5004 "Block containg CatchPadInst must be jumped to "
5005 "only by its catchswitch.",
5007 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
5008 "Catchswitch cannot unwind to one of its catchpads",
5009 CPI->getCatchSwitch(), CPI);
5021 Check(
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
5022 "EH pad must be jumped to via an unwind edge", ToPad,
II);
5025 if (CalledFn && CalledFn->isIntrinsic() &&
II->doesNotThrow() &&
5029 FromPad = Bundle->Inputs[0];
5033 FromPad = CRI->getOperand(0);
5034 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
5038 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
5042 SmallPtrSet<Value *, 8> Seen;
5044 Check(FromPad != ToPad,
5045 "EH pad cannot handle exceptions raised within it", FromPad, TI);
5046 if (FromPad == ToPadParent) {
5051 "A single unwind edge may only enter one EH pad", TI);
5052 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
5058 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
5063void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
5067 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
5069 visitEHPadPredecessors(LPI);
5071 if (!LandingPadResultTy)
5072 LandingPadResultTy = LPI.
getType();
5075 "The landingpad instruction should have a consistent result type "
5076 "inside a function.",
5080 Check(
F->hasPersonalityFn(),
5081 "LandingPadInst needs to be in a function with a personality.", &LPI);
5086 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
5092 "Catch operand does not have pointer type!", &LPI);
5094 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
5096 "Filter operand is not an array of constants!", &LPI);
5100 visitInstruction(LPI);
5103void Verifier::visitResumeInst(ResumeInst &RI) {
5105 "ResumeInst needs to be in a function with a personality.", &RI);
5107 if (!LandingPadResultTy)
5111 "The resume instruction should have a consistent result type "
5112 "inside a function.",
5115 visitTerminator(RI);
5118void Verifier::visitCatchPadInst(CatchPadInst &CPI) {
5122 Check(
F->hasPersonalityFn(),
5123 "CatchPadInst needs to be in a function with a personality.", &CPI);
5126 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
5132 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
5137 return isa<Constant>(V) || isa<AllocaInst>(V);
5139 "Argument operand must be alloca or constant.", &CPI);
5141 visitEHPadPredecessors(CPI);
5142 visitFuncletPadInst(CPI);
5145void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) {
5147 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
5150 visitTerminator(CatchReturn);
5153void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) {
5157 Check(
F->hasPersonalityFn(),
5158 "CleanupPadInst needs to be in a function with a personality.", &CPI);
5163 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
5167 "CleanupPadInst has an invalid parent.", &CPI);
5169 visitEHPadPredecessors(CPI);
5170 visitFuncletPadInst(CPI);
5173void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) {
5174 User *FirstUser =
nullptr;
5175 Value *FirstUnwindPad =
nullptr;
5177 SmallPtrSet<FuncletPadInst *, 8> Seen;
5179 while (!Worklist.empty()) {
5180 FuncletPadInst *CurrentPad = Worklist.pop_back_val();
5182 "FuncletPadInst must not be nested within itself", CurrentPad);
5183 Value *UnresolvedAncestorPad =
nullptr;
5184 for (User *U : CurrentPad->
users()) {
5187 UnwindDest = CRI->getUnwindDest();
5193 if (CSI->unwindsToCaller())
5195 UnwindDest = CSI->getUnwindDest();
5197 UnwindDest =
II->getUnwindDest();
5207 Worklist.push_back(CPI);
5222 if (UnwindParent == CurrentPad)
5228 Value *ExitedPad = CurrentPad;
5231 if (ExitedPad == &FPI) {
5236 UnresolvedAncestorPad = &FPI;
5240 if (ExitedParent == UnwindParent) {
5244 UnresolvedAncestorPad = ExitedParent;
5247 ExitedPad = ExitedParent;
5253 UnresolvedAncestorPad = &FPI;
5260 Check(UnwindPad == FirstUnwindPad,
5261 "Unwind edges out of a funclet "
5262 "pad must have the same unwind "
5264 &FPI, U, FirstUser);
5267 FirstUnwindPad = UnwindPad;
5276 if (CurrentPad != &FPI)
5279 if (UnresolvedAncestorPad) {
5280 if (CurrentPad == UnresolvedAncestorPad) {
5284 assert(CurrentPad == &FPI);
5292 Value *ResolvedPad = CurrentPad;
5293 while (!Worklist.empty()) {
5294 Value *UnclePad = Worklist.back();
5298 while (ResolvedPad != AncestorPad) {
5300 if (ResolvedParent == UnresolvedAncestorPad) {
5303 ResolvedPad = ResolvedParent;
5307 if (ResolvedPad != AncestorPad)
5310 Worklist.pop_back();
5315 if (FirstUnwindPad) {
5317 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
5318 Value *SwitchUnwindPad;
5319 if (SwitchUnwindDest)
5323 Check(SwitchUnwindPad == FirstUnwindPad,
5324 "Unwind edges out of a catch must have the same unwind dest as "
5325 "the parent catchswitch",
5326 &FPI, FirstUser, CatchSwitch);
5330 visitInstruction(FPI);
5333void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) {
5337 Check(
F->hasPersonalityFn(),
5338 "CatchSwitchInst needs to be in a function with a personality.",
5344 "CatchSwitchInst not the first non-PHI instruction in the block.",
5349 "CatchSwitchInst has an invalid parent.", ParentPad);
5354 "CatchSwitchInst must unwind to an EH block which is not a "
5360 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
5364 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
5366 for (BasicBlock *Handler : CatchSwitch.
handlers()) {
5368 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
5371 visitEHPadPredecessors(CatchSwitch);
5372 visitTerminator(CatchSwitch);
5375void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) {
5377 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
5383 "CleanupReturnInst must unwind to an EH block which is not a "
5388 visitTerminator(CRI);
5391void Verifier::verifyDominatesUse(Instruction &
I,
unsigned i) {
5397 if (
II->getNormalDest() ==
II->getUnwindDest())
5411 const Use &
U =
I.getOperandUse(i);
5412 Check(DT.dominates(
Op, U),
"Instruction does not dominate all uses!",
Op, &
I);
5415void Verifier::visitDereferenceableMetadata(Instruction&
I, MDNode* MD) {
5416 Check(
I.getType()->isPointerTy(),
5417 "dereferenceable, dereferenceable_or_null "
5418 "apply only to pointer types",
5421 "dereferenceable, dereferenceable_or_null apply only to load"
5422 " and inttoptr instructions, use attributes for calls or invokes",
5425 "dereferenceable, dereferenceable_or_null "
5426 "take one operand!",
5431 "dereferenceable_or_null metadata value must be an i64!",
5435void Verifier::visitNofreeMetadata(Instruction &
I, MDNode *MD) {
5436 Check(
I.getType()->isPointerTy(),
"nofree applies only to pointer types", &
I);
5442void Verifier::visitProfMetadata(Instruction &
I, MDNode *MD) {
5443 auto GetBranchingTerminatorNumOperands = [&]() {
5444 unsigned ExpectedNumOperands = 0;
5448 ExpectedNumOperands =
SI->getNumSuccessors();
5450 ExpectedNumOperands = 1;
5452 ExpectedNumOperands = IBI->getNumDestinations();
5454 ExpectedNumOperands = 2;
5457 return ExpectedNumOperands;
5460 "!prof annotations should have at least 1 operand", MD);
5462 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
5464 "expected string with name of the !prof annotation", MD);
5470 "'unknown' !prof should only appear on instructions on which "
5471 "'branch_weights' would",
5473 verifyUnknownProfileMetadata(MD);
5478 "!prof annotations should have no less than 2 operands", MD);
5484 Check(NumBranchWeights == 1 || NumBranchWeights == 2,
5485 "Wrong number of InvokeInst branch_weights operands", MD);
5487 const unsigned ExpectedNumOperands = GetBranchingTerminatorNumOperands();
5488 if (ExpectedNumOperands == 0)
5489 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
5492 Check(NumBranchWeights == ExpectedNumOperands,
"Wrong number of operands",
5498 Check(MDO,
"second operand should not be null", MD);
5500 "!prof brunch_weights operand is not a const int");
5505 Check(KindInt,
"VP !prof missing kind argument", MD);
5508 Check(Kind >= InstrProfValueKind::IPVK_First &&
5509 Kind <= InstrProfValueKind::IPVK_Last,
5510 "Invalid VP !prof kind", MD);
5512 "VP !prof should have an even number "
5513 "of arguments after 'VP'",
5515 if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget ||
5516 Kind == InstrProfValueKind::IPVK_MemOPSize)
5518 "VP !prof indirect call or memop size expected to be applied to "
5519 "CallBase instructions only",
5522 DenseSet<uint64_t> ProfileValues;
5524 ConstantInt *ProfileValue =
5526 Check(ProfileValue,
"VP !prof value operand is not a const int", MD);
5527 uint64_t ProfileValueInt = ProfileValue->
getZExtValue();
5528 auto [ValueIt,
Inserted] = ProfileValues.
insert(ProfileValueInt);
5529 Check(Inserted,
"VP !prof should not have duplicate profile values", MD);
5532 CheckFailed(
"expected either branch_weights or VP profile name", MD);
5536void Verifier::visitDIAssignIDMetadata(Instruction &
I, MDNode *MD) {
5537 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
5542 bool ExpectedInstTy =
5544 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
5549 for (
auto *User : AsValue->users()) {
5551 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
5555 CheckDI(DAI->getFunction() ==
I.getFunction(),
5556 "dbg.assign not in same function as inst", DAI, &
I);
5559 for (DbgVariableRecord *DVR :
5562 "!DIAssignID should only be used by Assign DVRs.", MD, DVR);
5563 CheckDI(DVR->getFunction() ==
I.getFunction(),
5564 "DVRAssign not in same function as inst", DVR, &
I);
5568void Verifier::visitMMRAMetadata(Instruction &
I, MDNode *MD) {
5570 "!mmra metadata attached to unexpected instruction kind",
I, MD);
5581 for (
const MDOperand &MDOp : MD->
operands())
5583 "!mmra metadata tuple operand is not an MMRA tag",
I, MDOp.get());
5586void Verifier::visitCallStackMetadata(MDNode *MD) {
5590 "call stack metadata should have at least 1 operand", MD);
5594 "call stack metadata operand should be constant integer",
Op);
5597void Verifier::visitMemProfMetadata(Instruction &
I, MDNode *MD) {
5600 "!memprof annotations should have at least 1 metadata operand "
5605 for (
auto &MIBOp : MD->
operands()) {
5611 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
5615 "!memprof MemInfoBlock first operand should not be null", MIB);
5617 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
5619 visitCallStackMetadata(StackMD);
5623 "!memprof MemInfoBlock second operand should be an MDString", MIB);
5628 Check(OpNode,
"Not all !memprof MemInfoBlock operands 2 to N are MDNode",
5631 "Not all !memprof MemInfoBlock operands 2 to N are MDNode with 2 "
5636 [](
const MDOperand &
Op) {
5637 return mdconst::hasa<ConstantInt>(Op);
5639 "Not all !memprof MemInfoBlock operands 2 to N are MDNode with "
5640 "ConstantInt operands",
5646void Verifier::visitCallsiteMetadata(Instruction &
I, MDNode *MD) {
5650 visitCallStackMetadata(MD);
5659void Verifier::visitCalleeTypeMetadata(Instruction &
I, MDNode *MD) {
5664 "The callee_type metadata must be a list of type metadata nodes",
Op);
5666 Check(TypeMD->getNumOperands() == 2,
5667 "Well-formed generalized type metadata must contain exactly two "
5672 "The first operand of type metadata for functions must be zero",
Op);
5673 Check(TypeMD->hasGeneralizedMDString(),
5674 "Only generalized type metadata can be part of the callee_type "
5680void Verifier::visitAnnotationMetadata(MDNode *Annotation) {
5683 "annotation must have at least one operand");
5685 bool TupleOfStrings =
5691 "operands must be a string or a tuple of strings");
5695void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
5700 "first scope operand must be self-referential or string", MD);
5703 "third scope operand must be string (if used)", MD);
5706 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
5708 unsigned NumDomainOps =
Domain->getNumOperands();
5709 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
5710 "domain must have one or two operands",
Domain);
5713 "first domain operand must be self-referential or string",
Domain);
5714 if (NumDomainOps == 2)
5716 "second domain operand must be string (if used)",
Domain);
5719void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
5722 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
5723 visitAliasScopeMetadata(OpMD);
5727void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
5728 auto IsValidAccessScope = [](
const MDNode *MD) {
5733 if (IsValidAccessScope(MD))
5739 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
5740 Check(IsValidAccessScope(OpMD),
5741 "Access scope list contains invalid access scope", MD);
5745void Verifier::visitCapturesMetadata(Instruction &
I,
const MDNode *Captures) {
5746 static const char *ValidArgs[] = {
"address_is_null",
"address",
5747 "read_provenance",
"provenance"};
5750 Check(SI,
"!captures metadata can only be applied to store instructions", &
I);
5751 Check(
SI->getValueOperand()->getType()->isPointerTy(),
5752 "!captures metadata can only be applied to store with value operand of "
5760 Check(Str,
"!captures metadata must be a list of strings", &
I);
5762 "invalid entry in !captures metadata", &
I, Str);
5766void Verifier::visitAllocTokenMetadata(Instruction &
I, MDNode *MD) {
5771 "expected integer constant", MD);
5774void Verifier::visitInlineHistoryMetadata(Instruction &
I, MDNode *MD) {
5783 ->stripPointerCastsAndAliases()),
5784 "!inline_history operands must be functions or null", MD);
5788void Verifier::visitMemCacheHintMetadata(Instruction &
I, MDNode *MD) {
5789 Check(
I.mayReadOrWriteMemory(),
5790 "!mem.cache_hint is only valid on memory operations", &
I);
5793 "!mem.cache_hint must have even number of operands "
5794 "(operand_no, hint_node pairs)",
5800 "!mem.cache_hint is not supported on non-intrinsic calls", &
I);
5802 unsigned NumOperands = CB ? CB->arg_size() :
I.getNumOperands();
5804 SmallDenseSet<unsigned, 4> SeenOperandNos;
5805 std::optional<uint64_t> LastOperandNo;
5811 "!mem.cache_hint must alternate between i32 operand numbers and "
5812 "metadata hint nodes",
5815 Check(OpNoCI->getValue().isNonNegative(),
5816 "!mem.cache_hint operand number must be non-negative", MD);
5818 uint64_t OperandNo = OpNoCI->getZExtValue();
5819 Check(OperandNo < NumOperands,
5820 "!mem.cache_hint operand number is out of range", &
I);
5823 CB ? CB->getArgOperand(OperandNo) :
I.getOperand(OperandNo);
5825 "!mem.cache_hint operand number must refer to a pointer operand", &
I);
5828 Check(Inserted,
"!mem.cache_hint contains duplicate operand number", MD);
5830 Check(!Inserted || !LastOperandNo || OperandNo > *LastOperandNo,
5831 "!mem.cache_hint operand numbers must be in increasing order", MD);
5832 LastOperandNo = OperandNo;
5836 "!mem.cache_hint must alternate between i32 operand numbers and "
5837 "metadata hint nodes",
5841 "!mem.cache_hint hint node must have even number of operands "
5842 "(key-value pairs)",
5845 StringSet<> SeenKeys;
5846 for (
unsigned K = 0;
K + 1 <
Node->getNumOperands();
K += 2) {
5848 Check(
Key,
"!mem.cache_hint key must be a string", Node);
5850 StringRef KeyStr =
Key->getString();
5852 "!mem.cache_hint hint node contains duplicate key", Node);
5857 "!mem.cache_hint value must be a string or integer", Node);
5864void Verifier::visitInstruction(Instruction &
I) {
5866 Check(BB,
"Instruction not embedded in basic block!", &
I);
5869 for (User *U :
I.users()) {
5870 Check(U != (User *)&
I || !DT.isReachableFromEntry(BB),
5871 "Only PHI nodes may reference their own value!", &
I);
5876 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
5877 "Instruction has a name, but provides a void value!", &
I);
5881 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
5882 "Instruction returns a non-scalar type!", &
I);
5887 "Invalid use of metadata!", &
I);
5892 for (Use &U :
I.uses()) {
5895 "Instruction referencing"
5896 " instruction not embedded in a basic block!",
5899 CheckFailed(
"Use of instruction is not an instruction!", U);
5908 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
5909 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
5913 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
5914 Check(
false,
"Instruction operands must be first-class values!", &
I);
5920 auto IsAttachedCallOperand = [](
Function *
F,
const CallBase *CBI,
5922 return CBI && CBI->isOperandBundleOfType(
5930 Check((!
F->isIntrinsic() ||
5931 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5932 IsAttachedCallOperand(
F, CBI, i)),
5933 "Cannot take the address of an intrinsic!", &
I);
5935 F->getIntrinsicID() == Intrinsic::donothing ||
5936 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5937 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5938 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5939 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5940 F->getIntrinsicID() == Intrinsic::coro_resume ||
5941 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5942 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5943 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5944 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5945 F->getIntrinsicID() ==
5946 Intrinsic::experimental_patchpoint_void ||
5947 F->getIntrinsicID() == Intrinsic::experimental_patchpoint ||
5948 F->getIntrinsicID() == Intrinsic::fake_use ||
5949 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5950 F->getIntrinsicID() == Intrinsic::wasm_throw ||
5951 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5952 IsAttachedCallOperand(
F, CBI, i),
5953 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5954 "statepoint, coro_resume, coro_destroy, clang.arc.attachedcall or "
5957 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5958 &M,
F,
F->getParent());
5961 "Referring to a basic block in another function!", &
I);
5964 "Referring to an argument in another function!", &
I);
5966 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5970 "Referring to an instruction in another function!", &
I);
5971 verifyDominatesUse(
I, i);
5973 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5974 "Cannot take the address of an inline asm!", &
I);
5976 visitConstantExprsRecursively(
C);
5980 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5982 "fpmath requires a floating point result!", &
I);
5984 if (ConstantFP *CFP0 =
5986 const APFloat &Accuracy = CFP0->getValueAPF();
5988 "fpmath accuracy must have float type", &
I);
5990 "fpmath accuracy not a positive number!", &
I);
5992 Check(
false,
"invalid fpmath accuracy!", &
I);
5996 if (MDNode *
Range =
I.getMetadata(LLVMContext::MD_range)) {
5998 "Ranges are only for loads, calls and invokes!", &
I);
5999 visitRangeMetadata(
I,
Range,
I.getType());
6002 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_nofpclass)) {
6004 visitNoFPClassMetadata(
I, MD,
I.getType());
6007 if (MDNode *
Range =
I.getMetadata(LLVMContext::MD_noalias_addrspace)) {
6010 "noalias.addrspace are only for memory operations!", &
I);
6011 visitNoaliasAddrspaceMetadata(
I,
Range,
I.getType());
6014 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
6016 "invariant.group metadata is only for loads and stores", &
I);
6019 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
6020 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
6023 "nonnull applies only to load instructions, use attributes"
6024 " for calls or invokes",
6029 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_noundef)) {
6034 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
6035 visitDereferenceableMetadata(
I, MD);
6037 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
6038 visitDereferenceableMetadata(
I, MD);
6040 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_nofree))
6041 visitNofreeMetadata(
I, MD);
6043 if (MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
6046 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
6047 visitAliasScopeListMetadata(MD);
6048 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
6049 visitAliasScopeListMetadata(MD);
6051 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
6052 visitAccessGroupMetadata(MD);
6054 if (MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
6055 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
6058 "align applies only to load instructions, "
6059 "use attributes for calls or invokes",
6061 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
6064 "align metadata value must be an i64!", &
I);
6068 Check(Align <= Value::MaximumAlignment,
6069 "alignment is larger that implementation defined limit", &
I);
6072 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
6073 visitProfMetadata(
I, MD);
6075 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
6076 visitMemProfMetadata(
I, MD);
6078 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
6079 visitCallsiteMetadata(
I, MD);
6081 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_callee_type))
6082 visitCalleeTypeMetadata(
I, MD);
6084 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
6085 visitDIAssignIDMetadata(
I, MD);
6087 if (MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
6088 visitMMRAMetadata(
I, MMRA);
6090 if (MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
6091 visitAnnotationMetadata(Annotation);
6093 if (MDNode *Captures =
I.getMetadata(LLVMContext::MD_captures))
6094 visitCapturesMetadata(
I, Captures);
6096 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_alloc_token))
6097 visitAllocTokenMetadata(
I, MD);
6099 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_inline_history))
6100 visitInlineHistoryMetadata(
I, MD);
6102 if (MDNode *MD =
I.getMetadata(LLVMContext::MD_mem_cache_hint))
6103 visitMemCacheHintMetadata(
I, MD);
6105 if (MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
6107 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
6110 if (
DL->getAtomGroup()) {
6111 CheckDI(
DL->getScope()->getSubprogram()->getKeyInstructionsEnabled(),
6112 "DbgLoc uses atomGroup but DISubprogram doesn't have Key "
6113 "Instructions enabled",
6114 DL,
DL->getScope()->getSubprogram());
6120 I.getAllMetadata(MDs);
6121 for (
auto Attachment : MDs) {
6122 unsigned Kind = Attachment.first;
6124 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
6125 ? AreDebugLocsAllowed::Yes
6126 : AreDebugLocsAllowed::
No;
6127 visitMDNode(*Attachment.second, AllowLocs);
6145 raw_string_ostream ErrOS(ErrMsg);
6148 Check(IsValid, ErrMsg, IF);
6154 const std::string ExpectedName =
6157 "Intrinsic name not mangled correctly for type arguments! "
6169 "const x86_amx is not allowed in argument!");
6175 case Intrinsic::assume: {
6179 "assume with operand bundles must have i1 true condition",
Call);
6185 auto GetTypeAt = [&](
unsigned Index) {
6186 return OBU.Inputs[
Index]->getType();
6191 CheckFailed(
"tags must be valid attribute names",
Call);
6193 case BundleAttr::Align:
6194 Check(OBU.Inputs.size() >= 2 && OBU.Inputs.size() <= 3,
6195 "alignment assumptions should have 2 or 3 arguments",
Call);
6198 Check(GetTypeAt(1)->isIntegerTy() &&
6199 GetTypeAt(1)->getIntegerBitWidth() <= 64,
6200 "second argument should be an integer with a maximum width of 64 "
6203 Check(OBU.Inputs.size() < 3 ||
6204 GetTypeAt(2)->isIntegerTy() &&
6205 GetTypeAt(2)->getIntegerBitWidth() <= 64,
6206 "third argument should be an integer with a maximum width of 64 "
6210 case BundleAttr::Cold:
6211 Check(OBU.Inputs.size() == 0,
6212 "cold assumptions should have no arguments",
Call);
6214 case BundleAttr::Dereferenceable:
6215 case BundleAttr::DereferenceableOrNull:
6216 Check(OBU.Inputs.size() == 2,
6217 "dereferenceable assumptions should have 2 arguments",
Call);
6220 Check(GetTypeAt(1)->isIntegerTy() &&
6221 GetTypeAt(1)->getIntegerBitWidth() <= 64,
6222 "second argument should be an integer with a maximum width of 64 "
6226 case BundleAttr::Ignore:
6228 case BundleAttr::NonNull:
6229 Check(OBU.Inputs.size() == 1,
6230 "nonnull assumptions should have 1 argument",
Call);
6234 case BundleAttr::NoUndef:
6235 Check(OBU.Inputs.size() == 1,
6236 "noundef assumptions should have 1 argument",
Call);
6238 case BundleAttr::SeparateStorage:
6239 Check(OBU.Inputs.size() == 2,
6240 "separate_storage assumptions should have 2 arguments",
Call);
6242 "arguments to separate_storage assumptions should be pointers",
6249 case Intrinsic::ucmp:
6250 case Intrinsic::scmp: {
6255 "result type must be at least 2 bits wide",
Call);
6257 bool IsDestTypeVector = DestTy->
isVectorTy();
6259 "ucmp/scmp argument and result types must both be either vector or "
6262 if (IsDestTypeVector) {
6265 Check(SrcVecLen == DestVecLen,
6266 "return type and arguments must have the same number of "
6272 case Intrinsic::coro_begin:
6273 case Intrinsic::coro_begin_custom_abi:
6275 "id argument of llvm.coro.begin must refer to coro.id");
6277 case Intrinsic::coro_id: {
6279 "align argument only accepts constants");
6282 "promise argument must refer to an alloca");
6287 "coro argument must refer to a function");
6291 if (BeforeCoroSplit)
6294 Check(!BeforeCoroEarly,
"cannot run CoroSplit before CoroEarly");
6297 "info argument of llvm.coro.id must refer to an initialized "
6301 "info argument of llvm.coro.id must refer to either a struct or "
6305 case Intrinsic::is_fpclass: {
6308 "unsupported bits for llvm.is.fpclass test mask");
6311 case Intrinsic::fptrunc_round: {
6316 MD = MAV->getMetadata();
6318 Check(MD !=
nullptr,
"missing rounding mode argument",
Call);
6321 (
"invalid value for llvm.fptrunc.round metadata operand"
6322 " (the operand should be a string)"),
6325 std::optional<RoundingMode> RoundMode =
6327 Check(RoundMode && *RoundMode != RoundingMode::Dynamic,
6328 "unsupported rounding mode argument",
Call);
6331 case Intrinsic::convert_to_arbitrary_fp: {
6339 "if floating-point operand is a vector, integer operand must also "
6342 Check(ValueVecTy->getElementCount() == IntVecTy->getElementCount(),
6343 "floating-point and integer vector operands must have the same "
6350 Check(InterpMAV,
"missing interpretation metadata operand",
Call);
6352 Check(InterpStr,
"interpretation metadata operand must be a string",
Call);
6353 StringRef Interp = InterpStr->getString();
6355 Check(!Interp.
empty(),
"interpretation metadata string must not be empty",
6360 "unsupported interpretation metadata string",
Call);
6364 Check(RoundingMAV,
"missing rounding mode metadata operand",
Call);
6366 Check(RoundingStr,
"rounding mode metadata operand must be a string",
Call);
6368 std::optional<RoundingMode>
RM =
6370 Check(RM && *RM != RoundingMode::Dynamic,
6371 "unsupported rounding mode argument",
Call);
6374 case Intrinsic::convert_from_arbitrary_fp: {
6382 "if floating-point operand is a vector, integer operand must also "
6385 Check(ValueVecTy->getElementCount() == IntVecTy->getElementCount(),
6386 "floating-point and integer vector operands must have the same "
6393 Check(InterpMAV,
"missing interpretation metadata operand",
Call);
6395 Check(InterpStr,
"interpretation metadata operand must be a string",
Call);
6396 StringRef Interp = InterpStr->getString();
6398 Check(!Interp.
empty(),
"interpretation metadata string must not be empty",
6403 "unsupported interpretation metadata string",
Call);
6406#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
6407#include "llvm/IR/VPIntrinsics.def"
6408#undef BEGIN_REGISTER_VP_INTRINSIC
6411#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
6412 case Intrinsic::INTRINSIC:
6413#include "llvm/IR/ConstrainedOps.def"
6417 case Intrinsic::dbg_declare:
6418 case Intrinsic::dbg_value:
6419 case Intrinsic::dbg_assign:
6420 case Intrinsic::dbg_label:
6427 case Intrinsic::memcpy:
6428 case Intrinsic::memcpy_inline:
6429 case Intrinsic::memmove:
6430 case Intrinsic::memset:
6431 case Intrinsic::memset_inline:
6433 case Intrinsic::experimental_memset_pattern: {
6435 Check(Memset->getValue()->getType()->isSized(),
6436 "unsized types cannot be used as memset patterns",
Call);
6439 case Intrinsic::memcpy_element_unordered_atomic:
6440 case Intrinsic::memmove_element_unordered_atomic:
6441 case Intrinsic::memset_element_unordered_atomic: {
6444 ConstantInt *ElementSizeCI =
6446 const APInt &ElementSizeVal = ElementSizeCI->
getValue();
6448 "element size of the element-wise atomic memory intrinsic "
6449 "must be a power of 2",
6452 auto IsValidAlignment = [&](MaybeAlign Alignment) {
6453 return Alignment && ElementSizeVal.
ule(Alignment->value());
6455 Check(IsValidAlignment(AMI->getDestAlign()),
6456 "incorrect alignment of the destination argument",
Call);
6458 Check(IsValidAlignment(AMT->getSourceAlign()),
6459 "incorrect alignment of the source argument",
Call);
6463 case Intrinsic::call_preallocated_setup: {
6465 bool FoundCall =
false;
6468 Check(UseCall !=
nullptr,
6469 "Uses of llvm.call.preallocated.setup must be calls");
6471 if (IID == Intrinsic::call_preallocated_arg) {
6473 Check(AllocArgIndex !=
nullptr,
6474 "llvm.call.preallocated.alloc arg index must be a constant");
6475 auto AllocArgIndexInt = AllocArgIndex->getValue();
6476 Check(AllocArgIndexInt.sge(0) &&
6477 AllocArgIndexInt.slt(NumArgs->getValue()),
6478 "llvm.call.preallocated.alloc arg index must be between 0 and "
6480 "llvm.call.preallocated.setup's argument count");
6481 }
else if (IID == Intrinsic::call_preallocated_teardown) {
6484 Check(!FoundCall,
"Can have at most one call corresponding to a "
6485 "llvm.call.preallocated.setup");
6487 size_t NumPreallocatedArgs = 0;
6488 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
6489 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
6490 ++NumPreallocatedArgs;
6493 Check(NumPreallocatedArgs != 0,
6494 "cannot use preallocated intrinsics on a call without "
6495 "preallocated arguments");
6496 Check(NumArgs->equalsInt(NumPreallocatedArgs),
6497 "llvm.call.preallocated.setup arg size must be equal to number "
6498 "of preallocated arguments "
6508 auto PreallocatedBundle =
6510 Check(PreallocatedBundle,
6511 "Use of llvm.call.preallocated.setup outside intrinsics "
6512 "must be in \"preallocated\" operand bundle");
6513 Check(PreallocatedBundle->Inputs.front().get() == &
Call,
6514 "preallocated bundle must have token from corresponding "
6515 "llvm.call.preallocated.setup");
6520 case Intrinsic::call_preallocated_arg: {
6523 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
6524 "llvm.call.preallocated.arg token argument must be a "
6525 "llvm.call.preallocated.setup");
6527 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
6528 "call site attribute");
6531 case Intrinsic::call_preallocated_teardown: {
6534 Token->getIntrinsicID() == Intrinsic::call_preallocated_setup,
6535 "llvm.call.preallocated.teardown token argument must be a "
6536 "llvm.call.preallocated.setup");
6539 case Intrinsic::gcroot:
6540 case Intrinsic::gcwrite:
6541 case Intrinsic::gcread:
6542 if (
ID == Intrinsic::gcroot) {
6545 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.",
Call);
6547 "llvm.gcroot parameter #2 must be a constant.",
Call);
6550 "llvm.gcroot parameter #1 must either be a pointer alloca, "
6551 "or argument #2 must be a non-null constant.",
6557 "Enclosing function does not use GC.",
Call);
6559 case Intrinsic::init_trampoline:
6561 "llvm.init_trampoline parameter #2 must resolve to a function.",
6564 case Intrinsic::prefetch:
6566 "rw argument to llvm.prefetch must be 0-1",
Call);
6568 "locality argument to llvm.prefetch must be 0-3",
Call);
6570 "cache type argument to llvm.prefetch must be 0-1",
Call);
6572 case Intrinsic::reloc_none: {
6575 "llvm.reloc.none argument must be a metadata string", &
Call);
6578 case Intrinsic::stackprotector:
6580 "llvm.stackprotector parameter #2 must resolve to an alloca.",
Call);
6582 case Intrinsic::localescape: {
6586 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
6593 "llvm.localescape only accepts static allocas",
Call);
6596 SawFrameEscape =
true;
6599 case Intrinsic::localrecover: {
6603 "llvm.localrecover first "
6604 "argument must be function defined in this module",
6607 auto &
Entry = FrameEscapeInfo[Fn];
6608 Entry.second = unsigned(
6609 std::max(uint64_t(
Entry.second), IdxArg->getLimitedValue(~0U) + 1));
6613 case Intrinsic::experimental_gc_statepoint:
6615 Check(!CI->isInlineAsm(),
6616 "gc.statepoint support for inline assembly unimplemented", CI);
6618 "Enclosing function does not use GC.",
Call);
6620 verifyStatepoint(
Call);
6622 case Intrinsic::experimental_gc_result: {
6624 "Enclosing function does not use GC.",
Call);
6632 Check(StatepointCall && StatepointCall->getIntrinsicID() ==
6633 Intrinsic::experimental_gc_statepoint,
6634 "gc.result operand #1 must be from a statepoint",
Call,
6638 auto *TargetFuncType =
6641 "gc.result result type does not match wrapped callee",
Call);
6644 case Intrinsic::experimental_gc_relocate: {
6648 "gc.relocate must return a pointer or a vector of pointers",
Call);
6653 if (LandingPadInst *LandingPad =
6657 LandingPad->getParent()->getUniquePredecessor();
6661 Check(InvokeBB,
"safepoints should have unique landingpads",
6662 LandingPad->getParent());
6666 "gc relocate should be linked to a statepoint", InvokeBB);
6673 "gc relocate is incorrectly tied to the statepoint",
Call, Token);
6682 "gc.relocate operand #2 must be integer offset",
Call);
6686 "gc.relocate operand #3 must be integer offset",
Call);
6696 Check(BaseIndex < Opt->Inputs.size(),
6697 "gc.relocate: statepoint base index out of bounds",
Call);
6698 Check(DerivedIndex < Opt->Inputs.size(),
6699 "gc.relocate: statepoint derived index out of bounds",
Call);
6712 "gc.relocate: relocated value must be a pointer",
Call);
6713 Check(DerivedType->isPtrOrPtrVectorTy(),
6714 "gc.relocate: relocated value must be a pointer",
Call);
6716 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
6717 "gc.relocate: vector relocates to vector and pointer to pointer",
6720 ResultType->getPointerAddressSpace() ==
6721 DerivedType->getPointerAddressSpace(),
6722 "gc.relocate: relocating a pointer shouldn't change its address space",
6726 Check(GC,
"gc.relocate: calling function must have GCStrategy",
6729 auto isGCPtr = [&
GC](
Type *PTy) {
6730 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
6732 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer",
Call);
6734 "gc.relocate: relocated value must be a gc pointer",
Call);
6735 Check(isGCPtr(DerivedType),
6736 "gc.relocate: relocated value must be a gc pointer",
Call);
6740 case Intrinsic::experimental_patchpoint: {
6743 "patchpoint: invalid return type used with anyregcc",
Call);
6747 case Intrinsic::eh_exceptioncode:
6748 case Intrinsic::eh_exceptionpointer: {
6750 "eh.exceptionpointer argument must be a catchpad",
Call);
6753 case Intrinsic::get_active_lane_mask: {
6756 "get_active_lane_mask: element type is not i1",
Call);
6759 case Intrinsic::experimental_get_vector_length: {
6762 "get_vector_length: VF must be positive",
Call);
6765 case Intrinsic::experimental_guard: {
6768 "experimental_guard must have exactly one "
6769 "\"deopt\" operand bundle");
6773 case Intrinsic::experimental_deoptimize: {
6777 "experimental_deoptimize must have exactly one "
6778 "\"deopt\" operand bundle");
6780 "experimental_deoptimize return type must match caller return type");
6785 "calls to experimental_deoptimize must be followed by a return");
6789 "calls to experimental_deoptimize must be followed by a return "
6790 "of the value computed by experimental_deoptimize");
6795 case Intrinsic::vastart: {
6797 "va_start called in a non-varargs function");
6800 case Intrinsic::get_dynamic_area_offset: {
6802 Check(IntTy &&
DL.getPointerSizeInBits(
DL.getAllocaAddrSpace()) ==
6803 IntTy->getBitWidth(),
6804 "get_dynamic_area_offset result type must be scalar integer matching "
6805 "alloca address space width",
6809 case Intrinsic::smul_fix:
6810 case Intrinsic::smul_fix_sat:
6811 case Intrinsic::umul_fix:
6812 case Intrinsic::umul_fix_sat:
6813 case Intrinsic::sdiv_fix:
6814 case Intrinsic::sdiv_fix_sat:
6815 case Intrinsic::udiv_fix:
6816 case Intrinsic::udiv_fix_sat: {
6820 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
6821 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
6823 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
6827 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
6828 "to the width of the operands");
6832 case Intrinsic::lrint:
6833 case Intrinsic::llrint:
6834 case Intrinsic::lround:
6835 case Intrinsic::llround: {
6839 ExpectedName +
": argument and result disagree on vector use", &
Call);
6842 Check(VTy->getElementCount() == RTy->getElementCount(),
6843 ExpectedName +
": argument must be same length as result", &
Call);
6847 case Intrinsic::bswap: {
6850 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &
Call);
6853 case Intrinsic::invariant_start: {
6855 Check(InvariantSize &&
6857 "invariant_start parameter must be -1, 0 or a positive number",
6861 case Intrinsic::matrix_multiply:
6862 case Intrinsic::matrix_transpose:
6863 case Intrinsic::matrix_column_major_load:
6864 case Intrinsic::matrix_column_major_store: {
6866 ConstantInt *Stride =
nullptr;
6867 ConstantInt *NumRows;
6868 ConstantInt *NumColumns;
6870 Type *Op0ElemTy =
nullptr;
6871 Type *Op1ElemTy =
nullptr;
6873 case Intrinsic::matrix_multiply: {
6878 ->getNumElements() ==
6880 "First argument of a matrix operation does not match specified "
6883 ->getNumElements() ==
6885 "Second argument of a matrix operation does not match specified "
6895 case Intrinsic::matrix_transpose:
6902 case Intrinsic::matrix_column_major_load: {
6909 case Intrinsic::matrix_column_major_store: {
6922 Check(ResultTy->getElementType()->isIntegerTy() ||
6923 ResultTy->getElementType()->isFloatingPointTy(),
6924 "Result type must be an integer or floating-point type!", IF);
6927 Check(ResultTy->getElementType() == Op0ElemTy,
6928 "Vector element type mismatch of the result and first operand "
6933 Check(ResultTy->getElementType() == Op1ElemTy,
6934 "Vector element type mismatch of the result and second operand "
6940 "Result of a matrix operation does not fit in the returned vector!");
6946 "Stride must be greater or equal than the number of rows!", IF);
6951 case Intrinsic::stepvector: {
6953 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6954 VecTy->getScalarSizeInBits() >= 8,
6955 "stepvector only supported for vectors of integers "
6956 "with a bitwidth of at least 8.",
6960 case Intrinsic::experimental_vector_match: {
6969 Check(Op1Ty && Op2Ty && MaskTy,
"Operands must be vectors.", &
Call);
6971 "Second operand must be a fixed length vector.", &
Call);
6972 Check(Op1Ty->getElementType()->isIntegerTy(),
6973 "First operand must be a vector of integers.", &
Call);
6974 Check(Op1Ty->getElementType() == Op2Ty->getElementType(),
6975 "First two operands must have the same element type.", &
Call);
6976 Check(Op1Ty->getElementCount() == MaskTy->getElementCount(),
6977 "First operand and mask must have the same number of elements.",
6979 Check(MaskTy->getElementType()->isIntegerTy(1),
6980 "Mask must be a vector of i1's.", &
Call);
6985 case Intrinsic::vector_insert: {
6994 ElementCount VecEC = VecTy->getElementCount();
6995 ElementCount SubVecEC = SubVecTy->getElementCount();
6996 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6997 "vector_insert parameters must have the same element "
7001 "vector_insert index must be a constant multiple of "
7002 "the subvector's known minimum vector length.");
7010 "subvector operand of vector_insert would overrun the "
7011 "vector being inserted into.");
7015 case Intrinsic::vector_extract: {
7023 ElementCount VecEC = VecTy->getElementCount();
7024 ElementCount ResultEC = ResultTy->getElementCount();
7026 Check(ResultTy->getElementType() == VecTy->getElementType(),
7027 "vector_extract result must have the same element "
7028 "type as the input vector.",
7031 "vector_extract index must be a constant multiple of "
7032 "the result type's known minimum vector length.");
7040 "vector_extract would overrun.");
7044 case Intrinsic::vector_partial_reduce_fadd:
7045 case Intrinsic::vector_partial_reduce_add: {
7049 unsigned VecWidth = VecTy->getElementCount().getKnownMinValue();
7050 unsigned AccWidth = AccTy->getElementCount().getKnownMinValue();
7052 Check((VecWidth % AccWidth) == 0,
7053 "Invalid vector widths for partial "
7054 "reduction. The width of the input vector "
7055 "must be a positive integer multiple of "
7056 "the width of the accumulator vector.");
7059 case Intrinsic::experimental_noalias_scope_decl: {
7063 case Intrinsic::preserve_array_access_index:
7064 case Intrinsic::preserve_struct_access_index:
7065 case Intrinsic::aarch64_ldaxr:
7066 case Intrinsic::aarch64_ldxr:
7067 case Intrinsic::arm_ldaex:
7068 case Intrinsic::arm_ldrex: {
7070 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
7074 case Intrinsic::aarch64_stlxr:
7075 case Intrinsic::aarch64_stxr:
7076 case Intrinsic::arm_stlex:
7077 case Intrinsic::arm_strex: {
7080 "Intrinsic requires elementtype attribute on second argument.",
7084 case Intrinsic::aarch64_prefetch: {
7086 "write argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
7088 "target argument to llvm.aarch64.prefetch must be 0-3",
Call);
7090 "stream argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
7092 "isdata argument to llvm.aarch64.prefetch must be 0 or 1",
Call);
7095 case Intrinsic::aarch64_range_prefetch: {
7097 "write argument to llvm.aarch64.range.prefetch must be 0 or 1",
Call);
7099 "stream argument to llvm.aarch64.range.prefetch must be 0 or 1",
7103 case Intrinsic::callbr_landingpad: {
7105 Check(CBR,
"intrinstic requires callbr operand", &
Call);
7112 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &
Call);
7116 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
7121 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
7122 "block in indirect destination list",
7125 Check(&
First == &
Call,
"No other instructions may proceed intrinsic",
7129 case Intrinsic::structured_gep: {
7135 "Intrinsic first parameter is missing an ElementType attribute",
7143 "Index operand type must be an integer", &
Call);
7146 T = AT->getElementType();
7148 Check(CI,
"Indexing into a struct requires a constant int", &
Call);
7150 "Indexing in a struct should be inbounds", &
Call);
7153 T = VT->getElementType();
7155 CheckFailed(
"Reached a non-composite type with more indices to process",
7161 case Intrinsic::structured_alloca:
7163 "@llvm.structured.alloca calls require elementtype attribute.",
7166 case Intrinsic::amdgcn_cs_chain: {
7169 case CallingConv::AMDGPU_CS:
7170 case CallingConv::AMDGPU_CS_Chain:
7171 case CallingConv::AMDGPU_CS_ChainPreserve:
7172 case CallingConv::AMDGPU_ES:
7173 case CallingConv::AMDGPU_GS:
7174 case CallingConv::AMDGPU_HS:
7175 case CallingConv::AMDGPU_LS:
7176 case CallingConv::AMDGPU_VS:
7179 CheckFailed(
"Intrinsic cannot be called from functions with this "
7180 "calling convention",
7186 "SGPR arguments must have the `inreg` attribute", &
Call);
7188 "VGPR arguments must not have the `inreg` attribute", &
Call);
7191 Check(FlagsArg->getValue().ult(2),
7192 "flags must be 0 or 1 for llvm.amdgcn.cs.chain", &
Call);
7197 Intrinsic::amdgcn_unreachable;
7199 "llvm.amdgcn.cs.chain must be followed by unreachable", &
Call);
7202 case Intrinsic::amdgcn_init_exec_from_input: {
7205 "only inreg arguments to the parent function are valid as inputs to "
7210 case Intrinsic::amdgcn_set_inactive_chain_arg: {
7213 case CallingConv::AMDGPU_CS_Chain:
7214 case CallingConv::AMDGPU_CS_ChainPreserve:
7217 CheckFailed(
"Intrinsic can only be used from functions with the "
7218 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
7219 "calling conventions",
7224 unsigned InactiveIdx = 1;
7226 "Value for inactive lanes must not have the `inreg` attribute",
7229 "Value for inactive lanes must be a function argument", &
Call);
7231 "Value for inactive lanes must be a VGPR function argument", &
Call);
7234 case Intrinsic::amdgcn_call_whole_wave: {
7236 Check(
F,
"Indirect whole wave calls are not allowed", &
Call);
7238 CallingConv::ID CC =
F->getCallingConv();
7239 Check(CC == CallingConv::AMDGPU_Gfx_WholeWave,
7240 "Callee must have the amdgpu_gfx_whole_wave calling convention",
7243 Check(!
F->isVarArg(),
"Variadic whole wave calls are not allowed", &
Call);
7246 "Call argument count must match callee argument count", &
Call);
7250 Check(
F->arg_begin()->getType()->isIntegerTy(1),
7251 "Callee must have i1 as its first argument", &
Call);
7252 for (
auto [CallArg, FuncArg] :
7254 Check(CallArg->getType() == FuncArg.getType(),
7255 "Argument types must match", &
Call);
7259 FuncArg.hasInRegAttr(),
7260 "Argument inreg attributes must match", &
Call);
7264 case Intrinsic::amdgcn_s_prefetch_data: {
7268 "llvm.amdgcn.s.prefetch.data only supports global or constant memory");
7271 case Intrinsic::amdgcn_load_to_lds:
7272 case Intrinsic::amdgcn_load_async_to_lds:
7273 case Intrinsic::amdgcn_global_load_lds:
7274 case Intrinsic::amdgcn_global_load_async_lds:
7275 case Intrinsic::amdgcn_raw_buffer_load_lds:
7276 case Intrinsic::amdgcn_raw_buffer_load_async_lds:
7277 case Intrinsic::amdgcn_raw_ptr_buffer_load_lds:
7278 case Intrinsic::amdgcn_raw_ptr_buffer_load_async_lds:
7279 case Intrinsic::amdgcn_struct_buffer_load_lds:
7280 case Intrinsic::amdgcn_struct_buffer_load_async_lds:
7281 case Intrinsic::amdgcn_struct_ptr_buffer_load_lds:
7282 case Intrinsic::amdgcn_struct_ptr_buffer_load_async_lds: {
7286 "invalid data size for load-to-LDS intrinsic; must be 1, 2, 4, 12, "
7291 case Intrinsic::amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
7292 case Intrinsic::amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
7298 Check(CBSZ <= 4,
"invalid value for cbsz format",
Call,
7300 Check(BLGP <= 4,
"invalid value for blgp format",
Call,
7304 auto getFormatNumRegs = [](
unsigned FormatVal) {
7305 switch (FormatVal) {
7319 auto isValidSrcASrcBVector = [](FixedVectorType *Ty) {
7320 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
7322 unsigned NumElts = Ty->getNumElements();
7323 return NumElts == 4 || NumElts == 6 || NumElts == 8;
7328 Check(isValidSrcASrcBVector(Src0Ty),
7329 "operand 0 must be 4, 6 or 8 element i32 vector", &
Call, Src0);
7330 Check(isValidSrcASrcBVector(Src1Ty),
7331 "operand 1 must be 4, 6 or 8 element i32 vector", &
Call, Src1);
7334 Check(Src0Ty->getNumElements() >= getFormatNumRegs(CBSZ),
7336 Check(Src1Ty->getNumElements() >= getFormatNumRegs(BLGP),
7340 case Intrinsic::amdgcn_wmma_f32_16x16x128_f8f6f4:
7341 case Intrinsic::amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
7342 case Intrinsic::amdgcn_wmma_scale16_f32_16x16x128_f8f6f4: {
7348 Check(FmtA <= 4,
"invalid value for matrix format",
Call,
7350 Check(FmtB <= 4,
"invalid value for matrix format",
Call,
7354 auto getFormatNumRegs = [](
unsigned FormatVal) {
7355 switch (FormatVal) {
7369 auto isValidSrcASrcBVector = [](FixedVectorType *Ty) {
7370 if (!Ty || !Ty->getElementType()->
isIntegerTy(32))
7372 unsigned NumElts = Ty->getNumElements();
7373 return NumElts == 16 || NumElts == 12 || NumElts == 8;
7378 Check(isValidSrcASrcBVector(Src0Ty),
7379 "operand 1 must be 8, 12 or 16 element i32 vector", &
Call, Src0);
7380 Check(isValidSrcASrcBVector(Src1Ty),
7381 "operand 3 must be 8, 12 or 16 element i32 vector", &
Call, Src1);
7384 Check(Src0Ty->getNumElements() >= getFormatNumRegs(FmtA),
7386 Check(Src1Ty->getNumElements() >= getFormatNumRegs(FmtB),
7390 case Intrinsic::amdgcn_cooperative_atomic_load_32x4B:
7391 case Intrinsic::amdgcn_cooperative_atomic_load_16x8B:
7392 case Intrinsic::amdgcn_cooperative_atomic_load_8x16B:
7393 case Intrinsic::amdgcn_cooperative_atomic_store_32x4B:
7394 case Intrinsic::amdgcn_cooperative_atomic_store_16x8B:
7395 case Intrinsic::amdgcn_cooperative_atomic_store_8x16B: {
7400 "cooperative atomic intrinsics require a generic or global pointer",
7407 "cooperative atomic intrinsics require that the last argument is a "
7412 case Intrinsic::amdgcn_av_load_b128:
7413 case Intrinsic::amdgcn_av_store_b128: {
7418 "the last argument to av load/store intrinsics must be a "
7423 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
7424 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
7427 Check(RegCount % 8 == 0,
7428 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
7431 case Intrinsic::experimental_convergence_entry:
7432 case Intrinsic::experimental_convergence_anchor:
7434 case Intrinsic::experimental_convergence_loop:
7436 case Intrinsic::ptrmask: {
7440 "llvm.ptrmask intrinsic first argument must be pointer or vector "
7445 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
7450 "llvm.ptrmask intrinsic arguments must have the same number of "
7454 "llvm.ptrmask intrinsic second argument bitwidth must match "
7455 "pointer index type size of first argument",
7459 case Intrinsic::thread_pointer: {
7461 DL.getDefaultGlobalsAddressSpace(),
7462 "llvm.thread.pointer intrinsic return type must be for the globals "
7467 case Intrinsic::threadlocal_address: {
7470 "llvm.threadlocal.address first argument must be a GlobalValue");
7472 "llvm.threadlocal.address operand isThreadLocal() must be true");
7475 case Intrinsic::lifetime_start:
7476 case Intrinsic::lifetime_end: {
7480 (
II &&
II->getIntrinsicID() == Intrinsic::structured_alloca),
7481 "llvm.lifetime.start/end can only be used on alloca or poison",
7485 case Intrinsic::sponentry: {
7486 const unsigned StackAS =
DL.getAllocaAddrSpace();
7489 "llvm.sponentry must return a pointer to the stack", &
Call);
7492 case Intrinsic::write_volatile_register: {
7496 "llvm.write_volatile_register metadata must be a single MDString",
7505 if (
F->hasPersonalityFn() &&
7509 if (BlockEHFuncletColors.
empty())
7513 bool InEHFunclet =
false;
7517 for (BasicBlock *ColorFirstBB : CV)
7518 if (
auto It = ColorFirstBB->getFirstNonPHIIt();
7519 It != ColorFirstBB->end())
7524 bool HasToken =
false;
7531 Check(HasToken,
"Missing funclet token on intrinsic call", &
Call);
7555void Verifier::visit(DbgLabelRecord &DLR) {
7557 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
7570 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
7574 if (!LabelSP || !LocSP)
7578 "mismatched subprogram between #dbg_label label and !dbg attachment",
7579 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
7580 Loc->getScope()->getSubprogram());
7583void Verifier::visit(DbgVariableRecord &DVR) {
7587 CheckDI(DVR.
getType() == DbgVariableRecord::LocationType::Value ||
7588 DVR.
getType() == DbgVariableRecord::LocationType::Declare ||
7589 DVR.
getType() == DbgVariableRecord::LocationType::DeclareValue ||
7590 DVR.
getType() == DbgVariableRecord::LocationType::Assign,
7591 "invalid #dbg record type", &DVR, DVR.
getType(), BB,
F);
7599 "invalid #dbg record address/value", &DVR, MD, BB,
F);
7601 visitValueAsMetadata(*VAM,
F);
7604 Type *Ty = VAM->getValue()->getType();
7606 "location of #dbg_declare must be a pointer or int", &DVR, MD, BB,
7610 visitDIArgList(*AL,
F);
7624 "invalid #dbg_assign DIAssignID", &DVR, DVR.
getRawAssignID(), BB,
7627 AreDebugLocsAllowed::No);
7636 "invalid #dbg_assign address", &DVR, DVR.
getRawAddress(), BB,
F);
7638 visitValueAsMetadata(*VAM,
F);
7641 "invalid #dbg_assign address expression", &DVR,
7648 "inst not in same function as #dbg_assign",
I, &DVR, BB,
F);
7658 &DVR, DLNode, BB,
F);
7664 if (!VarSP || !LocSP)
7668 "mismatched subprogram between #dbg record variable and DILocation",
7670 Loc->getScope()->getSubprogram(), BB,
F);
7675void Verifier::visitVPIntrinsic(VPIntrinsic &VPI) {
7679 Check(RetTy->getElementCount() == ValTy->getElementCount(),
7680 "VP cast intrinsic first argument and result vector lengths must be "
7684 switch (VPCast->getIntrinsicID()) {
7687 case Intrinsic::vp_trunc:
7689 "llvm.vp.trunc intrinsic first argument and result element type "
7693 "llvm.vp.trunc intrinsic the bit size of first argument must be "
7694 "larger than the bit size of the return type",
7697 case Intrinsic::vp_zext:
7698 case Intrinsic::vp_sext:
7700 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
7701 "element type must be integer",
7704 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
7705 "argument must be smaller than the bit size of the return type",
7708 case Intrinsic::vp_fptoui:
7709 case Intrinsic::vp_fptosi:
7710 case Intrinsic::vp_lrint:
7711 case Intrinsic::vp_llrint:
7714 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
7715 "type must be floating-point and result element type must be integer",
7718 case Intrinsic::vp_uitofp:
7719 case Intrinsic::vp_sitofp:
7722 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
7723 "type must be integer and result element type must be floating-point",
7726 case Intrinsic::vp_fptrunc:
7728 "llvm.vp.fptrunc intrinsic first argument and result element type "
7729 "must be floating-point",
7732 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
7733 "larger than the bit size of the return type",
7736 case Intrinsic::vp_fpext:
7738 "llvm.vp.fpext intrinsic first argument and result element type "
7739 "must be floating-point",
7742 "llvm.vp.fpext intrinsic the bit size of first argument must be "
7743 "smaller than the bit size of the return type",
7746 case Intrinsic::vp_ptrtoint:
7748 "llvm.vp.ptrtoint intrinsic first argument element type must be "
7749 "pointer and result element type must be integer",
7752 case Intrinsic::vp_inttoptr:
7754 "llvm.vp.inttoptr intrinsic first argument element type must be "
7755 "integer and result element type must be pointer",
7762 case Intrinsic::vp_fcmp: {
7765 "invalid predicate for VP FP comparison intrinsic", &VPI);
7768 case Intrinsic::vp_icmp: {
7771 "invalid predicate for VP integer comparison intrinsic", &VPI);
7774 case Intrinsic::vp_is_fpclass: {
7777 "unsupported bits for llvm.vp.is.fpclass test mask");
7780 case Intrinsic::experimental_vp_splice: {
7783 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
7785 AttributeList
Attrs = VPI.
getParent()->getParent()->getAttributes();
7786 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
7787 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
7789 Check((Idx < 0 && std::abs(Idx) <= KnownMinNumElements) ||
7790 (Idx >= 0 && Idx < KnownMinNumElements),
7791 "The splice index exceeds the range [-VL, VL-1] where VL is the "
7792 "known minimum number of elements in the vector. For scalable "
7793 "vectors the minimum number of elements is determined from "
7801void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) {
7803 bool HasRoundingMD =
7807 NumOperands += (1 + HasRoundingMD);
7813 "invalid arguments for constrained FP intrinsic", &FPI);
7816 case Intrinsic::experimental_constrained_fcmp:
7817 case Intrinsic::experimental_constrained_fcmps: {
7820 "invalid predicate for constrained FP comparison intrinsic", &FPI);
7824 case Intrinsic::experimental_constrained_fptosi:
7825 case Intrinsic::experimental_constrained_fptoui: {
7829 "Intrinsic first argument must be floating point", &FPI);
7836 "Intrinsic first argument and result disagree on vector use", &FPI);
7838 "Intrinsic result must be an integer", &FPI);
7841 "Intrinsic first argument and result vector lengths must be equal",
7847 case Intrinsic::experimental_constrained_sitofp:
7848 case Intrinsic::experimental_constrained_uitofp: {
7852 "Intrinsic first argument must be integer", &FPI);
7859 "Intrinsic first argument and result disagree on vector use", &FPI);
7861 "Intrinsic result must be a floating point", &FPI);
7864 "Intrinsic first argument and result vector lengths must be equal",
7870 case Intrinsic::experimental_constrained_fptrunc:
7871 case Intrinsic::experimental_constrained_fpext: {
7877 "Intrinsic first argument must be FP or FP vector", &FPI);
7879 "Intrinsic result must be FP or FP vector", &FPI);
7881 "Intrinsic first argument and result disagree on vector use", &FPI);
7885 "Intrinsic first argument and result vector lengths must be equal",
7888 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
7890 "Intrinsic first argument's type must be larger than result type",
7894 "Intrinsic first argument's type must be smaller than result type",
7910 "invalid exception behavior argument", &FPI);
7911 if (HasRoundingMD) {
7917void Verifier::verifyFragmentExpression(
const DbgVariableRecord &DVR) {
7922 if (!V || !
E || !
E->isValid())
7926 auto Fragment =
E->getFragmentInfo();
7936 if (
V->isArtificial())
7939 verifyFragmentExpression(*V, *Fragment, &DVR);
7942template <
typename ValueOrMetadata>
7943void Verifier::verifyFragmentExpression(
const DIVariable &V,
7945 ValueOrMetadata *
Desc) {
7948 auto VarSize =
V.getSizeInBits();
7954 CheckDI(FragSize + FragOffset <= *VarSize,
7955 "fragment is larger than or outside of variable",
Desc, &V);
7956 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
7959void Verifier::verifyFnArgs(
const DbgVariableRecord &DVR) {
7971 CheckDI(Var,
"#dbg record without variable");
7973 unsigned ArgNo = Var->
getArg();
7979 if (DebugFnArgs.
size() < ArgNo)
7980 DebugFnArgs.
resize(ArgNo,
nullptr);
7982 auto *Prev = DebugFnArgs[ArgNo - 1];
7983 DebugFnArgs[ArgNo - 1] = Var;
7984 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
7988void Verifier::verifyNotEntryValue(
const DbgVariableRecord &DVR) {
7992 if (!
E || !
E->isValid())
8002 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
8007 "Entry values are only allowed in MIR unless they target a "
8008 "swiftasync Argument",
8012void Verifier::verifyCompileUnits() {
8016 if (
M.getContext().isODRUniquingDebugTypes())
8018 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
8019 SmallPtrSet<const Metadata *, 2> Listed;
8022 for (
const auto *CU : CUVisited)
8023 CheckDI(Listed.
count(CU),
"DICompileUnit not listed in llvm.dbg.cu", CU);
8027void Verifier::verifyDeoptimizeCallingConvs() {
8028 if (DeoptimizeDeclarations.
empty())
8032 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
8033 Check(
First->getCallingConv() ==
F->getCallingConv(),
8034 "All llvm.experimental.deoptimize declarations must have the same "
8035 "calling convention",
8040void Verifier::verifyAttachedCallBundle(
const CallBase &
Call,
8041 const OperandBundleUse &BU) {
8044 Check((FTy->getReturnType()->isPointerTy() ||
8046 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
8047 "function returning a pointer or a non-returning function that has a "
8052 "operand bundle \"clang.arc.attachedcall\" requires one function as "
8060 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
8061 IID == Intrinsic::objc_claimAutoreleasedReturnValue ||
8062 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
8063 "invalid function argument",
Call);
8065 StringRef FnName = Fn->
getName();
8066 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
8067 FnName ==
"objc_claimAutoreleasedReturnValue" ||
8068 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
8069 "invalid function argument",
Call);
8073void Verifier::verifyNoAliasScopeDecl() {
8074 if (NoAliasScopeDecls.
empty())
8078 for (
auto *
II : NoAliasScopeDecls) {
8079 assert(
II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
8080 "Not a llvm.experimental.noalias.scope.decl ?");
8083 Check(ScopeListMV !=
nullptr,
8084 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
8089 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode",
II);
8090 Check(ScopeListMD->getNumOperands() == 1,
8091 "!id.scope.list must point to a list with a single scope",
II);
8092 visitAliasScopeListMetadata(ScopeListMD);
8102 auto GetScope = [](IntrinsicInst *
II) {
8105 return &
cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
8110 auto Compare = [GetScope](IntrinsicInst *Lhs, IntrinsicInst *Rhs) {
8111 return GetScope(Lhs) < GetScope(Rhs);
8118 auto ItCurrent = NoAliasScopeDecls.begin();
8119 while (ItCurrent != NoAliasScopeDecls.end()) {
8120 auto CurScope = GetScope(*ItCurrent);
8121 auto ItNext = ItCurrent;
8124 }
while (ItNext != NoAliasScopeDecls.end() &&
8125 GetScope(*ItNext) == CurScope);
8130 if (ItNext - ItCurrent < 32)
8134 Check(!DT.dominates(
I, J),
8135 "llvm.experimental.noalias.scope.decl dominates another one "
8136 "with the same scope",
8150 Verifier V(OS,
true, *f.getParent());
8154 return !V.verify(
F);
8158 bool *BrokenDebugInfo) {
8160 Verifier V(OS, !BrokenDebugInfo, M);
8162 bool Broken =
false;
8164 Broken |= !V.verify(
F);
8166 Broken |= !V.verify();
8167 if (BrokenDebugInfo)
8168 *BrokenDebugInfo = V.hasBrokenDebugInfo();
8179 std::unique_ptr<Verifier> V;
8180 bool FatalErrors =
true;
8183 explicit VerifierLegacyPass(
bool FatalErrors)
8184 : FunctionPass(
ID), FatalErrors(FatalErrors) {}
8186 bool doInitialization(
Module &M)
override {
8187 V = std::make_unique<Verifier>(
8193 if (!
V->verify(
F) && FatalErrors) {
8194 errs() <<
"in function " <<
F.getName() <<
'\n';
8200 bool doFinalization(
Module &M)
override {
8201 bool HasErrors =
false;
8202 for (Function &
F : M)
8203 if (
F.isDeclaration())
8204 HasErrors |= !
V->verify(
F);
8206 HasErrors |= !
V->verify();
8207 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
8212 void getAnalysisUsage(AnalysisUsage &AU)
const override {
8220template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
8222 return Diagnostic->CheckFailed(
Args...);
8225#define CheckTBAA(C, ...) \
8228 CheckFailed(__VA_ARGS__); \
8236TBAAVerifier::TBAABaseNodeSummary
8240 CheckFailed(
"Base nodes must have at least two operands",
I, BaseNode);
8244 auto Itr = TBAABaseNodes.find(BaseNode);
8245 if (Itr != TBAABaseNodes.end())
8248 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
8249 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
8251 assert(InsertResult.second &&
"We just checked!");
8255TBAAVerifier::TBAABaseNodeSummary
8256TBAAVerifier::verifyTBAABaseNodeImpl(
const Instruction *
I,
8257 const MDNode *BaseNode,
bool IsNewFormat) {
8258 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
8262 return isValidScalarTBAANode(BaseNode)
8263 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
8269 CheckFailed(
"Access tag nodes must have the number of operands that is a "
8270 "multiple of 3!", BaseNode);
8275 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
8285 if (!TypeSizeNode) {
8286 CheckFailed(
"Type size nodes must be constants!",
I, BaseNode);
8293 CheckFailed(
"Struct tag nodes have a string as their first operand",
8300 std::optional<APInt> PrevOffset;
8305 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
8306 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
8307 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
8308 Idx += NumOpsPerField) {
8309 const MDOperand &FieldTy = BaseNode->
getOperand(Idx);
8310 const MDOperand &FieldOffset = BaseNode->
getOperand(Idx + 1);
8312 CheckFailed(
"Incorrect field entry in struct type node!",
I, BaseNode);
8317 auto *OffsetEntryCI =
8319 if (!OffsetEntryCI) {
8320 CheckFailed(
"Offset entries must be constants!",
I, BaseNode);
8326 BitWidth = OffsetEntryCI->getBitWidth();
8328 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
8330 "Bitwidth between the offsets and struct type entries must match",
I,
8342 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
8345 CheckFailed(
"Offsets must be increasing!",
I, BaseNode);
8349 PrevOffset = OffsetEntryCI->getValue();
8354 if (!MemberSizeNode) {
8355 CheckFailed(
"Member size entries must be constants!",
I, BaseNode);
8362 return Failed ? InvalidNode
8363 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
8385 return Parent && Visited.
insert(Parent).second &&
8389bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
8390 auto ResultIt = TBAAScalarNodes.find(MD);
8391 if (ResultIt != TBAAScalarNodes.end())
8392 return ResultIt->second;
8394 SmallPtrSet<const MDNode *, 4> Visited;
8396 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
8398 assert(InsertResult.second &&
"Just checked!");
8407MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(
const Instruction *
I,
8408 const MDNode *BaseNode,
8419 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
8420 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
8421 for (
unsigned Idx = FirstFieldOpNo; Idx < BaseNode->
getNumOperands();
8422 Idx += NumOpsPerField) {
8423 auto *OffsetEntryCI =
8425 if (OffsetEntryCI->getValue().ugt(
Offset)) {
8426 if (Idx == FirstFieldOpNo) {
8427 CheckFailed(
"Could not find TBAA parent in struct type node",
I,
8432 unsigned PrevIdx = Idx - NumOpsPerField;
8433 auto *PrevOffsetEntryCI =
8435 Offset -= PrevOffsetEntryCI->getValue();
8443 Offset -= LastOffsetEntryCI->getValue();
8448 if (!
Type ||
Type->getNumOperands() < 3)
8464 "This instruction shall not have a TBAA access tag!",
I);
8466 bool IsStructPathTBAA =
8470 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
8480 "Access tag metadata must have either 4 or 5 operands",
I, MD);
8483 "Struct tag metadata must have either 3 or 4 operands",
I, MD);
8490 CheckTBAA(AccessSizeNode,
"Access size field must be a constant",
I, MD);
8494 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
8499 "Immutability tag on struct tag metadata must be a constant",
I,
8502 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
8503 "Immutability part of the struct tag metadata must be either 0 or 1",
I,
8508 "Malformed struct tag metadata: base and access-type "
8509 "should be non-null and point to Metadata nodes",
8510 I, MD, BaseNode, AccessType);
8513 CheckTBAA(isValidScalarTBAANode(AccessType),
8514 "Access type node must be a valid scalar type",
I, MD,
8519 CheckTBAA(OffsetCI,
"Offset must be constant integer",
I, MD);
8522 bool SeenAccessTypeInPath =
false;
8528 getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset, IsNewFormat)) {
8529 if (!StructPath.
insert(BaseNode).second) {
8530 CheckFailed(
"Cycle detected in struct path",
I, MD);
8535 unsigned BaseNodeBitWidth;
8536 std::tie(
Invalid, BaseNodeBitWidth) =
8537 verifyTBAABaseNode(
I, BaseNode, IsNewFormat);
8544 SeenAccessTypeInPath |= BaseNode == AccessType;
8546 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
8551 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
8552 (IsNewFormat && BaseNodeBitWidth == ~0u),
8553 "Access bit-width not the same as description bit-width",
I, MD,
8554 BaseNodeBitWidth,
Offset.getBitWidth());
8556 if (IsNewFormat && SeenAccessTypeInPath)
8560 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!",
I,
8565char VerifierLegacyPass::ID = 0;
8566INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
8569 return new VerifierLegacyPass(FatalErrors);
8587 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
8595 if (res.IRBroken && FatalErrors)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares the LLVM IR specialization of the GenericConvergenceVerifier template.
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
static bool runOnFunction(Function &F, bool PostInlining)
This file contains the declarations of entities that describe floating point environment and related ...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
static constexpr Value * getValue(Ty &ValueOrUse)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
static unsigned getNumElements(Type *Ty)
static void visit(BasicBlock &Start, std::function< bool(BasicBlock *)> op)
verify safepoint Safepoint IR Verifier
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static bool IsScalarTBAANodeImpl(const MDNode *MD, SmallPtrSetImpl< const MDNode * > &Visited)
static bool isType(const Metadata *MD)
static Instruction * getSuccPad(Instruction *Terminator)
static bool isMDTuple(const Metadata *MD)
static bool isNewFormatTBAATypeNode(llvm::MDNode *Type)
#define CheckDI(C,...)
We know that a debug info condition should be true, if not print an error message.
static void forEachUser(const Value *User, SmallPtrSet< const Value *, 32 > &Visited, llvm::function_ref< bool(const Value *)> Callback)
static bool isDINode(const Metadata *MD)
static bool isScope(const Metadata *MD)
static cl::opt< bool > VerifyNoAliasScopeDomination("verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false), cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical " "scopes are not dominating"))
static bool isConstantIntMetadataOperand(const Metadata *MD)
static bool IsRootTBAANode(const MDNode *MD)
static Value * getParentPad(Value *EHPad)
static bool hasConflictingReferenceFlags(unsigned Flags)
Detect mutually exclusive flags.
static AttrBuilder getParameterABIAttributes(LLVMContext &C, unsigned I, AttributeList Attrs)
static const char PassName[]
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
bool isFiniteNonZero() const
const fltSemantics & getSemantics() const
Class for arbitrary precision integers.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isMinValue() const
Determine if this is the smallest unsigned value.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
int64_t getSExtValue() const
Get sign extended value.
bool isMaxValue() const
Determine if this is the largest unsigned value.
This class represents a conversion between pointers from one address space to another.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
LLVM_ABI bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
unsigned getAddressSpace() const
Return the address space for the allocation.
LLVM_ABI bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
const Value * getArraySize() const
Get the number of elements allocated.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_ABI bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
bool isElementwise() const
Return true if this RMW has elementwise vector semantics.
static bool isFPOperation(BinOp Op)
BinOp getOperation() const
static LLVM_ABI StringRef getOperationName(BinOp Op)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
LLVM_ABI const ConstantRange & getValueAsConstantRange() const
Return the attribute's value as a ConstantRange.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM_ABI Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const Instruction & front() const
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
This class represents a no-op cast from one type to another.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
auto operand_bundles() const
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool doesNotAccessMemory(unsigned OpNo) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
unsigned countOperandBundlesOfType(StringRef Name) const
Return the number of operand bundles with the tag Name attached to this instruction.
bool onlyReadsMemory(unsigned OpNo) const
Value * getCalledOperand() const
Type * getParamElementType(unsigned ArgNo) const
Extract the elementtype type for a parameter.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
bool doesNotReturn() const
Determine if the call cannot return.
LLVM_ABI bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
BasicBlock * getIndirectDest(unsigned i) const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
bool isMustTailCall() const
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
unsigned getNumHandlers() const
return the number of 'handlers' in this catchswitch instruction, except the default handler
Value * getParentPad() const
BasicBlock * getUnwindDest() const
handler_range handlers()
iteration adapter for range-for loops.
BasicBlock * getUnwindDest() const
bool isFPPredicate() const
bool isIntPredicate() const
static bool isIntPredicate(Predicate P)
Value * getCondition() const
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
ConstantInt * getKey() const
The Key ID, an i32 constant.
Constant * getDeactivationSymbol() const
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
static LLVM_ABI bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
LLVM_ABI std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
LLVM_ABI std::optional< RoundingMode > getRoundingMode() const
LLVM_ABI unsigned getNonMetadataArgCount() const
DbgVariableFragmentInfo FragmentInfo
@ FixedPointBinary
Scale factor 2^Factor.
@ FixedPointDecimal
Scale factor 10^Factor.
@ FixedPointRational
Arbitrary rational scale factor.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
LLVM_ABI DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata * getRawScope() const
Base class for scope-like contexts.
Subprogram description. Uses SubclassData1.
static LLVM_ABI const DIScope * getRawRetainedNodeScope(const MDNode *N)
Base class for template parameters.
Base class for variables.
Metadata * getRawType() const
Metadata * getRawScope() const
uint64_t getNumOperands() const
A parsed version of the target data layout string in and methods for querying it.
Records a position in IR for a source label (DILabel).
MDNode * getRawLabel() const
DILabel * getLabel() const
Base class for non-instruction debug metadata records that have positions within IR.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
LLVM_ABI const BasicBlock * getParent() const
LLVM_ABI Function * getFunction()
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LocationType getType() const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
LLVM_ABI Value * getVariableLocationOp(unsigned OpIdx) const
DIExpression * getExpression() const
Metadata * getRawAssignID() const
MDNode * getRawVariable() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
DIExpression * getAddressExpression() const
LLVM_ABI MDNode * getAsMDNode() const
Return this as a bar MDNode.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This instruction compares its operands according to the predicate given to the constructor.
This class represents an extension of floating point types.
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
op_range arg_operands()
arg_operands - iteration adapter for range-for loops.
Value * getParentPad() const
Convenience accessors.
FunctionPass class - This class is used to implement most global optimizations.
Type * getReturnType() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
DISubprogram * getSubprogram() const
Get the attached subprogram.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasPersonalityFn() const
Check whether this function has a personality function.
const Function & getFunction() const
const std::string & getGC() const
Type * getReturnType() const
Returns the type of the ret val.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
LLVM_ABI Value * getBasePtr() const
LLVM_ABI Value * getDerivedPtr() const
void visit(const BlockT &BB)
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
static bool isValidLinkage(LinkageTypes L)
const Constant * getAliasee() const
LLVM_ABI const Function * getResolverFunction() const
static bool isValidLinkage(LinkageTypes L)
const Constant * getResolver() const
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
bool hasExternalLinkage() const
bool isImplicitDSOLocal() const
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasValidDeclarationLinkage() const
LinkageTypes getLinkage() const
bool hasDefaultVisibility() const
bool hasPrivateLinkage() const
bool hasHiddenVisibility() const
bool hasExternalWeakLinkage() const
bool hasDLLImportStorageClass() const
bool hasDLLExportStorageClass() const
bool isDeclarationForLinker() const
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
bool hasCommonLinkage() const
bool hasGlobalUnnamedAddr() const
bool hasAppendingLinkage() const
bool hasAvailableExternallyLinkage() const
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
This instruction compares its operands according to the predicate given to the constructor.
BasicBlock * getDestination(unsigned i)
Return the specified destination.
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
unsigned getNumSuccessors() const
This instruction inserts a single (scalar) element into a VectorType value.
static LLVM_ABI bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
Value * getAggregateOperand()
ArrayRef< unsigned > getIndices() const
Base class for instruction visitors.
void visit(Iterator Start, Iterator End)
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
static LLVM_ABI bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
@ OB_clang_arc_attachedcall
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
Align getAlign() const
Return the alignment of the access that is being performed.
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
bool isResolved() const
Check if node is fully resolved.
LLVMContext & getContext() const
bool equalsStr(StringRef Str) const
LLVM_ABI StringRef getString() const
This class implements a map that also provides access to all stored values in a deterministic order.
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
LLVM_ABI StringRef getName() const
LLVM_ABI void print(raw_ostream &ROS, bool IsForDebug=false) const
LLVM_ABI unsigned getNumOperands() const
iterator_range< op_iterator > operands()
op_range incoming_values()
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
This class represents a cast from a pointer to an address (non-capturing ptrtoint).
This class represents a cast from a pointer to an integer.
Value * getValue() const
Convenience accessor.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
This class represents a sign extension of integer types.
This class represents a cast from signed integer to floating point.
static LLVM_ABI const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
This instruction constructs a fixed permutation of two input vectors.
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
static LLVM_ABI void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static constexpr size_t npos
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
std::pair< typename Base::iterator, bool > insert(StringRef key)
unsigned getNumElements() const
Random access to the elements.
LLVM_ABI Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Returns true if this struct contains a scalable vector.
Verify that the TBAA Metadatas are valid.
LLVM_ABI bool visitTBAAMetadata(const Instruction *I, const MDNode *MD)
Visit an instruction, or a TBAA node itself as part of a metadata, and return true if it is valid,...
Triple - Helper class for working with autoconf configuration names.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isByteTy() const
True if this is an instance of ByteType.
bool isVectorTy() const
True if this is an instance of VectorType.
LLVM_ABI bool containsNonGlobalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a global...
bool isArrayTy() const
True if this is an instance of ArrayType.
LLVM_ABI bool containsNonLocalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a local.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
bool isLabelTy() const
Return true if this is 'label'.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI bool isTokenLikeTy() const
Returns true if this is 'token' or a token-like target type.s.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSingleValueType() const
Return true if the type is a valid type for a register in codegen.
LLVM_ABI bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
This class represents a cast unsigned integer to floating point.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
iterator_range< user_iterator > materialized_users()
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
iterator_range< user_iterator > users()
bool materialized_use_empty() const
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Check a module for errors, and report separate error states for IR and debug info errors.
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class represents zero extension of integer types.
std::pair< iterator, bool > insert(const ValueT &V)
constexpr bool isNonZero() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class implements an extremely fast bulk output stream that can only output to a stream.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char ReqdWorkGroupSize[]
Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool isFlatGlobalAddrSpace(unsigned AS)
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
static const int NoAliasScopeDeclScopeArg
LLVM_ABI bool isSignatureValid(Intrinsic::ID ID, FunctionType *FT, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS=nulls())
Returns true if FT is a valid function type for intrinsic ID.
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
@ CE
Windows NT (Windows on ARM)
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
@ DW_LLVM_LANG_DIALECT_max
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool canInstructionHaveMMRAs(const Instruction &I)
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
BundleAttr getBundleAttrFromOBU(OperandBundleUse OBU)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
testing::Matcher< const detail::ErrorHolder & > Failed()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
gep_type_iterator gep_type_end(const User *GEP)
bool isa_and_nonnull(const Y &Val)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
auto dyn_cast_or_null(const Y &Val)
GenericConvergenceVerifier< SSAContext > ConvergenceVerifier
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isModSet(const ModRefInfo MRI)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isPointerTy(const Type *T)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
generic_gep_type_iterator<> gep_type_iterator
FunctionAddr VTableAddr Count
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData)
Checks if an MDNode contains value profiling Metadata.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI unsigned getNumBranchWeights(const MDNode &ProfileData)
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
LLVM_ABI FunctionPass * createVerifierPass(bool FatalErrors=true)
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
TinyPtrVector< BasicBlock * > ColorVector
LLVM_ABI const char * LLVMLoopEstimatedTripCount
Profile-based loop metadata that should be accessed only by using llvm::getLoopEstimatedTripCount and...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
gep_type_iterator gep_type_begin(const User *GEP)
LLVM_ABI std::unique_ptr< GCStrategy > getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
bool to_integer(StringRef S, N &Num, unsigned Base=0)
Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...
constexpr bool isCallableCC(CallingConv::ID CC)
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static LLVM_ABI const char * SyntheticFunctionEntryCount
static LLVM_ABI const char * UnknownBranchWeightsMarker
static LLVM_ABI const char * ValueProfile
static LLVM_ABI const char * FunctionEntryCount
static LLVM_ABI const char * BranchWeights
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
void DebugInfoCheckFailed(const Twine &Message)
A debug info check failed.
VerifierSupport(raw_ostream *OS, const Module &M)
bool Broken
Track the brokenness of the module while recursively visiting.
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A check failed (with values to print).
bool BrokenDebugInfo
Broken debug info can be "recovered" from by stripping the debug info.
bool TreatBrokenDebugInfoAsError
Whether to treat broken debug info as an error.
void CheckFailed(const Twine &Message)
A check failed, so printout out the condition and the message.
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs)
A debug info check failed (with values to print).