96#include "llvm/IR/IntrinsicsAArch64.h"
97#include "llvm/IR/IntrinsicsAMDGPU.h"
98#include "llvm/IR/IntrinsicsARM.h"
99#include "llvm/IR/IntrinsicsNVPTX.h"
100#include "llvm/IR/IntrinsicsWebAssembly.h"
132 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
133 "scopes are not dominating"));
161 void Write(
const Value *V) {
166 void Write(
const Value &V) {
167 if (isa<Instruction>(V)) {
171 V.printAsOperand(*
OS,
true,
MST);
221 void Write(
Type *
T) {
233 void Write(
const APInt *AI) {
239 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
245 *
OS <<
A->getAsString() <<
'\n';
265 for (
const T &V : Vs)
269 template <
typename T1,
typename... Ts>
270 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
275 template <
typename... Ts>
void WriteTs() {}
284 *
OS << Message <<
'\n';
292 template <
typename T1,
typename... Ts>
302 *
OS << Message <<
'\n';
308 template <
typename T1,
typename... Ts>
329 static constexpr unsigned ParamMaxAlignment = 1 << 14;
349 Type *LandingPadResultTy;
356 bool HasDebugInfo =
false;
402 SawFrameEscape(
false), TBAAVerifyHelper(this) {
403 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
410 "An instance of this class only works with a specific module!");
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);
434 auto FailureCB = [
this](
const Twine &Message) {
442 verifySiblingFuncletUnwinds();
445 ConvergenceVerifyHelper.
verify(DT);
447 InstsInThisBlock.
clear();
449 LandingPadResultTy =
nullptr;
450 SawFrameEscape =
false;
451 SiblingFuncletInfo.
clear();
452 verifyNoAliasScopeDecl();
453 NoAliasScopeDecls.
clear();
464 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
469 verifyFrameRecoverIndices();
471 visitGlobalVariable(GV);
474 visitGlobalAlias(GA);
477 visitGlobalIFunc(GI);
480 visitNamedMDNode(NMD);
483 visitComdat(SMEC.getValue());
487 visitModuleCommandLines();
489 verifyCompileUnits();
491 verifyDeoptimizeCallingConvs();
492 DISubprogramAttachments.
clear();
498 enum class AreDebugLocsAllowed {
No,
Yes };
509 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
513 void visitComdat(
const Comdat &
C);
514 void visitModuleIdents();
515 void visitModuleCommandLines();
516 void visitModuleFlags();
517 void visitModuleFlag(
const MDNode *
Op,
520 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
523 void verifyRangeMetadata(
const Value &V,
const MDNode *Range,
Type *Ty,
524 bool IsAbsoluteSymbol);
528 void visitCallStackMetadata(
MDNode *MD);
532 void visitAnnotationMetadata(
MDNode *Annotation);
533 void visitAliasScopeMetadata(
const MDNode *MD);
534 void visitAliasScopeListMetadata(
const MDNode *MD);
535 void visitAccessGroupMetadata(
const MDNode *MD);
537 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
538#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
539#include "llvm/IR/Metadata.def"
540 void visitDIScope(
const DIScope &
N);
567 void visitPHINode(
PHINode &PN);
576 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
614 void verifySwiftErrorCall(
CallBase &Call,
const Value *SwiftErrorVal);
615 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
617 void verifyMustTailCall(
CallInst &CI);
618 bool verifyAttributeCount(
AttributeList Attrs,
unsigned Params);
624 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
625 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
627 void visitConstantExprsRecursively(
const Constant *EntryC);
629 void verifyInlineAsmCall(
const CallBase &Call);
630 void verifyStatepoint(
const CallBase &Call);
631 void verifyFrameRecoverIndices();
632 void verifySiblingFuncletUnwinds();
635 void verifyFragmentExpression(
const DPValue &
I);
636 template <
typename ValueOrMetadata>
637 void verifyFragmentExpression(
const DIVariable &V,
639 ValueOrMetadata *
Desc);
641 void verifyFnArgs(
const DPValue &DPV);
643 void verifyNotEntryValue(
const DPValue &
I);
646 void verifyCompileUnits();
650 void verifyDeoptimizeCallingConvs();
652 void verifyAttachedCallBundle(
const CallBase &Call,
656 void verifyNoAliasScopeDecl();
662#define Check(C, ...) \
665 CheckFailed(__VA_ARGS__); \
672#define CheckDI(C, ...) \
675 DebugInfoCheckFailed(__VA_ARGS__); \
683 CheckDI(
I.DbgMarker->MarkedInstr == &
I,
"Instruction has invalid DbgMarker",
685 CheckDI(!isa<PHINode>(&
I) || !
I.hasDbgRecords(),
686 "PHI Node must not have any attached DbgRecords", &
I);
692 visitMDNode(*Loc, AreDebugLocsAllowed::Yes);
693 if (
auto *DPV = dyn_cast<DPValue>(&DR)) {
697 verifyFragmentExpression(*DPV);
698 verifyNotEntryValue(*DPV);
699 }
else if (
auto *DPL = dyn_cast<DPLabel>(&DR)) {
707 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
708 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
721 while (!WorkList.
empty()) {
723 if (!Visited.
insert(Cur).second)
730void Verifier::visitGlobalValue(
const GlobalValue &GV) {
732 "Global is external, but doesn't have external or weak linkage!", &GV);
734 if (
const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
738 "huge alignment values are unsupported", GO);
741 if (
const MDNode *Associated =
742 GO->getMetadata(LLVMContext::MD_associated)) {
743 Check(Associated->getNumOperands() == 1,
744 "associated metadata must have one operand", &GV, Associated);
745 const Metadata *
Op = Associated->getOperand(0).get();
746 Check(
Op,
"associated metadata must have a global value", GO, Associated);
748 const auto *VM = dyn_cast_or_null<ValueAsMetadata>(
Op);
749 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
751 Check(isa<PointerType>(VM->getValue()->getType()),
752 "associated value must be pointer typed", GV, Associated);
755 Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
756 "associated metadata must point to a GlobalObject", GO, Stripped);
757 Check(Stripped != GO,
758 "global values should not associate to themselves", GO,
764 if (
const MDNode *AbsoluteSymbol =
765 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
766 verifyRangeMetadata(*GO, AbsoluteSymbol,
DL.getIntPtrType(GO->getType()),
772 "Only global variables can have appending linkage!", &GV);
777 "Only global arrays can have appending linkage!", GVar);
781 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
785 "dllexport GlobalValue must have default or protected visibility",
790 "dllimport GlobalValue must have default visibility", &GV);
791 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
797 "Global is marked as dllimport, but not external", &GV);
802 "GlobalValue with local linkage or non-default "
803 "visibility must be dso_local!",
808 if (!
I->getParent() || !
I->getParent()->getParent())
809 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
811 else if (
I->getParent()->getParent()->getParent() != &M)
812 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
813 I->getParent()->getParent(),
814 I->getParent()->getParent()->getParent());
816 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
817 if (
F->getParent() != &M)
818 CheckFailed(
"Global is used by function in a different module", &GV, &M,
829 "Global variable initializer type does not match global "
836 "'common' global must have a zero initializer!", &GV);
839 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
844 GV.
getName() ==
"llvm.global_dtors")) {
846 "invalid linkage for intrinsic global variable", &GV);
848 "invalid uses of intrinsic global variable", &GV);
853 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
859 "wrong type for intrinsic global variable", &GV);
861 "the third field of the element type is mandatory, "
862 "specify ptr null to migrate from the obsoleted 2-field form");
870 GV.
getName() ==
"llvm.compiler.used")) {
872 "invalid linkage for intrinsic global variable", &GV);
874 "invalid uses of intrinsic global variable", &GV);
877 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
878 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
879 Check(PTy,
"wrong type for intrinsic global variable", &GV);
883 Check(InitArray,
"wrong initalizer for intrinsic global variable",
887 Check(isa<GlobalVariable>(V) || isa<Function>(V) ||
891 Twine(
"members of ") + GV.
getName() +
" must be named", V);
900 for (
auto *MD : MDs) {
901 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
902 visitDIGlobalVariableExpression(*GVE);
904 CheckDI(
false,
"!dbg attachment of global variable must be a "
905 "DIGlobalVariableExpression");
911 "Globals cannot contain scalable types", &GV);
915 if (
auto *TTy = dyn_cast<TargetExtType>(GV.
getValueType()))
917 "Global @" + GV.
getName() +
" has illegal target extension type",
921 visitGlobalValue(GV);
928 visitGlobalValue(GV);
934 visitAliaseeSubExpr(Visited, GA,
C);
940 Check(isa<GlobalValue>(
C) &&
941 cast<GlobalValue>(
C).hasAvailableExternallyLinkage(),
942 "available_externally alias must point to available_externally "
946 if (
const auto *GV = dyn_cast<GlobalValue>(&
C)) {
952 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
953 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
955 Check(!GA2->isInterposable(),
956 "Alias cannot point to an interposable alias", &GA);
964 if (
const auto *CE = dyn_cast<ConstantExpr>(&
C))
965 visitConstantExprsRecursively(CE);
967 for (
const Use &U :
C.operands()) {
969 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
970 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
971 else if (
const auto *C2 = dyn_cast<Constant>(V))
972 visitAliaseeSubExpr(Visited, GA, *C2);
976void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
978 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
979 "weak_odr, external, or available_externally linkage!",
982 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
984 "Alias and aliasee types should match!", &GA);
986 Check(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
987 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
989 visitAliaseeSubExpr(GA, *Aliasee);
991 visitGlobalValue(GA);
994void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
996 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
997 "weak_odr, or external linkage!",
1002 Check(
Resolver,
"IFunc must have a Function resolver", &GI);
1004 "IFunc resolver must be a definition", &GI);
1010 Check(isa<PointerType>(
Resolver->getFunctionType()->getReturnType()),
1011 "IFunc resolver must return a pointer", &GI);
1013 const Type *ResolverFuncTy =
1016 "IFunc resolver has incorrect type", &GI);
1019void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1024 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1026 if (NMD.
getName() ==
"llvm.dbg.cu")
1027 CheckDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
1032 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1036void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1039 if (!MDNodes.
insert(&MD).second)
1043 "MDNode context does not match Module context!", &MD);
1048 case Metadata::MDTupleKind:
1050#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1051 case Metadata::CLASS##Kind: \
1052 visit##CLASS(cast<CLASS>(MD)); \
1054#include "llvm/IR/Metadata.def"
1060 Check(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
1062 CheckDI(!isa<DILocation>(
Op) || AllowLocs == AreDebugLocsAllowed::Yes,
1063 "DILocation not allowed within this metadata node", &MD,
Op);
1064 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
1065 visitMDNode(*
N, AllowLocs);
1068 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
1069 visitValueAsMetadata(*V,
nullptr);
1082 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1084 auto *
L = dyn_cast<LocalAsMetadata>(&MD);
1088 Check(
F,
"function-local metadata used outside a function", L);
1093 if (
Instruction *
I = dyn_cast<Instruction>(
L->getValue())) {
1094 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1095 ActualF =
I->getParent()->getParent();
1096 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(
L->getValue()))
1098 else if (
Argument *
A = dyn_cast<Argument>(
L->getValue()))
1099 ActualF =
A->getParent();
1100 assert(ActualF &&
"Unimplemented function local metadata case!");
1102 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1107 visitValueAsMetadata(*VAM,
F);
1112 if (
auto *
N = dyn_cast<MDNode>(MD)) {
1113 visitMDNode(*
N, AreDebugLocsAllowed::No);
1119 if (!MDNodes.
insert(MD).second)
1122 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
1123 visitValueAsMetadata(*V,
F);
1125 if (
auto *AL = dyn_cast<DIArgList>(MD))
1126 visitDIArgList(*AL,
F);
1133void Verifier::visitDILocation(
const DILocation &
N) {
1134 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1135 "location requires a valid scope", &
N,
N.getRawScope());
1136 if (
auto *IA =
N.getRawInlinedAt())
1137 CheckDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
1138 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1139 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1146void Verifier::visitDIScope(
const DIScope &
N) {
1147 if (
auto *
F =
N.getRawFile())
1148 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1151void Verifier::visitDISubrange(
const DISubrange &
N) {
1152 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1154 CheckDI(HasAssumedSizedArraySupport ||
N.getRawCountNode() ||
1155 N.getRawUpperBound(),
1156 "Subrange must contain count or upperBound", &
N);
1157 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1158 "Subrange can have any one of count or upperBound", &
N);
1159 auto *CBound =
N.getRawCountNode();
1160 CheckDI(!CBound || isa<ConstantAsMetadata>(CBound) ||
1161 isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1162 "Count must be signed constant or DIVariable or DIExpression", &
N);
1163 auto Count =
N.getCount();
1164 CheckDI(!Count || !isa<ConstantInt *>(Count) ||
1165 cast<ConstantInt *>(Count)->getSExtValue() >= -1,
1166 "invalid subrange count", &
N);
1167 auto *LBound =
N.getRawLowerBound();
1168 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1169 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1170 "LowerBound must be signed constant or DIVariable or DIExpression",
1172 auto *UBound =
N.getRawUpperBound();
1173 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1174 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1175 "UpperBound must be signed constant or DIVariable or DIExpression",
1177 auto *Stride =
N.getRawStride();
1178 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1179 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1180 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1184 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1185 CheckDI(
N.getRawCountNode() ||
N.getRawUpperBound(),
1186 "GenericSubrange must contain count or upperBound", &
N);
1187 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1188 "GenericSubrange can have any one of count or upperBound", &
N);
1189 auto *CBound =
N.getRawCountNode();
1190 CheckDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1191 "Count must be signed constant or DIVariable or DIExpression", &
N);
1192 auto *LBound =
N.getRawLowerBound();
1193 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1194 CheckDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1195 "LowerBound must be signed constant or DIVariable or DIExpression",
1197 auto *UBound =
N.getRawUpperBound();
1198 CheckDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1199 "UpperBound must be signed constant or DIVariable or DIExpression",
1201 auto *Stride =
N.getRawStride();
1202 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1203 CheckDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1204 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1208 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1212 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1213 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1214 N.getTag() == dwarf::DW_TAG_string_type,
1219 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1220 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1228 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1229 N.getTag() == dwarf::DW_TAG_pointer_type ||
1230 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1231 N.getTag() == dwarf::DW_TAG_reference_type ||
1232 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1233 N.getTag() == dwarf::DW_TAG_const_type ||
1234 N.getTag() == dwarf::DW_TAG_immutable_type ||
1235 N.getTag() == dwarf::DW_TAG_volatile_type ||
1236 N.getTag() == dwarf::DW_TAG_restrict_type ||
1237 N.getTag() == dwarf::DW_TAG_atomic_type ||
1238 N.getTag() == dwarf::DW_TAG_member ||
1239 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1240 N.getTag() == dwarf::DW_TAG_inheritance ||
1241 N.getTag() == dwarf::DW_TAG_friend ||
1242 N.getTag() == dwarf::DW_TAG_set_type,
1244 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1245 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1246 N.getRawExtraData());
1249 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1250 if (
auto *
T =
N.getRawBaseType()) {
1251 auto *
Enum = dyn_cast_or_null<DICompositeType>(
T);
1252 auto *
Basic = dyn_cast_or_null<DIBasicType>(
T);
1254 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1255 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1256 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1257 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1258 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1259 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1260 "invalid set base type", &
N,
T);
1266 N.getRawBaseType());
1268 if (
N.getDWARFAddressSpace()) {
1269 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1270 N.getTag() == dwarf::DW_TAG_reference_type ||
1271 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1272 "DWARF address space only applies to pointer or reference types",
1279 return ((Flags & DINode::FlagLValueReference) &&
1280 (Flags & DINode::FlagRValueReference)) ||
1281 ((Flags & DINode::FlagTypePassByValue) &&
1282 (Flags & DINode::FlagTypePassByReference));
1285void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1286 auto *Params = dyn_cast<MDTuple>(&RawParams);
1287 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1289 CheckDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
1298 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1299 N.getTag() == dwarf::DW_TAG_structure_type ||
1300 N.getTag() == dwarf::DW_TAG_union_type ||
1301 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1302 N.getTag() == dwarf::DW_TAG_class_type ||
1303 N.getTag() == dwarf::DW_TAG_variant_part ||
1304 N.getTag() == dwarf::DW_TAG_namelist,
1309 N.getRawBaseType());
1311 CheckDI(!
N.getRawElements() || isa<MDTuple>(
N.getRawElements()),
1312 "invalid composite elements", &
N,
N.getRawElements());
1314 N.getRawVTableHolder());
1316 "invalid reference flags", &
N);
1317 unsigned DIBlockByRefStruct = 1 << 4;
1318 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1319 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1322 const DINodeArray
Elements =
N.getElements();
1324 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1325 "invalid vector, expected one element of type subrange", &
N);
1328 if (
auto *Params =
N.getRawTemplateParams())
1329 visitTemplateParams(
N, *Params);
1331 if (
auto *
D =
N.getRawDiscriminator()) {
1332 CheckDI(isa<DIDerivedType>(
D) &&
N.getTag() == dwarf::DW_TAG_variant_part,
1333 "discriminator can only appear on variant part");
1336 if (
N.getRawDataLocation()) {
1337 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1338 "dataLocation can only appear in array type");
1341 if (
N.getRawAssociated()) {
1342 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1343 "associated can only appear in array type");
1346 if (
N.getRawAllocated()) {
1347 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1348 "allocated can only appear in array type");
1351 if (
N.getRawRank()) {
1352 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1353 "rank can only appear in array type");
1356 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1357 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1362 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1363 if (
auto *Types =
N.getRawTypeArray()) {
1364 CheckDI(isa<MDTuple>(Types),
"invalid composite elements", &
N, Types);
1365 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1366 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1370 "invalid reference flags", &
N);
1373void Verifier::visitDIFile(
const DIFile &
N) {
1374 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1375 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1378 "invalid checksum kind", &
N);
1380 switch (Checksum->Kind) {
1391 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1393 "invalid checksum", &
N);
1398 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1399 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1403 CheckDI(
N.getRawFile() && isa<DIFile>(
N.getRawFile()),
"invalid file", &
N,
1405 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1411 "invalid emission kind", &
N);
1413 if (
auto *Array =
N.getRawEnumTypes()) {
1414 CheckDI(isa<MDTuple>(Array),
"invalid enum list", &
N, Array);
1415 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1416 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1417 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1418 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1421 if (
auto *Array =
N.getRawRetainedTypes()) {
1422 CheckDI(isa<MDTuple>(Array),
"invalid retained type list", &
N, Array);
1423 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1425 Op && (isa<DIType>(
Op) || (isa<DISubprogram>(
Op) &&
1426 !cast<DISubprogram>(
Op)->isDefinition())),
1427 "invalid retained type", &
N,
Op);
1430 if (
auto *Array =
N.getRawGlobalVariables()) {
1431 CheckDI(isa<MDTuple>(Array),
"invalid global variable list", &
N, Array);
1432 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1433 CheckDI(
Op && (isa<DIGlobalVariableExpression>(
Op)),
1434 "invalid global variable ref", &
N,
Op);
1437 if (
auto *Array =
N.getRawImportedEntities()) {
1438 CheckDI(isa<MDTuple>(Array),
"invalid imported entity list", &
N, Array);
1439 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1440 CheckDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1444 if (
auto *Array =
N.getRawMacros()) {
1445 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1447 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1454 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1456 if (
auto *
F =
N.getRawFile())
1457 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1459 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1460 if (
auto *
T =
N.getRawType())
1461 CheckDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1462 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1463 N.getRawContainingType());
1464 if (
auto *Params =
N.getRawTemplateParams())
1465 visitTemplateParams(
N, *Params);
1466 if (
auto *S =
N.getRawDeclaration())
1467 CheckDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1468 "invalid subprogram declaration", &
N, S);
1469 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1470 auto *
Node = dyn_cast<MDTuple>(RawNode);
1471 CheckDI(
Node,
"invalid retained nodes list", &
N, RawNode);
1473 CheckDI(
Op && (isa<DILocalVariable>(
Op) || isa<DILabel>(
Op) ||
1474 isa<DIImportedEntity>(
Op)),
1475 "invalid retained nodes, expected DILocalVariable, DILabel or "
1481 "invalid reference flags", &
N);
1483 auto *Unit =
N.getRawUnit();
1484 if (
N.isDefinition()) {
1486 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1487 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1488 CheckDI(isa<DICompileUnit>(Unit),
"invalid unit type", &
N, Unit);
1491 auto *CT = dyn_cast_or_null<DICompositeType>(
N.getRawScope());
1492 if (CT && CT->getRawIdentifier() &&
1493 M.getContext().isODRUniquingDebugTypes())
1495 "definition subprograms cannot be nested within DICompositeType "
1496 "when enabling ODR",
1500 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1502 "subprogram declaration must not have a declaration field");
1505 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1506 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1507 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1509 CheckDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1513 if (
N.areAllCallsDescribed())
1515 "DIFlagAllCallsDescribed must be attached to a definition");
1519 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1520 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1521 "invalid local scope", &
N,
N.getRawScope());
1522 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1523 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1527 visitDILexicalBlockBase(
N);
1530 "cannot have column info without line info", &
N);
1534 visitDILexicalBlockBase(
N);
1538 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1539 if (
auto *S =
N.getRawScope())
1540 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1541 if (
auto *S =
N.getRawDecl())
1542 CheckDI(isa<DIGlobalVariable>(S),
"invalid declaration", &
N, S);
1546 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1547 if (
auto *S =
N.getRawScope())
1548 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1551void Verifier::visitDIMacro(
const DIMacro &
N) {
1554 "invalid macinfo type", &
N);
1555 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1556 if (!
N.getValue().empty()) {
1557 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1563 "invalid macinfo type", &
N);
1564 if (
auto *
F =
N.getRawFile())
1565 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1567 if (
auto *Array =
N.getRawElements()) {
1568 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1569 for (
Metadata *
Op :
N.getElements()->operands()) {
1570 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1575void Verifier::visitDIModule(
const DIModule &
N) {
1576 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1577 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1585 visitDITemplateParameter(
N);
1587 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1591void Verifier::visitDITemplateValueParameter(
1593 visitDITemplateParameter(
N);
1595 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1596 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1597 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1601void Verifier::visitDIVariable(
const DIVariable &
N) {
1602 if (
auto *S =
N.getRawScope())
1603 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1604 if (
auto *
F =
N.getRawFile())
1605 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1612 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1615 if (
N.isDefinition())
1616 CheckDI(
N.getType(),
"missing global variable type", &
N);
1617 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1618 CheckDI(isa<DIDerivedType>(Member),
1619 "invalid static data member declaration", &
N, Member);
1628 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1629 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1630 "local variable requires a valid scope", &
N,
N.getRawScope());
1631 if (
auto Ty =
N.getType())
1632 CheckDI(!isa<DISubroutineType>(Ty),
"invalid type", &
N,
N.getType());
1635void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1636 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1637 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1640void Verifier::visitDILabel(
const DILabel &
N) {
1641 if (
auto *S =
N.getRawScope())
1642 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1643 if (
auto *
F =
N.getRawFile())
1644 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1646 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1647 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1648 "label requires a valid scope", &
N,
N.getRawScope());
1652 CheckDI(
N.isValid(),
"invalid expression", &
N);
1655void Verifier::visitDIGlobalVariableExpression(
1659 visitDIGlobalVariable(*Var);
1661 visitDIExpression(*Expr);
1662 if (
auto Fragment = Expr->getFragmentInfo())
1663 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1668 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1669 if (
auto *
T =
N.getRawType())
1671 if (
auto *
F =
N.getRawFile())
1672 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1676 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1677 N.getTag() == dwarf::DW_TAG_imported_declaration,
1679 if (
auto *S =
N.getRawScope())
1680 CheckDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1685void Verifier::visitComdat(
const Comdat &
C) {
1688 if (
TT.isOSBinFormatCOFF())
1694void Verifier::visitModuleIdents() {
1695 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1702 Check(
N->getNumOperands() == 1,
1703 "incorrect number of operands in llvm.ident metadata",
N);
1704 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1705 (
"invalid value for llvm.ident metadata entry operand"
1706 "(the operand should be a string)"),
1711void Verifier::visitModuleCommandLines() {
1712 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1720 Check(
N->getNumOperands() == 1,
1721 "incorrect number of operands in llvm.commandline metadata",
N);
1722 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1723 (
"invalid value for llvm.commandline metadata entry operand"
1724 "(the operand should be a string)"),
1729void Verifier::visitModuleFlags() {
1737 visitModuleFlag(MDN, SeenIDs, Requirements);
1740 for (
const MDNode *Requirement : Requirements) {
1741 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1742 const Metadata *ReqValue = Requirement->getOperand(1);
1746 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1751 if (
Op->getOperand(2) != ReqValue) {
1752 CheckFailed((
"invalid requirement on flag, "
1753 "flag does not have the required value"),
1761Verifier::visitModuleFlag(
const MDNode *
Op,
1767 "incorrect number of operands in module flag",
Op);
1770 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)),
1771 "invalid behavior operand in module flag (expected constant integer)",
1774 "invalid behavior operand in module flag (unexpected constant)",
1777 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
1778 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1790 auto *
V = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1791 Check(V &&
V->getValue().isNonNegative(),
1792 "invalid value for 'min' module flag (expected constant non-negative "
1799 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2)),
1800 "invalid value for 'max' module flag (expected constant integer)",
1810 "invalid value for 'require' module flag (expected metadata pair)",
1813 (
"invalid value for 'require' module flag "
1814 "(first value operand should be a string)"),
1815 Value->getOperand(0));
1826 Check(isa<MDNode>(
Op->getOperand(2)),
1827 "invalid value for 'append'-type module flag "
1828 "(expected a metadata node)",
1838 "module flag identifiers must be unique (or of 'require' type)",
ID);
1841 if (
ID->getString() ==
"wchar_size") {
1843 = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1844 Check(
Value,
"wchar_size metadata requires constant integer argument");
1847 if (
ID->getString() ==
"Linker Options") {
1851 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1852 "'Linker Options' named metadata no longer supported");
1855 if (
ID->getString() ==
"SemanticInterposition") {
1857 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1859 "SemanticInterposition metadata requires constant integer argument");
1862 if (
ID->getString() ==
"CG Profile") {
1863 for (
const MDOperand &MDO : cast<MDNode>(
Op->getOperand(2))->operands())
1864 visitModuleFlagCGProfileEntry(MDO);
1868void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1869 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1872 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1873 Check(
F && isa<Function>(
F->getValue()->stripPointerCasts()),
1874 "expected a Function or null", FuncMDO);
1876 auto Node = dyn_cast_or_null<MDNode>(MDO);
1877 Check(
Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1878 CheckFunction(
Node->getOperand(0));
1879 CheckFunction(
Node->getOperand(1));
1880 auto Count = dyn_cast_or_null<ConstantAsMetadata>(
Node->getOperand(2));
1881 Check(Count && Count->getType()->isIntegerTy(),
1882 "expected an integer constant",
Node->getOperand(2));
1888 if (
A.isStringAttribute()) {
1889#define GET_ATTR_NAMES
1890#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1891#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1892 if (A.getKindAsString() == #DISPLAY_NAME) { \
1893 auto V = A.getValueAsString(); \
1894 if (!(V.empty() || V == "true" || V == "false")) \
1895 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1899#include "llvm/IR/Attributes.inc"
1904 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1915 if (!
Attrs.hasAttributes())
1918 verifyAttributeTypes(Attrs, V);
1921 Check(Attr.isStringAttribute() ||
1923 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
1926 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
1928 "Attribute 'immarg' is incompatible with other attributes", V);
1933 unsigned AttrCount = 0;
1934 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
1935 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
1936 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
1937 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
1938 Attrs.hasAttribute(Attribute::InReg);
1939 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
1940 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
1941 Check(AttrCount <= 1,
1942 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
1943 "'byref', and 'sret' are incompatible!",
1946 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
1947 Attrs.hasAttribute(Attribute::ReadOnly)),
1949 "'inalloca and readonly' are incompatible!",
1952 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
1953 Attrs.hasAttribute(Attribute::Returned)),
1955 "'sret and returned' are incompatible!",
1958 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
1959 Attrs.hasAttribute(Attribute::SExt)),
1961 "'zeroext and signext' are incompatible!",
1964 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1965 Attrs.hasAttribute(Attribute::ReadOnly)),
1967 "'readnone and readonly' are incompatible!",
1970 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1971 Attrs.hasAttribute(Attribute::WriteOnly)),
1973 "'readnone and writeonly' are incompatible!",
1976 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
1977 Attrs.hasAttribute(Attribute::WriteOnly)),
1979 "'readonly and writeonly' are incompatible!",
1982 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
1983 Attrs.hasAttribute(Attribute::AlwaysInline)),
1985 "'noinline and alwaysinline' are incompatible!",
1988 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
1989 Attrs.hasAttribute(Attribute::ReadNone)),
1990 "Attributes writable and readnone are incompatible!", V);
1992 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
1993 Attrs.hasAttribute(Attribute::ReadOnly)),
1994 "Attributes writable and readonly are incompatible!", V);
1998 if (!Attr.isStringAttribute() &&
1999 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2000 CheckFailed(
"Attribute '" + Attr.getAsString() +
2001 "' applied to incompatible type!", V);
2006 if (isa<PointerType>(Ty)) {
2007 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2008 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2009 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2010 Align MaxAlign(ParamMaxAlignment);
2011 Check(AttrAlign <= MaxAlign,
2012 "Attribute 'align' exceed the max size 2^14", V);
2015 Check(
Attrs.getByValType()->isSized(&Visited),
2016 "Attribute 'byval' does not support unsized types!", V);
2018 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2020 Check(
Attrs.getByRefType()->isSized(&Visited),
2021 "Attribute 'byref' does not support unsized types!", V);
2023 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2025 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2026 "Attribute 'inalloca' does not support unsized types!", V);
2028 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2030 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2031 "Attribute 'preallocated' does not support unsized types!", V);
2035 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2036 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2037 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2040 "Invalid value for 'nofpclass' test mask", V);
2042 if (
Attrs.hasAttribute(Attribute::Range)) {
2043 auto CR =
Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2045 "Range bit width must match type bit width!", V);
2051 if (
Attrs.hasFnAttr(Attr)) {
2055 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2062 const Value *V,
bool IsIntrinsic,
2064 if (
Attrs.isEmpty())
2067 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2069 "Attribute list does not match Module context!", &Attrs, V);
2070 for (
const auto &AttrSet : Attrs) {
2071 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
2072 "Attribute set does not match Module context!", &AttrSet, V);
2073 for (
const auto &
A : AttrSet) {
2074 Check(
A.hasParentContext(Context),
2075 "Attribute does not match Module context!", &
A, V);
2080 bool SawNest =
false;
2081 bool SawReturned =
false;
2082 bool SawSRet =
false;
2083 bool SawSwiftSelf =
false;
2084 bool SawSwiftAsync =
false;
2085 bool SawSwiftError =
false;
2092 "Attribute '" +
RetAttr.getAsString() +
2093 "' does not apply to function return values",
2096 unsigned MaxParameterWidth = 0;
2097 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2099 if (
auto *VT = dyn_cast<FixedVectorType>(Ty)) {
2100 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2101 if (
Size > MaxParameterWidth)
2102 MaxParameterWidth =
Size;
2106 GetMaxParameterWidth(FT->getReturnType());
2107 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2110 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2111 Type *Ty = FT->getParamType(i);
2116 "immarg attribute only applies to intrinsics", V);
2119 "Attribute 'elementtype' can only be applied to intrinsics"
2124 verifyParameterAttrs(ArgAttrs, Ty, V);
2125 GetMaxParameterWidth(Ty);
2128 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2133 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2135 "Incompatible argument and return types for 'returned' attribute",
2141 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2142 Check(i == 0 || i == 1,
2143 "Attribute 'sret' is not on first or second parameter!", V);
2148 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2149 SawSwiftSelf =
true;
2153 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2154 SawSwiftAsync =
true;
2158 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2159 SawSwiftError =
true;
2163 Check(i == FT->getNumParams() - 1,
2164 "inalloca isn't on the last parameter!", V);
2168 if (!
Attrs.hasFnAttrs())
2171 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2175 "Attribute '" +
FnAttr.getAsString() +
2176 "' does not apply to functions!",
2179 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2180 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2181 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2183 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2185 "Attribute 'optnone' requires 'noinline'!", V);
2187 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2188 "Attributes 'optsize and optnone' are incompatible!", V);
2191 "Attributes 'minsize and optnone' are incompatible!", V);
2193 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2194 "Attributes 'optdebug and optnone' are incompatible!", V);
2197 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2198 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2199 "Attributes 'optsize and optdebug' are incompatible!", V);
2202 "Attributes 'minsize and optdebug' are incompatible!", V);
2205 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2207 "Attribute writable and memory without argmem: write are incompatible!",
2210 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2211 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2212 "Attributes 'aarch64_pstate_sm_enabled and "
2213 "aarch64_pstate_sm_compatible' are incompatible!",
2217 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2218 Attrs.hasFnAttr(
"aarch64_inout_za") +
2219 Attrs.hasFnAttr(
"aarch64_out_za") +
2220 Attrs.hasFnAttr(
"aarch64_preserves_za")) <= 1,
2221 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2222 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
2226 (
Attrs.hasFnAttr(
"aarch64_new_zt0") +
Attrs.hasFnAttr(
"aarch64_in_zt0") +
2227 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2228 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2229 Attrs.hasFnAttr(
"aarch64_preserves_zt0")) <= 1,
2230 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2231 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive",
2234 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2237 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2240 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2242 if (ParamNo >= FT->getNumParams()) {
2243 CheckFailed(
"'allocsize' " +
Name +
" argument is out of bounds", V);
2247 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2248 CheckFailed(
"'allocsize' " +
Name +
2249 " argument must refer to an integer parameter",
2257 if (!CheckParam(
"element size",
Args->first))
2260 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2264 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2272 "'allockind()' requires exactly one of alloc, realloc, and free");
2276 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2277 "or aligned modifiers.");
2279 if ((K & ZeroedUninit) == ZeroedUninit)
2280 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2283 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2284 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2286 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2288 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2289 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2290 if (VScaleMax && VScaleMin > VScaleMax)
2291 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2293 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2296 if (
Attrs.hasFnAttr(
"frame-pointer")) {
2298 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none")
2299 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2303 if (MaxParameterWidth >= 512 &&
Attrs.hasFnAttr(
"target-features") &&
2305 StringRef TF =
Attrs.getFnAttr(
"target-features").getValueAsString();
2307 "512-bit vector arguments require 'evex512' for AVX512", V);
2310 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2311 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2312 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2314 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2316 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2317 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2320 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2322 if (S !=
"a_key" && S !=
"b_key")
2323 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2327 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2329 if (S !=
"true" && S !=
"false")
2331 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2334 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2338 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2342void Verifier::verifyFunctionMetadata(
2343 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2344 for (
const auto &Pair : MDs) {
2345 if (Pair.first == LLVMContext::MD_prof) {
2346 MDNode *MD = Pair.second;
2348 "!prof annotations should have no less than 2 operands", MD);
2351 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2354 "expected string with name of the !prof annotation", MD);
2358 ProfName.
equals(
"synthetic_function_entry_count"),
2359 "first operand should be 'function_entry_count'"
2360 " or 'synthetic_function_entry_count'",
2364 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2367 "expected integer argument to function_entry_count", MD);
2368 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2369 MDNode *MD = Pair.second;
2371 "!kcfi_type must have exactly one operand", MD);
2372 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2375 "expected a constant operand for !kcfi_type", MD);
2377 Check(isa<ConstantInt>(
C) && isa<IntegerType>(
C->getType()),
2378 "expected a constant integer operand for !kcfi_type", MD);
2380 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2385void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2386 if (!ConstantExprVisited.
insert(EntryC).second)
2390 Stack.push_back(EntryC);
2392 while (!
Stack.empty()) {
2396 if (
const auto *CE = dyn_cast<ConstantExpr>(
C))
2397 visitConstantExpr(CE);
2399 if (
const auto *GV = dyn_cast<GlobalValue>(
C)) {
2402 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2408 for (
const Use &U :
C->operands()) {
2409 const auto *OpC = dyn_cast<Constant>(U);
2412 if (!ConstantExprVisited.
insert(OpC).second)
2414 Stack.push_back(OpC);
2419void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2420 if (
CE->getOpcode() == Instruction::BitCast)
2423 "Invalid bitcast", CE);
2426bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
2429 return Attrs.getNumAttrSets() <= Params + 2;
2432void Verifier::verifyInlineAsmCall(
const CallBase &Call) {
2435 unsigned LabelNo = 0;
2446 if (CI.isIndirect) {
2447 const Value *Arg =
Call.getArgOperand(ArgNo);
2449 "Operand for indirect constraint must have pointer type", &Call);
2452 "Operand for indirect constraint must have elementtype attribute",
2455 Check(!
Call.paramHasAttr(ArgNo, Attribute::ElementType),
2456 "Elementtype attribute can only be applied for indirect "
2464 if (
auto *CallBr = dyn_cast<CallBrInst>(&Call)) {
2465 Check(LabelNo == CallBr->getNumIndirectDests(),
2466 "Number of label constraints does not match number of callbr dests",
2469 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2475void Verifier::verifyStatepoint(
const CallBase &Call) {
2477 Call.getCalledFunction()->getIntrinsicID() ==
2478 Intrinsic::experimental_gc_statepoint);
2480 Check(!
Call.doesNotAccessMemory() && !
Call.onlyReadsMemory() &&
2481 !
Call.onlyAccessesArgMemory(),
2482 "gc.statepoint must read and write all memory to preserve "
2483 "reordering restrictions required by safepoint semantics",
2486 const int64_t NumPatchBytes =
2487 cast<ConstantInt>(
Call.getArgOperand(1))->getSExtValue();
2488 assert(isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
2489 Check(NumPatchBytes >= 0,
2490 "gc.statepoint number of patchable bytes must be "
2494 Type *TargetElemType =
Call.getParamElementType(2);
2495 Check(TargetElemType,
2496 "gc.statepoint callee argument must have elementtype attribute", Call);
2497 FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
2498 Check(TargetFuncType,
2499 "gc.statepoint callee elementtype must be function type", Call);
2501 const int NumCallArgs = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
2502 Check(NumCallArgs >= 0,
2503 "gc.statepoint number of arguments to underlying call "
2506 const int NumParams = (int)TargetFuncType->getNumParams();
2507 if (TargetFuncType->isVarArg()) {
2508 Check(NumCallArgs >= NumParams,
2509 "gc.statepoint mismatch in number of vararg call args", Call);
2512 Check(TargetFuncType->getReturnType()->isVoidTy(),
2513 "gc.statepoint doesn't support wrapping non-void "
2514 "vararg functions yet",
2517 Check(NumCallArgs == NumParams,
2518 "gc.statepoint mismatch in number of call args", Call);
2521 = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
2523 "unknown flag used in gc.statepoint flags argument", Call);
2528 for (
int i = 0; i < NumParams; i++) {
2529 Type *ParamType = TargetFuncType->getParamType(i);
2530 Type *ArgType =
Call.getArgOperand(5 + i)->getType();
2531 Check(ArgType == ParamType,
2532 "gc.statepoint call argument does not match wrapped "
2536 if (TargetFuncType->isVarArg()) {
2539 "Attribute 'sret' cannot be used for vararg call arguments!", Call);
2543 const int EndCallArgsInx = 4 + NumCallArgs;
2545 const Value *NumTransitionArgsV =
Call.getArgOperand(EndCallArgsInx + 1);
2546 Check(isa<ConstantInt>(NumTransitionArgsV),
2547 "gc.statepoint number of transition arguments "
2548 "must be constant integer",
2550 const int NumTransitionArgs =
2551 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2552 Check(NumTransitionArgs == 0,
2553 "gc.statepoint w/inline transition bundle is deprecated", Call);
2554 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2556 const Value *NumDeoptArgsV =
Call.getArgOperand(EndTransitionArgsInx + 1);
2557 Check(isa<ConstantInt>(NumDeoptArgsV),
2558 "gc.statepoint number of deoptimization arguments "
2559 "must be constant integer",
2561 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2562 Check(NumDeoptArgs == 0,
2563 "gc.statepoint w/inline deopt operands is deprecated", Call);
2565 const int ExpectedNumArgs = 7 + NumCallArgs;
2566 Check(ExpectedNumArgs == (
int)
Call.arg_size(),
2567 "gc.statepoint too many arguments", Call);
2572 for (
const User *U :
Call.users()) {
2573 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2574 Check(UserCall,
"illegal use of statepoint token", Call, U);
2577 Check(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),
2578 "gc.result or gc.relocate are the only value uses "
2579 "of a gc.statepoint",
2581 if (isa<GCResultInst>(UserCall)) {
2583 "gc.result connected to wrong gc.statepoint", Call, UserCall);
2584 }
else if (isa<GCRelocateInst>(Call)) {
2586 "gc.relocate connected to wrong gc.statepoint", Call, UserCall);
2600void Verifier::verifyFrameRecoverIndices() {
2601 for (
auto &Counts : FrameEscapeInfo) {
2603 unsigned EscapedObjectCount = Counts.second.first;
2604 unsigned MaxRecoveredIndex = Counts.second.second;
2605 Check(MaxRecoveredIndex <= EscapedObjectCount,
2606 "all indices passed to llvm.localrecover must be less than the "
2607 "number of arguments passed to llvm.localescape in the parent "
2615 if (
auto *II = dyn_cast<InvokeInst>(Terminator))
2616 UnwindDest = II->getUnwindDest();
2617 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2618 UnwindDest = CSI->getUnwindDest();
2620 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2624void Verifier::verifySiblingFuncletUnwinds() {
2627 for (
const auto &Pair : SiblingFuncletInfo) {
2629 if (Visited.
count(PredPad))
2635 if (Active.
count(SuccPad)) {
2641 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2642 if (CycleTerminator != CyclePad)
2645 }
while (CyclePad != SuccPad);
2646 Check(
false,
"EH pads can't handle each other's exceptions",
2650 if (!Visited.
insert(SuccPad).second)
2654 auto TermI = SiblingFuncletInfo.find(PredPad);
2655 if (TermI == SiblingFuncletInfo.end())
2668void Verifier::visitFunction(
const Function &
F) {
2669 visitGlobalValue(
F);
2673 unsigned NumArgs =
F.arg_size();
2675 Check(&Context == &
F.getContext(),
2676 "Function context does not match Module context!", &
F);
2678 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2679 Check(FT->getNumParams() == NumArgs,
2680 "# formal arguments must match # of arguments for function type!", &
F,
2682 Check(
F.getReturnType()->isFirstClassType() ||
2683 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2684 "Functions cannot return aggregate values!", &
F);
2686 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2687 "Invalid struct return type!", &
F);
2691 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2692 "Attribute after last parameter!", &
F);
2694 CheckDI(
F.IsNewDbgInfoFormat ==
F.getParent()->IsNewDbgInfoFormat,
2695 "Function debug format should match parent module", &
F,
2696 F.IsNewDbgInfoFormat,
F.getParent(),
2697 F.getParent()->IsNewDbgInfoFormat);
2699 bool IsIntrinsic =
F.isIntrinsic();
2702 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2708 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2710 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2711 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2716 switch (
F.getCallingConv()) {
2721 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2722 "Calling convention parameter requires byval", &
F);
2729 Check(
F.getReturnType()->isVoidTy(),
2730 "Calling convention requires void return type", &
F);
2737 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2739 const unsigned StackAS =
DL.getAllocaAddrSpace();
2742 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2743 "Calling convention disallows byval", &
F);
2744 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2745 "Calling convention disallows preallocated", &
F);
2746 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2747 "Calling convention disallows inalloca", &
F);
2749 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2752 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2753 "Calling convention disallows stack byref", &
F);
2767 "Calling convention does not support varargs or "
2768 "perfect forwarding!",
2776 Check(Arg.getType() == FT->getParamType(i),
2777 "Argument value does not match function argument type!", &Arg,
2778 FT->getParamType(i));
2779 Check(Arg.getType()->isFirstClassType(),
2780 "Function arguments must have first-class types!", &Arg);
2782 Check(!Arg.getType()->isMetadataTy(),
2783 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
2784 Check(!Arg.getType()->isTokenTy(),
2785 "Function takes token but isn't an intrinsic", &Arg, &
F);
2786 Check(!Arg.getType()->isX86_AMXTy(),
2787 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
2791 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
2792 verifySwiftErrorValue(&Arg);
2798 Check(!
F.getReturnType()->isTokenTy(),
2799 "Function returns a token but isn't an intrinsic", &
F);
2800 Check(!
F.getReturnType()->isX86_AMXTy(),
2801 "Function returns a x86_amx but isn't an intrinsic", &
F);
2806 F.getAllMetadata(MDs);
2807 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
2808 verifyFunctionMetadata(MDs);
2811 if (
F.hasPersonalityFn()) {
2812 auto *Per = dyn_cast<Function>(
F.getPersonalityFn()->stripPointerCasts());
2814 Check(Per->getParent() ==
F.getParent(),
2815 "Referencing personality function in another module!", &
F,
2816 F.getParent(), Per, Per->getParent());
2820 BlockEHFuncletColors.
clear();
2822 if (
F.isMaterializable()) {
2824 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
2826 }
else if (
F.isDeclaration()) {
2827 for (
const auto &
I : MDs) {
2829 CheckDI(
I.first != LLVMContext::MD_dbg ||
2830 !cast<DISubprogram>(
I.second)->isDistinct(),
2831 "function declaration may only have a unique !dbg attachment",
2833 Check(
I.first != LLVMContext::MD_prof,
2834 "function declaration may not have a !prof attachment", &
F);
2837 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
2839 Check(!
F.hasPersonalityFn(),
2840 "Function declaration shouldn't have a personality routine", &
F);
2844 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
2849 "Entry block to function must not have predecessors!", Entry);
2852 if (Entry->hasAddressTaken()) {
2854 "blockaddress may not be used with the entry block!", Entry);
2857 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
2858 NumKCFIAttachments = 0;
2860 for (
const auto &
I : MDs) {
2862 auto AllowLocs = AreDebugLocsAllowed::No;
2866 case LLVMContext::MD_dbg: {
2867 ++NumDebugAttachments;
2868 CheckDI(NumDebugAttachments == 1,
2869 "function must have a single !dbg attachment", &
F,
I.second);
2870 CheckDI(isa<DISubprogram>(
I.second),
2871 "function !dbg attachment must be a subprogram", &
F,
I.second);
2872 CheckDI(cast<DISubprogram>(
I.second)->isDistinct(),
2873 "function definition may only have a distinct !dbg attachment",
2876 auto *SP = cast<DISubprogram>(
I.second);
2877 const Function *&AttachedTo = DISubprogramAttachments[SP];
2878 CheckDI(!AttachedTo || AttachedTo == &
F,
2879 "DISubprogram attached to more than one function", SP, &
F);
2881 AllowLocs = AreDebugLocsAllowed::Yes;
2884 case LLVMContext::MD_prof:
2885 ++NumProfAttachments;
2886 Check(NumProfAttachments == 1,
2887 "function must have a single !prof attachment", &
F,
I.second);
2889 case LLVMContext::MD_kcfi_type:
2890 ++NumKCFIAttachments;
2891 Check(NumKCFIAttachments == 1,
2892 "function must have a single !kcfi_type attachment", &
F,
2898 visitMDNode(*
I.second, AllowLocs);
2906 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
2908 if (
F.hasAddressTaken(&U,
false,
true,
false,
2910 Check(
false,
"Invalid user of intrinsic instruction!", U);
2914 switch (
F.getIntrinsicID()) {
2915 case Intrinsic::experimental_gc_get_pointer_base: {
2917 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2918 Check(isa<PointerType>(
F.getReturnType()),
2919 "gc.get.pointer.base must return a pointer",
F);
2920 Check(FT->getParamType(0) ==
F.getReturnType(),
2921 "gc.get.pointer.base operand and result must be of the same type",
F);
2924 case Intrinsic::experimental_gc_get_pointer_offset: {
2926 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2927 Check(isa<PointerType>(FT->getParamType(0)),
2928 "gc.get.pointer.offset operand must be a pointer",
F);
2929 Check(
F.getReturnType()->isIntegerTy(),
2930 "gc.get.pointer.offset must return integer",
F);
2935 auto *
N =
F.getSubprogram();
2936 HasDebugInfo = (
N !=
nullptr);
2955 CheckDI(Parent && isa<DILocalScope>(Parent),
2956 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
2959 Check(Scope,
"Failed to find DILocalScope",
DL);
2961 if (!Seen.
insert(Scope).second)
2968 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
2972 "!dbg attachment points at wrong subprogram for function",
N, &
F,
2976 for (
auto &
I : BB) {
2977 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
2979 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
2981 VisitDebugLoc(
I, dyn_cast_or_null<MDNode>(MD->
getOperand(i)));
2982 if (BrokenDebugInfo)
2989void Verifier::visitBasicBlock(
BasicBlock &BB) {
2990 InstsInThisBlock.
clear();
2991 ConvergenceVerifyHelper.
visit(BB);
2998 if (isa<PHINode>(BB.
front())) {
3003 Check(PN.getNumIncomingValues() == Preds.size(),
3004 "PHINode should have one entry for each predecessor of its "
3005 "parent basic block!",
3010 Values.
reserve(PN.getNumIncomingValues());
3011 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3013 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3016 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3021 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3022 Values[i].second == Values[i - 1].second,
3023 "PHI node has multiple entries for the same basic block with "
3024 "different incoming values!",
3025 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3029 Check(Values[i].first == Preds[i],
3030 "PHI node entries do not match predecessors!", &PN,
3031 Values[i].first, Preds[i]);
3039 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3042 CheckDI(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
3043 "BB debug format should match parent function", &BB,
3044 BB.IsNewDbgInfoFormat, BB.getParent(),
3045 BB.getParent()->IsNewDbgInfoFormat);
3048 if (BB.IsNewDbgInfoFormat)
3049 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3055 Check(&
I ==
I.getParent()->getTerminator(),
3056 "Terminator found in the middle of a basic block!",
I.getParent());
3060void Verifier::visitBranchInst(
BranchInst &BI) {
3063 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3068void Verifier::visitReturnInst(
ReturnInst &RI) {
3071 if (
F->getReturnType()->isVoidTy())
3073 "Found return instr that returns non-void in Function of void "
3075 &RI,
F->getReturnType());
3078 "Function return type does not match operand "
3079 "type of return inst!",
3080 &RI,
F->getReturnType());
3087void Verifier::visitSwitchInst(
SwitchInst &SI) {
3088 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3091 Type *SwitchTy =
SI.getCondition()->getType();
3093 for (
auto &Case :
SI.cases()) {
3094 Check(isa<ConstantInt>(
SI.getOperand(Case.getCaseIndex() * 2 + 2)),
3095 "Case value is not a constant integer.", &SI);
3096 Check(Case.getCaseValue()->getType() == SwitchTy,
3097 "Switch constants must all be same type as switch value!", &SI);
3099 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3107 "Indirectbr operand must have pointer type!", &BI);
3110 "Indirectbr destinations must all have pointer type!", &BI);
3115void Verifier::visitCallBrInst(
CallBrInst &CBI) {
3116 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3118 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3120 verifyInlineAsmCall(CBI);
3124void Verifier::visitSelectInst(
SelectInst &SI) {
3127 "Invalid operands for select instruction!", &SI);
3129 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3130 "Select values must have same type as select instruction!", &SI);
3138 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3143 Type *SrcTy =
I.getOperand(0)->getType();
3144 Type *DestTy =
I.getType();
3153 "trunc source and destination must both be a vector or neither", &
I);
3154 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3159void Verifier::visitZExtInst(
ZExtInst &
I) {
3161 Type *SrcTy =
I.getOperand(0)->getType();
3162 Type *DestTy =
I.getType();
3168 "zext source and destination must both be a vector or neither", &
I);
3172 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3177void Verifier::visitSExtInst(
SExtInst &
I) {
3179 Type *SrcTy =
I.getOperand(0)->getType();
3180 Type *DestTy =
I.getType();
3189 "sext source and destination must both be a vector or neither", &
I);
3190 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3197 Type *SrcTy =
I.getOperand(0)->getType();
3198 Type *DestTy =
I.getType();
3206 "fptrunc source and destination must both be a vector or neither", &
I);
3207 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3214 Type *SrcTy =
I.getOperand(0)->getType();
3215 Type *DestTy =
I.getType();
3224 "fpext source and destination must both be a vector or neither", &
I);
3225 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3232 Type *SrcTy =
I.getOperand(0)->getType();
3233 Type *DestTy =
I.getType();
3238 Check(SrcVec == DstVec,
3239 "UIToFP source and dest must both be vector or scalar", &
I);
3241 "UIToFP source must be integer or integer vector", &
I);
3245 if (SrcVec && DstVec)
3246 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3247 cast<VectorType>(DestTy)->getElementCount(),
3248 "UIToFP source and dest vector length mismatch", &
I);
3255 Type *SrcTy =
I.getOperand(0)->getType();
3256 Type *DestTy =
I.getType();
3261 Check(SrcVec == DstVec,
3262 "SIToFP source and dest must both be vector or scalar", &
I);
3264 "SIToFP source must be integer or integer vector", &
I);
3268 if (SrcVec && DstVec)
3269 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3270 cast<VectorType>(DestTy)->getElementCount(),
3271 "SIToFP source and dest vector length mismatch", &
I);
3278 Type *SrcTy =
I.getOperand(0)->getType();
3279 Type *DestTy =
I.getType();
3284 Check(SrcVec == DstVec,
3285 "FPToUI source and dest must both be vector or scalar", &
I);
3288 "FPToUI result must be integer or integer vector", &
I);
3290 if (SrcVec && DstVec)
3291 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3292 cast<VectorType>(DestTy)->getElementCount(),
3293 "FPToUI source and dest vector length mismatch", &
I);
3300 Type *SrcTy =
I.getOperand(0)->getType();
3301 Type *DestTy =
I.getType();
3306 Check(SrcVec == DstVec,
3307 "FPToSI source and dest must both be vector or scalar", &
I);
3310 "FPToSI result must be integer or integer vector", &
I);
3312 if (SrcVec && DstVec)
3313 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3314 cast<VectorType>(DestTy)->getElementCount(),
3315 "FPToSI source and dest vector length mismatch", &
I);
3322 Type *SrcTy =
I.getOperand(0)->getType();
3323 Type *DestTy =
I.getType();
3332 auto *VSrc = cast<VectorType>(SrcTy);
3333 auto *VDest = cast<VectorType>(DestTy);
3334 Check(VSrc->getElementCount() == VDest->getElementCount(),
3335 "PtrToInt Vector width mismatch", &
I);
3343 Type *SrcTy =
I.getOperand(0)->getType();
3344 Type *DestTy =
I.getType();
3352 auto *VSrc = cast<VectorType>(SrcTy);
3353 auto *VDest = cast<VectorType>(DestTy);
3354 Check(VSrc->getElementCount() == VDest->getElementCount(),
3355 "IntToPtr Vector width mismatch", &
I);
3363 "Invalid bitcast", &
I);
3368 Type *SrcTy =
I.getOperand(0)->getType();
3369 Type *DestTy =
I.getType();
3376 "AddrSpaceCast must be between different address spaces", &
I);
3377 if (
auto *SrcVTy = dyn_cast<VectorType>(SrcTy))
3378 Check(SrcVTy->getElementCount() ==
3379 cast<VectorType>(DestTy)->getElementCount(),
3380 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3386void Verifier::visitPHINode(
PHINode &PN) {
3393 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3402 "PHI node operands are not the same type as the result!", &PN);
3410void Verifier::visitCallBase(
CallBase &Call) {
3411 Check(
Call.getCalledOperand()->getType()->isPointerTy(),
3412 "Called function must be a pointer!", Call);
3416 if (FTy->isVarArg())
3417 Check(
Call.arg_size() >= FTy->getNumParams(),
3418 "Called function requires more parameters than were provided!", Call);
3420 Check(
Call.arg_size() == FTy->getNumParams(),
3421 "Incorrect number of arguments passed to called function!", Call);
3424 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3425 Check(
Call.getArgOperand(i)->getType() == FTy->getParamType(i),
3426 "Call parameter type does not match function signature!",
3427 Call.getArgOperand(i), FTy->getParamType(i), Call);
3431 Check(verifyAttributeCount(Attrs,
Call.arg_size()),
3432 "Attribute after last parameter!", Call);
3435 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
3439 "Intrinsic called with incompatible signature", Call);
3443 auto CC =
Call.getCallingConv();
3446 "Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions "
3447 "not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.",
3450 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3453 Align ABIAlign =
DL.getABITypeAlign(Ty);
3454 Align MaxAlign(ParamMaxAlignment);
3455 Check(ABIAlign <= MaxAlign,
3456 "Incorrect alignment of " + Message +
" to called function!", Call);
3460 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3461 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3462 Type *Ty = FTy->getParamType(i);
3463 VerifyTypeAlign(Ty,
"argument passed");
3467 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3471 "speculatable attribute may not apply to call sites", Call);
3474 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3475 Check(
Call.getCalledFunction()->getIntrinsicID() ==
3476 Intrinsic::call_preallocated_arg,
3477 "preallocated as a call site attribute can only be on "
3478 "llvm.call.preallocated.arg");
3482 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic,
Call.isInlineAsm());
3487 if (
Call.hasInAllocaArgument()) {
3488 Value *InAllocaArg =
Call.getArgOperand(FTy->getNumParams() - 1);
3490 Check(AI->isUsedWithInAlloca(),
3491 "inalloca argument for call has mismatched alloca", AI, Call);
3497 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3498 if (
Call.paramHasAttr(i, Attribute::SwiftError)) {
3499 Value *SwiftErrorArg =
Call.getArgOperand(i);
3501 Check(AI->isSwiftError(),
3502 "swifterror argument for call has mismatched alloca", AI, Call);
3505 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
3506 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3507 SwiftErrorArg, Call);
3508 Check(ArgI->hasSwiftErrorAttr(),
3509 "swifterror argument for call has mismatched parameter", ArgI,
3513 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3516 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3517 "immarg may not apply only to call sites",
Call.getArgOperand(i),
3521 if (
Call.paramHasAttr(i, Attribute::ImmArg)) {
3523 Check(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),
3524 "immarg operand has non-immediate parameter", ArgVal, Call);
3527 if (
Call.paramHasAttr(i, Attribute::Preallocated)) {
3531 bool isMustTail =
Call.isMustTailCall();
3532 Check(hasOB != isMustTail,
3533 "preallocated operand either requires a preallocated bundle or "
3534 "the call to be musttail (but not both)",
3539 if (FTy->isVarArg()) {
3541 bool SawNest =
false;
3542 bool SawReturned =
false;
3544 for (
unsigned Idx = 0;
Idx < FTy->getNumParams(); ++
Idx) {
3545 if (
Attrs.hasParamAttr(
Idx, Attribute::Nest))
3547 if (
Attrs.hasParamAttr(
Idx, Attribute::Returned))
3552 for (
unsigned Idx = FTy->getNumParams();
Idx <
Call.arg_size(); ++
Idx) {
3555 verifyParameterAttrs(ArgAttrs, Ty, &Call);
3558 Check(!SawNest,
"More than one parameter has attribute nest!", Call);
3563 Check(!SawReturned,
"More than one parameter has attribute returned!",
3566 "Incompatible argument and return types for 'returned' "
3574 if (!
Call.getCalledFunction() ||
3575 Call.getCalledFunction()->getIntrinsicID() !=
3576 Intrinsic::experimental_gc_statepoint)
3578 "Attribute 'sret' cannot be used for vararg call arguments!",
3583 "inalloca isn't on the last argument!", Call);
3589 for (
Type *ParamTy : FTy->params()) {
3590 Check(!ParamTy->isMetadataTy(),
3591 "Function has metadata parameter but isn't an intrinsic", Call);
3592 Check(!ParamTy->isTokenTy(),
3593 "Function has token parameter but isn't an intrinsic", Call);
3598 if (!
Call.getCalledFunction()) {
3599 Check(!FTy->getReturnType()->isTokenTy(),
3600 "Return type cannot be token for indirect call!");
3601 Check(!FTy->getReturnType()->isX86_AMXTy(),
3602 "Return type cannot be x86_amx for indirect call!");
3607 visitIntrinsicCall(
ID, Call);
3612 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3613 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3614 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3615 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3616 FoundAttachedCallBundle =
false;
3617 for (
unsigned i = 0, e =
Call.getNumOperandBundles(); i < e; ++i) {
3621 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles", Call);
3622 FoundDeoptBundle =
true;
3624 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3626 FoundGCTransitionBundle =
true;
3628 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles", Call);
3629 FoundFuncletBundle =
true;
3631 "Expected exactly one funclet bundle operand", Call);
3633 "Funclet bundle operands should correspond to a FuncletPadInst",
3636 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3638 FoundCFGuardTargetBundle =
true;
3640 "Expected exactly one cfguardtarget bundle operand", Call);
3642 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles", Call);
3643 FoundPtrauthBundle =
true;
3645 "Expected exactly two ptrauth bundle operands", Call);
3647 BU.
Inputs[0]->getType()->isIntegerTy(32),
3648 "Ptrauth bundle key operand must be an i32 constant", Call);
3650 "Ptrauth bundle discriminator operand must be an i64", Call);
3652 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles", Call);
3653 FoundKCFIBundle =
true;
3654 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3657 BU.
Inputs[0]->getType()->isIntegerTy(32),
3658 "Kcfi bundle operand must be an i32 constant", Call);
3660 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3662 FoundPreallocatedBundle =
true;
3664 "Expected exactly one preallocated bundle operand", Call);
3665 auto Input = dyn_cast<IntrinsicInst>(BU.
Inputs.front());
3667 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3668 "\"preallocated\" argument must be a token from "
3669 "llvm.call.preallocated.setup",
3672 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles", Call);
3673 FoundGCLiveBundle =
true;
3675 Check(!FoundAttachedCallBundle,
3676 "Multiple \"clang.arc.attachedcall\" operand bundles", Call);
3677 FoundAttachedCallBundle =
true;
3678 verifyAttachedCallBundle(Call, BU);
3683 Check(!(
Call.getCalledFunction() && FoundPtrauthBundle),
3684 "Direct call cannot have a ptrauth bundle", Call);
3691 if (
Call.getFunction()->getSubprogram() &&
Call.getCalledFunction() &&
3692 !
Call.getCalledFunction()->isInterposable() &&
3693 !
Call.getCalledFunction()->isDeclaration() &&
3694 Call.getCalledFunction()->getSubprogram())
3696 "inlinable function call in a function with "
3697 "debug info must have a !dbg location",
3700 if (
Call.isInlineAsm())
3701 verifyInlineAsmCall(Call);
3703 ConvergenceVerifyHelper.
visit(Call);
3708void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3711 Twine(
"inalloca attribute not allowed in ") + Context);
3713 Twine(
"inreg attribute not allowed in ") + Context);
3714 Check(!
Attrs.contains(Attribute::SwiftError),
3715 Twine(
"swifterror attribute not allowed in ") + Context);
3716 Check(!
Attrs.contains(Attribute::Preallocated),
3717 Twine(
"preallocated attribute not allowed in ") + Context);
3719 Twine(
"byref attribute not allowed in ") + Context);
3731 return PL->getAddressSpace() == PR->getAddressSpace();
3736 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3737 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3738 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3741 for (
auto AK : ABIAttrs) {
3742 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3744 Copy.addAttribute(Attr);
3748 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
3749 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
3750 Attrs.hasParamAttr(
I, Attribute::ByRef)))
3751 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
3755void Verifier::verifyMustTailCall(
CallInst &CI) {
3761 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
3762 "cannot guarantee tail call due to mismatched varargs", &CI);
3764 "cannot guarantee tail call due to mismatched return types", &CI);
3768 "cannot guarantee tail call due to mismatched calling conv", &CI);
3774 Value *RetVal = &CI;
3778 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3780 "bitcast following musttail call must use the call", BI);
3787 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
3788 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
3789 isa<UndefValue>(
Ret->getReturnValue()),
3790 "musttail call result must be returned", Ret);
3801 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
3804 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3806 for (
unsigned I = 0,
E = CalleeTy->getNumParams();
I !=
E; ++
I) {
3809 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3812 Check(!CallerTy->isVarArg(),
Twine(
"cannot guarantee ") + CCName +
3813 " tail call for varargs function");
3821 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
3822 "cannot guarantee tail call due to mismatched parameter counts", &CI);
3823 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
3826 "cannot guarantee tail call due to mismatched parameter types", &CI);
3832 for (
unsigned I = 0,
E = CallerTy->getNumParams();
I !=
E; ++
I) {
3835 Check(CallerABIAttrs == CalleeABIAttrs,
3836 "cannot guarantee tail call due to mismatched ABI impacting "
3837 "function attributes",
3842void Verifier::visitCallInst(
CallInst &CI) {
3846 verifyMustTailCall(CI);
3849void Verifier::visitInvokeInst(
InvokeInst &II) {
3856 "The unwind destination does not have an exception handling instruction!",
3865 Check(
U.getType() ==
U.getOperand(0)->getType(),
3866 "Unary operators must have same type for"
3867 "operands and result!",
3870 switch (
U.getOpcode()) {
3873 case Instruction::FNeg:
3874 Check(
U.getType()->isFPOrFPVectorTy(),
3875 "FNeg operator only works with float types!", &U);
3888 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
3889 "Both operands to a binary operator are not of the same type!", &
B);
3891 switch (
B.getOpcode()) {
3894 case Instruction::Add:
3895 case Instruction::Sub:
3896 case Instruction::Mul:
3897 case Instruction::SDiv:
3898 case Instruction::UDiv:
3899 case Instruction::SRem:
3900 case Instruction::URem:
3901 Check(
B.getType()->isIntOrIntVectorTy(),
3902 "Integer arithmetic operators only work with integral types!", &
B);
3903 Check(
B.getType() ==
B.getOperand(0)->getType(),
3904 "Integer arithmetic operators must have same type "
3905 "for operands and result!",
3910 case Instruction::FAdd:
3911 case Instruction::FSub:
3912 case Instruction::FMul:
3913 case Instruction::FDiv:
3914 case Instruction::FRem:
3915 Check(
B.getType()->isFPOrFPVectorTy(),
3916 "Floating-point arithmetic operators only work with "
3917 "floating-point types!",
3919 Check(
B.getType() ==
B.getOperand(0)->getType(),
3920 "Floating-point arithmetic operators must have same type "
3921 "for operands and result!",
3925 case Instruction::And:
3926 case Instruction::Or:
3927 case Instruction::Xor:
3928 Check(
B.getType()->isIntOrIntVectorTy(),
3929 "Logical operators only work with integral types!", &
B);
3930 Check(
B.getType() ==
B.getOperand(0)->getType(),
3931 "Logical operators must have same type for operands and result!", &
B);
3933 case Instruction::Shl:
3934 case Instruction::LShr:
3935 case Instruction::AShr:
3936 Check(
B.getType()->isIntOrIntVectorTy(),
3937 "Shifts only work with integral types!", &
B);
3938 Check(
B.getType() ==
B.getOperand(0)->getType(),
3939 "Shift return type must be same as operands!", &
B);
3948void Verifier::visitICmpInst(
ICmpInst &IC) {
3952 Check(Op0Ty == Op1Ty,
3953 "Both operands to ICmp instruction are not of the same type!", &IC);
3956 "Invalid operand types for ICmp instruction", &IC);
3963void Verifier::visitFCmpInst(
FCmpInst &FC) {
3965 Type *Op0Ty =
FC.getOperand(0)->getType();
3966 Type *Op1Ty =
FC.getOperand(1)->getType();
3967 Check(Op0Ty == Op1Ty,
3968 "Both operands to FCmp instruction are not of the same type!", &FC);
3973 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
3980 "Invalid extractelement operands!", &EI);
3987 "Invalid insertelement operands!", &IE);
3994 "Invalid shufflevector operands!", &SV);
3999 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4001 Check(isa<PointerType>(TargetTy),
4002 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4003 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4005 if (
auto *STy = dyn_cast<StructType>(
GEP.getSourceElementType())) {
4008 "getelementptr cannot target structure that contains scalable vector"
4015 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4016 "GEP indexes must be integers", &
GEP);
4019 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4021 Check(
GEP.getType()->isPtrOrPtrVectorTy() &&
4022 GEP.getResultElementType() == ElTy,
4023 "GEP is not of right type for indices!", &
GEP, ElTy);
4025 if (
auto *GEPVTy = dyn_cast<VectorType>(
GEP.getType())) {
4028 if (
GEP.getPointerOperandType()->isVectorTy())
4031 cast<VectorType>(
GEP.getPointerOperandType())->getElementCount(),
4032 "Vector GEP result width doesn't match operand's", &
GEP);
4034 Type *IndexTy =
Idx->getType();
4035 if (
auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) {
4037 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4040 "All GEP indices should be of integer type");
4044 if (
auto *PTy = dyn_cast<PointerType>(
GEP.getType())) {
4045 Check(
GEP.getAddressSpace() == PTy->getAddressSpace(),
4046 "GEP address space doesn't match type", &
GEP);
4053 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4058void Verifier::verifyRangeMetadata(
const Value &
I,
const MDNode *Range,
4059 Type *Ty,
bool IsAbsoluteSymbol) {
4060 unsigned NumOperands =
Range->getNumOperands();
4061 Check(NumOperands % 2 == 0,
"Unfinished range!", Range);
4062 unsigned NumRanges = NumOperands / 2;
4063 Check(NumRanges >= 1,
"It should have at least one range!", Range);
4066 for (
unsigned i = 0; i < NumRanges; ++i) {
4068 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i));
4069 Check(
Low,
"The lower limit must be an integer!",
Low);
4071 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i + 1));
4075 "Range types must match instruction type!", &
I);
4083 "The upper and lower limits cannot be the same value", &
I);
4086 Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()),
4087 "Range must not be empty!", Range);
4089 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4090 "Intervals are overlapping", Range);
4091 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4098 if (NumRanges > 2) {
4100 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(0))->getValue();
4102 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(1))->getValue();
4104 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4105 "Intervals are overlapping", Range);
4112 assert(Range && Range ==
I.getMetadata(LLVMContext::MD_range) &&
4113 "precondition violation");
4114 verifyRangeMetadata(
I, Range, Ty,
false);
4118 unsigned Size =
DL.getTypeSizeInBits(Ty);
4119 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4121 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4124void Verifier::visitLoadInst(
LoadInst &LI) {
4126 Check(PTy,
"Load operand must be a pointer.", &LI);
4130 "huge alignment values are unsupported", &LI);
4132 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4136 "Load cannot have Release ordering", &LI);
4138 "atomic load operand must have integer, pointer, or floating point "
4141 checkAtomicMemAccessSize(ElTy, &LI);
4144 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4150void Verifier::visitStoreInst(
StoreInst &SI) {
4151 PointerType *PTy = dyn_cast<PointerType>(
SI.getOperand(1)->getType());
4152 Check(PTy,
"Store operand must be a pointer.", &SI);
4153 Type *ElTy =
SI.getOperand(0)->getType();
4156 "huge alignment values are unsupported", &SI);
4158 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4159 if (
SI.isAtomic()) {
4162 "Store cannot have Acquire ordering", &SI);
4164 "atomic store operand must have integer, pointer, or floating point "
4167 checkAtomicMemAccessSize(ElTy, &SI);
4170 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4176void Verifier::verifySwiftErrorCall(
CallBase &Call,
4177 const Value *SwiftErrorVal) {
4179 if (
I.value() == SwiftErrorVal) {
4180 Check(
Call.paramHasAttr(
I.index(), Attribute::SwiftError),
4181 "swifterror value when used in a callsite should be marked "
4182 "with swifterror attribute",
4183 SwiftErrorVal, Call);
4188void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4191 for (
const User *U : SwiftErrorVal->
users()) {
4192 Check(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
4194 "swifterror value can only be loaded and stored from, or "
4195 "as a swifterror argument!",
4198 if (
auto StoreI = dyn_cast<StoreInst>(U))
4199 Check(StoreI->getOperand(1) == SwiftErrorVal,
4200 "swifterror value should be the second operand when used "
4203 if (
auto *Call = dyn_cast<CallBase>(U))
4204 verifySwiftErrorCall(*
const_cast<CallBase *
>(Call), SwiftErrorVal);
4208void Verifier::visitAllocaInst(
AllocaInst &AI) {
4211 "Cannot allocate unsized type", &AI);
4213 "Alloca array size must have integer type", &AI);
4216 "huge alignment values are unsupported", &AI);
4221 "swifterror alloca must have pointer type", &AI);
4223 "swifterror alloca must not be array allocation", &AI);
4224 verifySwiftErrorValue(&AI);
4233 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4234 checkAtomicMemAccessSize(ElTy, &CXI);
4240 "atomicrmw instructions cannot be unordered.", &RMWI);
4247 " operand must have integer or floating point type!",
4252 " operand must have floating point type!",
4257 " operand must have integer type!",
4260 checkAtomicMemAccessSize(ElTy, &RMWI);
4262 "Invalid binary operation!", &RMWI);
4266void Verifier::visitFenceInst(
FenceInst &FI) {
4272 "fence instructions may only have acquire, release, acq_rel, or "
4273 "seq_cst ordering.",
4281 "Invalid ExtractValueInst operands!", &EVI);
4290 "Invalid InsertValueInst operands!", &IVI);
4296 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
4297 return FPI->getParentPad();
4299 return cast<CatchSwitchInst>(EHPad)->getParentPad();
4308 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4310 if (
auto *LPI = dyn_cast<LandingPadInst>(&
I)) {
4315 const auto *II = dyn_cast<InvokeInst>(PredBB->getTerminator());
4316 Check(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
4317 "Block containing LandingPadInst must be jumped to "
4318 "only by the unwind edge of an invoke.",
4323 if (
auto *CPI = dyn_cast<CatchPadInst>(&
I)) {
4326 "Block containg CatchPadInst must be jumped to "
4327 "only by its catchswitch.",
4329 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4330 "Catchswitch cannot unwind to one of its catchpads",
4331 CPI->getCatchSwitch(), CPI);
4342 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
4343 Check(II->getUnwindDest() == BB && II->getNormalDest() != BB,
4344 "EH pad must be jumped to via an unwind edge", ToPad, II);
4346 FromPad = Bundle->Inputs[0];
4349 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
4350 FromPad = CRI->getOperand(0);
4351 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4352 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
4355 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4361 Check(FromPad != ToPad,
4362 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4363 if (FromPad == ToPadParent) {
4367 Check(!isa<ConstantTokenNone>(FromPad),
4368 "A single unwind edge may only enter one EH pad", TI);
4369 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4374 Check(isa<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(FromPad),
4375 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4384 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4386 visitEHPadPredecessors(LPI);
4388 if (!LandingPadResultTy)
4389 LandingPadResultTy = LPI.
getType();
4392 "The landingpad instruction should have a consistent result type "
4393 "inside a function.",
4397 Check(
F->hasPersonalityFn(),
4398 "LandingPadInst needs to be in a function with a personality.", &LPI);
4403 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4409 "Catch operand does not have pointer type!", &LPI);
4411 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4413 "Filter operand is not an array of constants!", &LPI);
4420void Verifier::visitResumeInst(
ResumeInst &RI) {
4422 "ResumeInst needs to be in a function with a personality.", &RI);
4424 if (!LandingPadResultTy)
4428 "The resume instruction should have a consistent result type "
4429 "inside a function.",
4439 Check(
F->hasPersonalityFn(),
4440 "CatchPadInst needs to be in a function with a personality.", &CPI);
4443 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4449 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4451 visitEHPadPredecessors(CPI);
4457 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4467 Check(
F->hasPersonalityFn(),
4468 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4473 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4476 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4477 "CleanupPadInst has an invalid parent.", &CPI);
4479 visitEHPadPredecessors(CPI);
4484 User *FirstUser =
nullptr;
4485 Value *FirstUnwindPad =
nullptr;
4489 while (!Worklist.empty()) {
4492 "FuncletPadInst must not be nested within itself", CurrentPad);
4493 Value *UnresolvedAncestorPad =
nullptr;
4496 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
4497 UnwindDest = CRI->getUnwindDest();
4498 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
4503 if (CSI->unwindsToCaller())
4505 UnwindDest = CSI->getUnwindDest();
4506 }
else if (
auto *II = dyn_cast<InvokeInst>(U)) {
4507 UnwindDest = II->getUnwindDest();
4508 }
else if (isa<CallInst>(U)) {
4513 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
4517 Worklist.push_back(CPI);
4520 Check(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
4528 if (!cast<Instruction>(UnwindPad)->isEHPad())
4532 if (UnwindParent == CurrentPad)
4538 Value *ExitedPad = CurrentPad;
4541 if (ExitedPad == &FPI) {
4546 UnresolvedAncestorPad = &FPI;
4550 if (ExitedParent == UnwindParent) {
4554 UnresolvedAncestorPad = ExitedParent;
4557 ExitedPad = ExitedParent;
4558 }
while (!isa<ConstantTokenNone>(ExitedPad));
4563 UnresolvedAncestorPad = &FPI;
4570 Check(UnwindPad == FirstUnwindPad,
4571 "Unwind edges out of a funclet "
4572 "pad must have the same unwind "
4574 &FPI, U, FirstUser);
4577 FirstUnwindPad = UnwindPad;
4579 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
4581 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
4586 if (CurrentPad != &FPI)
4589 if (UnresolvedAncestorPad) {
4590 if (CurrentPad == UnresolvedAncestorPad) {
4594 assert(CurrentPad == &FPI);
4602 Value *ResolvedPad = CurrentPad;
4603 while (!Worklist.empty()) {
4604 Value *UnclePad = Worklist.back();
4608 while (ResolvedPad != AncestorPad) {
4610 if (ResolvedParent == UnresolvedAncestorPad) {
4613 ResolvedPad = ResolvedParent;
4617 if (ResolvedPad != AncestorPad)
4620 Worklist.pop_back();
4625 if (FirstUnwindPad) {
4626 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
4627 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4628 Value *SwitchUnwindPad;
4629 if (SwitchUnwindDest)
4633 Check(SwitchUnwindPad == FirstUnwindPad,
4634 "Unwind edges out of a catch must have the same unwind dest as "
4635 "the parent catchswitch",
4636 &FPI, FirstUser, CatchSwitch);
4647 Check(
F->hasPersonalityFn(),
4648 "CatchSwitchInst needs to be in a function with a personality.",
4654 "CatchSwitchInst not the first non-PHI instruction in the block.",
4658 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4659 "CatchSwitchInst has an invalid parent.", ParentPad);
4663 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4664 "CatchSwitchInst must unwind to an EH block which is not a "
4670 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4674 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4677 Check(isa<CatchPadInst>(Handler->getFirstNonPHI()),
4678 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4681 visitEHPadPredecessors(CatchSwitch);
4687 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4692 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4693 "CleanupReturnInst must unwind to an EH block which is not a "
4701void Verifier::verifyDominatesUse(
Instruction &
I,
unsigned i) {
4707 if (II->getNormalDest() == II->getUnwindDest())
4718 if (!isa<PHINode>(
I) && InstsInThisBlock.
count(
Op))
4721 const Use &
U =
I.getOperandUse(i);
4726 Check(
I.getType()->isPointerTy(),
4727 "dereferenceable, dereferenceable_or_null "
4728 "apply only to pointer types",
4730 Check((isa<LoadInst>(
I) || isa<IntToPtrInst>(
I)),
4731 "dereferenceable, dereferenceable_or_null apply only to load"
4732 " and inttoptr instructions, use attributes for calls or invokes",
4735 "dereferenceable, dereferenceable_or_null "
4736 "take one operand!",
4741 "dereferenceable_or_null metadata value must be an i64!",
4747 "!prof annotations should have no less than 2 operands", MD);
4750 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
4752 "expected string with name of the !prof annotation", MD);
4757 if (ProfName.
equals(
"branch_weights")) {
4758 if (isa<InvokeInst>(&
I)) {
4760 "Wrong number of InvokeInst branch_weights operands", MD);
4762 unsigned ExpectedNumOperands = 0;
4765 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
4766 ExpectedNumOperands =
SI->getNumSuccessors();
4767 else if (isa<CallInst>(&
I))
4768 ExpectedNumOperands = 1;
4770 ExpectedNumOperands = IBI->getNumDestinations();
4771 else if (isa<SelectInst>(&
I))
4772 ExpectedNumOperands = 2;
4773 else if (
CallBrInst *CI = dyn_cast<CallBrInst>(&
I))
4776 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
4780 "Wrong number of operands", MD);
4784 Check(MDO,
"second operand should not be null", MD);
4785 Check(mdconst::dyn_extract<ConstantInt>(MDO),
4786 "!prof brunch_weights operand is not a const int");
4792 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
4793 bool ExpectedInstTy =
4794 isa<AllocaInst>(
I) || isa<StoreInst>(
I) || isa<MemIntrinsic>(
I);
4795 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
4802 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
4805 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(
User))
4806 CheckDI(DAI->getFunction() ==
I.getFunction(),
4807 "dbg.assign not in same function as inst", DAI, &
I);
4810 for (
DPValue *DPV : cast<DIAssignID>(MD)->getAllDPValueUsers()) {
4812 "!DIAssignID should only be used by Assign DPVs.", MD, DPV);
4813 CheckDI(DPV->getFunction() ==
I.getFunction(),
4814 "DPVAssign not in same function as inst", DPV, &
I);
4818void Verifier::visitCallStackMetadata(
MDNode *MD) {
4822 "call stack metadata should have at least 1 operand", MD);
4825 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op),
4826 "call stack metadata operand should be constant integer",
Op);
4830 Check(isa<CallBase>(
I),
"!memprof metadata should only exist on calls", &
I);
4832 "!memprof annotations should have at least 1 metadata operand "
4837 for (
auto &MIBOp : MD->
operands()) {
4838 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
4843 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
4847 "!memprof MemInfoBlock first operand should not be null", MIB);
4849 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
4851 visitCallStackMetadata(StackMD);
4855 [](
const MDOperand &
Op) { return isa<MDString>(Op); }),
4856 "Not all !memprof MemInfoBlock operands 1 to N are MDString", MIB);
4861 Check(isa<CallBase>(
I),
"!callsite metadata should only exist on calls", &
I);
4864 visitCallStackMetadata(MD);
4867void Verifier::visitAnnotationMetadata(
MDNode *Annotation) {
4868 Check(isa<MDTuple>(Annotation),
"annotation must be a tuple");
4870 "annotation must have at least one operand");
4872 bool TupleOfStrings =
4873 isa<MDTuple>(
Op.get()) &&
4874 all_of(cast<MDTuple>(
Op)->operands(), [](
auto &Annotation) {
4877 Check(isa<MDString>(
Op.get()) || TupleOfStrings,
4878 "operands must be a string or a tuple of strings");
4882void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
4884 Check(NumOps >= 2 && NumOps <= 3,
"scope must have two or three operands",
4887 "first scope operand must be self-referential or string", MD);
4890 "third scope operand must be string (if used)", MD);
4893 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
4895 unsigned NumDomainOps =
Domain->getNumOperands();
4896 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
4897 "domain must have one or two operands",
Domain);
4899 isa<MDString>(
Domain->getOperand(0)),
4900 "first domain operand must be self-referential or string",
Domain);
4901 if (NumDomainOps == 2)
4903 "second domain operand must be string (if used)",
Domain);
4906void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
4908 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
4909 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
4910 visitAliasScopeMetadata(OpMD);
4914void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
4915 auto IsValidAccessScope = [](
const MDNode *MD) {
4920 if (IsValidAccessScope(MD))
4925 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
4926 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
4927 Check(IsValidAccessScope(OpMD),
4928 "Access scope list contains invalid access scope", MD);
4936 Check(BB,
"Instruction not embedded in basic block!", &
I);
4938 if (!isa<PHINode>(
I)) {
4939 for (
User *U :
I.users()) {
4941 "Only PHI nodes may reference their own value!", &
I);
4946 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
4947 "Instruction has a name, but provides a void value!", &
I);
4951 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
4952 "Instruction returns a non-scalar type!", &
I);
4956 Check(!
I.getType()->isMetadataTy() || isa<CallInst>(
I) || isa<InvokeInst>(
I),
4957 "Invalid use of metadata!", &
I);
4962 for (
Use &U :
I.uses()) {
4963 if (
Instruction *Used = dyn_cast<Instruction>(
U.getUser()))
4965 "Instruction referencing"
4966 " instruction not embedded in a basic block!",
4969 CheckFailed(
"Use of instruction is not an instruction!", U);
4976 const CallBase *CBI = dyn_cast<CallBase>(&
I);
4978 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
4979 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
4983 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
4984 Check(
false,
"Instruction operands must be first-class values!", &
I);
4987 if (
Function *
F = dyn_cast<Function>(
I.getOperand(i))) {
4992 return CBI && CBI->isOperandBundleOfType(
5000 Check((!
F->isIntrinsic() ||
5001 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5002 IsAttachedCallOperand(
F, CBI, i)),
5003 "Cannot take the address of an intrinsic!", &
I);
5004 Check(!
F->isIntrinsic() || isa<CallInst>(
I) ||
5005 F->getIntrinsicID() == Intrinsic::donothing ||
5006 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5007 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5008 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5009 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5010 F->getIntrinsicID() == Intrinsic::coro_resume ||
5011 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5012 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5013 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5014 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5015 F->getIntrinsicID() ==
5016 Intrinsic::experimental_patchpoint_void ||
5017 F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 ||
5018 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5019 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5020 IsAttachedCallOperand(
F, CBI, i),
5021 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5022 "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall",
5024 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5025 &M,
F,
F->getParent());
5026 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(
I.getOperand(i))) {
5028 "Referring to a basic block in another function!", &
I);
5029 }
else if (
Argument *OpArg = dyn_cast<Argument>(
I.getOperand(i))) {
5031 "Referring to an argument in another function!", &
I);
5032 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(
I.getOperand(i))) {
5033 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5035 }
else if (
Instruction *OpInst = dyn_cast<Instruction>(
I.getOperand(i))) {
5037 "Referring to an instruction in another function!", &
I);
5038 verifyDominatesUse(
I, i);
5039 }
else if (isa<InlineAsm>(
I.getOperand(i))) {
5040 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5041 "Cannot take the address of an inline asm!", &
I);
5042 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(
I.getOperand(i))) {
5043 if (
CE->getType()->isPtrOrPtrVectorTy()) {
5046 visitConstantExprsRecursively(CE);
5051 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5052 Check(
I.getType()->isFPOrFPVectorTy(),
5053 "fpmath requires a floating point result!", &
I);
5056 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
5057 const APFloat &Accuracy = CFP0->getValueAPF();
5059 "fpmath accuracy must have float type", &
I);
5061 "fpmath accuracy not a positive number!", &
I);
5063 Check(
false,
"invalid fpmath accuracy!", &
I);
5067 if (
MDNode *Range =
I.getMetadata(LLVMContext::MD_range)) {
5068 Check(isa<LoadInst>(
I) || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5069 "Ranges are only for loads, calls and invokes!", &
I);
5070 visitRangeMetadata(
I, Range,
I.getType());
5073 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5074 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I),
5075 "invariant.group metadata is only for loads and stores", &
I);
5078 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
5079 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
5082 "nonnull applies only to load instructions, use attributes"
5083 " for calls or invokes",
5088 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
5089 visitDereferenceableMetadata(
I, MD);
5091 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
5092 visitDereferenceableMetadata(
I, MD);
5094 if (
MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5097 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5098 visitAliasScopeListMetadata(MD);
5099 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5100 visitAliasScopeListMetadata(MD);
5102 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5103 visitAccessGroupMetadata(MD);
5105 if (
MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5106 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5109 "align applies only to load instructions, "
5110 "use attributes for calls or invokes",
5112 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5113 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
5115 "align metadata value must be an i64!", &
I);
5120 "alignment is larger that implementation defined limit", &
I);
5123 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5124 visitProfMetadata(
I, MD);
5126 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5127 visitMemProfMetadata(
I, MD);
5129 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5130 visitCallsiteMetadata(
I, MD);
5132 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5133 visitDIAssignIDMetadata(
I, MD);
5135 if (
MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5136 visitAnnotationMetadata(Annotation);
5138 if (
MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5139 CheckDI(isa<DILocation>(
N),
"invalid !dbg metadata attachment", &
I,
N);
5140 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5143 if (
auto *DII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
5144 verifyFragmentExpression(*DII);
5145 verifyNotEntryValue(*DII);
5149 I.getAllMetadata(MDs);
5150 for (
auto Attachment : MDs) {
5151 unsigned Kind = Attachment.first;
5153 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5154 ? AreDebugLocsAllowed::Yes
5155 : AreDebugLocsAllowed::No;
5156 visitMDNode(*Attachment.second, AllowLocs);
5165 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5171 bool IsVarArg = IFTy->isVarArg();
5182 "Intrinsic has incorrect return type!", IF);
5184 "Intrinsic has incorrect argument type!", IF);
5189 "Intrinsic was not defined with variable arguments!", IF);
5192 "Callsite was not defined with variable arguments!", IF);
5201 const std::string ExpectedName =
5203 Check(ExpectedName ==
IF->getName(),
5204 "Intrinsic name not mangled correctly for type arguments! "
5212 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
5213 visitMetadataAsValue(*MD,
Call.getCaller());
5214 if (
auto *Const = dyn_cast<Constant>(V))
5216 "const x86_amx is not allowed in argument!");
5222 case Intrinsic::assume: {
5223 for (
auto &Elem :
Call.bundle_op_infos()) {
5224 unsigned ArgCount = Elem.End - Elem.Begin;
5227 if (Elem.Tag->getKey() ==
"separate_storage") {
5228 Check(ArgCount == 2,
5229 "separate_storage assumptions should have 2 arguments", Call);
5230 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy() &&
5231 Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
5232 "arguments to separate_storage assumptions should be pointers",
5236 Check(Elem.Tag->getKey() ==
"ignore" ||
5238 "tags must be valid attribute names", Call);
5241 if (Kind == Attribute::Alignment) {
5242 Check(ArgCount <= 3 && ArgCount >= 2,
5243 "alignment assumptions should have 2 or 3 arguments", Call);
5244 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5245 "first argument should be a pointer", Call);
5246 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5247 "second argument should be an integer", Call);
5249 Check(
Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
5250 "third argument should be an integer if present", Call);
5253 Check(ArgCount <= 2,
"too many arguments", Call);
5257 Check(ArgCount == 2,
"this attribute should have 2 arguments", Call);
5258 Check(isa<ConstantInt>(
Call.getOperand(Elem.Begin + 1)),
5259 "the second argument should be a constant integral value", Call);
5261 Check((ArgCount) == 1,
"this attribute should have one argument", Call);
5263 Check((ArgCount) == 0,
"this attribute has no argument", Call);
5268 case Intrinsic::coro_id: {
5269 auto *InfoArg =
Call.getArgOperand(3)->stripPointerCasts();
5270 if (isa<ConstantPointerNull>(InfoArg))
5272 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
5274 "info argument of llvm.coro.id must refer to an initialized "
5277 Check(isa<ConstantStruct>(
Init) || isa<ConstantArray>(
Init),
5278 "info argument of llvm.coro.id must refer to either a struct or "
5282 case Intrinsic::is_fpclass: {
5285 "unsupported bits for llvm.is.fpclass test mask");
5288 case Intrinsic::fptrunc_round: {
5291 auto *MAV = dyn_cast<MetadataAsValue>(
Call.getOperand(1));
5293 MD = MAV->getMetadata();
5295 Check(MD !=
nullptr,
"missing rounding mode argument", Call);
5297 Check(isa<MDString>(MD),
5298 (
"invalid value for llvm.fptrunc.round metadata operand"
5299 " (the operand should be a string)"),
5302 std::optional<RoundingMode> RoundMode =
5305 "unsupported rounding mode argument", Call);
5308#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5309#include "llvm/IR/VPIntrinsics.def"
5310 visitVPIntrinsic(cast<VPIntrinsic>(Call));
5312#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5313 case Intrinsic::INTRINSIC:
5314#include "llvm/IR/ConstrainedOps.def"
5315 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
5317 case Intrinsic::dbg_declare:
5318 Check(isa<MetadataAsValue>(
Call.getArgOperand(0)),
5319 "invalid llvm.dbg.declare intrinsic call 1", Call);
5320 visitDbgIntrinsic(
"declare", cast<DbgVariableIntrinsic>(Call));
5322 case Intrinsic::dbg_value:
5323 visitDbgIntrinsic(
"value", cast<DbgVariableIntrinsic>(Call));
5325 case Intrinsic::dbg_assign:
5326 visitDbgIntrinsic(
"assign", cast<DbgVariableIntrinsic>(Call));
5328 case Intrinsic::dbg_label:
5329 visitDbgLabelIntrinsic(
"label", cast<DbgLabelInst>(Call));
5331 case Intrinsic::memcpy:
5332 case Intrinsic::memcpy_inline:
5333 case Intrinsic::memmove:
5334 case Intrinsic::memset:
5335 case Intrinsic::memset_inline: {
5338 case Intrinsic::memcpy_element_unordered_atomic:
5339 case Intrinsic::memmove_element_unordered_atomic:
5340 case Intrinsic::memset_element_unordered_atomic: {
5341 const auto *AMI = cast<AtomicMemIntrinsic>(&Call);
5344 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
5347 "element size of the element-wise atomic memory intrinsic "
5348 "must be a power of 2",
5351 auto IsValidAlignment = [&](
MaybeAlign Alignment) {
5352 return Alignment && ElementSizeVal.
ule(Alignment->value());
5354 Check(IsValidAlignment(AMI->getDestAlign()),
5355 "incorrect alignment of the destination argument", Call);
5356 if (
const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
5357 Check(IsValidAlignment(AMT->getSourceAlign()),
5358 "incorrect alignment of the source argument", Call);
5362 case Intrinsic::call_preallocated_setup: {
5363 auto *NumArgs = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5364 Check(NumArgs !=
nullptr,
5365 "llvm.call.preallocated.setup argument must be a constant");
5366 bool FoundCall =
false;
5368 auto *UseCall = dyn_cast<CallBase>(U);
5369 Check(UseCall !=
nullptr,
5370 "Uses of llvm.call.preallocated.setup must be calls");
5371 const Function *Fn = UseCall->getCalledFunction();
5372 if (Fn && Fn->
getIntrinsicID() == Intrinsic::call_preallocated_arg) {
5373 auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5374 Check(AllocArgIndex !=
nullptr,
5375 "llvm.call.preallocated.alloc arg index must be a constant");
5376 auto AllocArgIndexInt = AllocArgIndex->getValue();
5377 Check(AllocArgIndexInt.sge(0) &&
5378 AllocArgIndexInt.slt(NumArgs->getValue()),
5379 "llvm.call.preallocated.alloc arg index must be between 0 and "
5381 "llvm.call.preallocated.setup's argument count");
5383 Intrinsic::call_preallocated_teardown) {
5386 Check(!FoundCall,
"Can have at most one call corresponding to a "
5387 "llvm.call.preallocated.setup");
5389 size_t NumPreallocatedArgs = 0;
5390 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5391 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5392 ++NumPreallocatedArgs;
5395 Check(NumPreallocatedArgs != 0,
5396 "cannot use preallocated intrinsics on a call without "
5397 "preallocated arguments");
5398 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5399 "llvm.call.preallocated.setup arg size must be equal to number "
5400 "of preallocated arguments "
5410 auto PreallocatedBundle =
5412 Check(PreallocatedBundle,
5413 "Use of llvm.call.preallocated.setup outside intrinsics "
5414 "must be in \"preallocated\" operand bundle");
5415 Check(PreallocatedBundle->Inputs.front().get() == &Call,
5416 "preallocated bundle must have token from corresponding "
5417 "llvm.call.preallocated.setup");
5422 case Intrinsic::call_preallocated_arg: {
5423 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5424 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5425 Intrinsic::call_preallocated_setup,
5426 "llvm.call.preallocated.arg token argument must be a "
5427 "llvm.call.preallocated.setup");
5428 Check(
Call.hasFnAttr(Attribute::Preallocated),
5429 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5430 "call site attribute");
5433 case Intrinsic::call_preallocated_teardown: {
5434 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5435 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5436 Intrinsic::call_preallocated_setup,
5437 "llvm.call.preallocated.teardown token argument must be a "
5438 "llvm.call.preallocated.setup");
5441 case Intrinsic::gcroot:
5442 case Intrinsic::gcwrite:
5443 case Intrinsic::gcread:
5444 if (
ID == Intrinsic::gcroot) {
5446 dyn_cast<AllocaInst>(
Call.getArgOperand(0)->stripPointerCasts());
5447 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.", Call);
5448 Check(isa<Constant>(
Call.getArgOperand(1)),
5449 "llvm.gcroot parameter #2 must be a constant.", Call);
5451 Check(!isa<ConstantPointerNull>(
Call.getArgOperand(1)),
5452 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5453 "or argument #2 must be a non-null constant.",
5458 Check(
Call.getParent()->getParent()->hasGC(),
5459 "Enclosing function does not use GC.", Call);
5461 case Intrinsic::init_trampoline:
5462 Check(isa<Function>(
Call.getArgOperand(1)->stripPointerCasts()),
5463 "llvm.init_trampoline parameter #2 must resolve to a function.",
5466 case Intrinsic::prefetch:
5467 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
5468 "rw argument to llvm.prefetch must be 0-1", Call);
5469 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
5470 "locality argument to llvm.prefetch must be 0-3", Call);
5471 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
5472 "cache type argument to llvm.prefetch must be 0-1", Call);
5474 case Intrinsic::stackprotector:
5475 Check(isa<AllocaInst>(
Call.getArgOperand(1)->stripPointerCasts()),
5476 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call);
5478 case Intrinsic::localescape: {
5482 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5485 if (isa<ConstantPointerNull>(Arg))
5487 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
5489 "llvm.localescape only accepts static allocas", Call);
5492 SawFrameEscape =
true;
5495 case Intrinsic::localrecover: {
5496 Value *FnArg =
Call.getArgOperand(0)->stripPointerCasts();
5497 Function *Fn = dyn_cast<Function>(FnArg);
5499 "llvm.localrecover first "
5500 "argument must be function defined in this module",
5502 auto *IdxArg = cast<ConstantInt>(
Call.getArgOperand(2));
5503 auto &Entry = FrameEscapeInfo[Fn];
5505 std::max(
uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5509 case Intrinsic::experimental_gc_statepoint:
5510 if (
auto *CI = dyn_cast<CallInst>(&Call))
5511 Check(!CI->isInlineAsm(),
5512 "gc.statepoint support for inline assembly unimplemented", CI);
5513 Check(
Call.getParent()->getParent()->hasGC(),
5514 "Enclosing function does not use GC.", Call);
5516 verifyStatepoint(Call);
5518 case Intrinsic::experimental_gc_result: {
5519 Check(
Call.getParent()->getParent()->hasGC(),
5520 "Enclosing function does not use GC.", Call);
5522 auto *Statepoint =
Call.getArgOperand(0);
5523 if (isa<UndefValue>(Statepoint))
5527 const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
5529 StatepointCall ? StatepointCall->getCalledFunction() :
nullptr;
5532 Intrinsic::experimental_gc_statepoint,
5533 "gc.result operand #1 must be from a statepoint", Call,
5534 Call.getArgOperand(0));
5537 auto *TargetFuncType =
5538 cast<FunctionType>(StatepointCall->getParamElementType(2));
5539 Check(
Call.getType() == TargetFuncType->getReturnType(),
5540 "gc.result result type does not match wrapped callee", Call);
5543 case Intrinsic::experimental_gc_relocate: {
5544 Check(
Call.arg_size() == 3,
"wrong number of arguments", Call);
5546 Check(isa<PointerType>(
Call.getType()->getScalarType()),
5547 "gc.relocate must return a pointer or a vector of pointers", Call);
5553 dyn_cast<LandingPadInst>(
Call.getArgOperand(0))) {
5556 LandingPad->
getParent()->getUniquePredecessor();
5560 Check(InvokeBB,
"safepoints should have unique landingpads",
5561 LandingPad->getParent());
5565 "gc relocate should be linked to a statepoint", InvokeBB);
5570 auto *Token =
Call.getArgOperand(0);
5571 Check(isa<GCStatepointInst>(Token) || isa<UndefValue>(Token),
5572 "gc relocate is incorrectly tied to the statepoint", Call, Token);
5576 const Value &StatepointCall = *cast<GCRelocateInst>(Call).getStatepoint();
5581 "gc.relocate operand #2 must be integer offset", Call);
5584 Check(isa<ConstantInt>(Derived),
5585 "gc.relocate operand #3 must be integer offset", Call);
5587 const uint64_t BaseIndex = cast<ConstantInt>(
Base)->getZExtValue();
5588 const uint64_t DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
5591 if (isa<UndefValue>(StatepointCall))
5593 if (
auto Opt = cast<GCStatepointInst>(StatepointCall)
5595 Check(BaseIndex < Opt->Inputs.size(),
5596 "gc.relocate: statepoint base index out of bounds", Call);
5597 Check(DerivedIndex < Opt->Inputs.size(),
5598 "gc.relocate: statepoint derived index out of bounds", Call);
5606 auto *ResultType =
Call.getType();
5611 "gc.relocate: relocated value must be a pointer", Call);
5612 Check(DerivedType->isPtrOrPtrVectorTy(),
5613 "gc.relocate: relocated value must be a pointer", Call);
5615 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
5616 "gc.relocate: vector relocates to vector and pointer to pointer",
5619 ResultType->getPointerAddressSpace() ==
5620 DerivedType->getPointerAddressSpace(),
5621 "gc.relocate: relocating a pointer shouldn't change its address space",
5625 Check(GC,
"gc.relocate: calling function must have GCStrategy",
5626 Call.getFunction());
5628 auto isGCPtr = [&
GC](
Type *PTy) {
5629 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
5631 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer", Call);
5633 "gc.relocate: relocated value must be a gc pointer", Call);
5634 Check(isGCPtr(DerivedType),
5635 "gc.relocate: relocated value must be a gc pointer", Call);
5639 case Intrinsic::eh_exceptioncode:
5640 case Intrinsic::eh_exceptionpointer: {
5641 Check(isa<CatchPadInst>(
Call.getArgOperand(0)),
5642 "eh.exceptionpointer argument must be a catchpad", Call);
5645 case Intrinsic::get_active_lane_mask: {
5647 "get_active_lane_mask: must return a "
5650 auto *ElemTy =
Call.getType()->getScalarType();
5651 Check(ElemTy->isIntegerTy(1),
5652 "get_active_lane_mask: element type is not "
5657 case Intrinsic::experimental_get_vector_length: {
5660 "get_vector_length: VF must be positive", Call);
5663 case Intrinsic::masked_load: {
5664 Check(
Call.getType()->isVectorTy(),
"masked_load: must return a vector",
5669 Value *PassThru =
Call.getArgOperand(3);
5670 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
5673 "masked_load: alignment must be a power of 2", Call);
5675 "masked_load: pass through and return type must match", Call);
5676 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5677 cast<VectorType>(
Call.getType())->getElementCount(),
5678 "masked_load: vector mask must be same length as return", Call);
5681 case Intrinsic::masked_store: {
5685 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
5688 "masked_store: alignment must be a power of 2", Call);
5689 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5690 cast<VectorType>(Val->
getType())->getElementCount(),
5691 "masked_store: vector mask must be same length as value", Call);
5695 case Intrinsic::masked_gather: {
5696 const APInt &Alignment =
5699 "masked_gather: alignment must be 0 or a power of 2", Call);
5702 case Intrinsic::masked_scatter: {
5703 const APInt &Alignment =
5704 cast<ConstantInt>(
Call.getArgOperand(2))->getValue();
5706 "masked_scatter: alignment must be 0 or a power of 2", Call);
5710 case Intrinsic::experimental_guard: {
5711 Check(isa<CallInst>(Call),
"experimental_guard cannot be invoked", Call);
5713 "experimental_guard must have exactly one "
5714 "\"deopt\" operand bundle");
5718 case Intrinsic::experimental_deoptimize: {
5719 Check(isa<CallInst>(Call),
"experimental_deoptimize cannot be invoked",
5722 "experimental_deoptimize must have exactly one "
5723 "\"deopt\" operand bundle");
5724 Check(
Call.getType() ==
Call.getFunction()->getReturnType(),
5725 "experimental_deoptimize return type must match caller return type");
5727 if (isa<CallInst>(Call)) {
5728 auto *RI = dyn_cast<ReturnInst>(
Call.getNextNode());
5730 "calls to experimental_deoptimize must be followed by a return");
5732 if (!
Call.getType()->isVoidTy() && RI)
5733 Check(RI->getReturnValue() == &Call,
5734 "calls to experimental_deoptimize must be followed by a return "
5735 "of the value computed by experimental_deoptimize");
5740 case Intrinsic::vector_reduce_and:
5741 case Intrinsic::vector_reduce_or:
5742 case Intrinsic::vector_reduce_xor:
5743 case Intrinsic::vector_reduce_add:
5744 case Intrinsic::vector_reduce_mul:
5745 case Intrinsic::vector_reduce_smax:
5746 case Intrinsic::vector_reduce_smin:
5747 case Intrinsic::vector_reduce_umax:
5748 case Intrinsic::vector_reduce_umin: {
5749 Type *ArgTy =
Call.getArgOperand(0)->getType();
5751 "Intrinsic has incorrect argument type!");
5754 case Intrinsic::vector_reduce_fmax:
5755 case Intrinsic::vector_reduce_fmin: {
5756 Type *ArgTy =
Call.getArgOperand(0)->getType();
5758 "Intrinsic has incorrect argument type!");
5761 case Intrinsic::vector_reduce_fadd:
5762 case Intrinsic::vector_reduce_fmul: {
5765 Type *ArgTy =
Call.getArgOperand(1)->getType();
5767 "Intrinsic has incorrect argument type!");
5770 case Intrinsic::smul_fix:
5771 case Intrinsic::smul_fix_sat:
5772 case Intrinsic::umul_fix:
5773 case Intrinsic::umul_fix_sat:
5774 case Intrinsic::sdiv_fix:
5775 case Intrinsic::sdiv_fix_sat:
5776 case Intrinsic::udiv_fix:
5777 case Intrinsic::udiv_fix_sat: {
5781 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
5784 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
5787 auto *Op3 = cast<ConstantInt>(
Call.getArgOperand(2));
5788 Check(Op3->getType()->isIntegerTy(),
5789 "third operand of [us][mul|div]_fix[_sat] must be an int type");
5790 Check(Op3->getBitWidth() <= 32,
5791 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
5793 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
5794 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
5796 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
5800 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
5801 "to the width of the operands");
5805 case Intrinsic::lrint:
5806 case Intrinsic::llrint: {
5807 Type *ValTy =
Call.getArgOperand(0)->getType();
5811 "llvm.lrint, llvm.llrint: argument must be floating-point or vector "
5812 "of floating-points, and result must be integer or vector of integers",
5815 "llvm.lrint, llvm.llrint: argument and result disagree on vector use",
5818 Check(cast<VectorType>(ValTy)->getElementCount() ==
5819 cast<VectorType>(ResultTy)->getElementCount(),
5820 "llvm.lrint, llvm.llrint: argument must be same length as result",
5825 case Intrinsic::lround:
5826 case Intrinsic::llround: {
5827 Type *ValTy =
Call.getArgOperand(0)->getType();
5830 "Intrinsic does not support vectors", &Call);
5833 case Intrinsic::bswap: {
5836 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &Call);
5839 case Intrinsic::invariant_start: {
5840 ConstantInt *InvariantSize = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5841 Check(InvariantSize &&
5843 "invariant_start parameter must be -1, 0 or a positive number",
5847 case Intrinsic::matrix_multiply:
5848 case Intrinsic::matrix_transpose:
5849 case Intrinsic::matrix_column_major_load:
5850 case Intrinsic::matrix_column_major_store: {
5856 Type *Op0ElemTy =
nullptr;
5857 Type *Op1ElemTy =
nullptr;
5859 case Intrinsic::matrix_multiply: {
5860 NumRows = cast<ConstantInt>(
Call.getArgOperand(2));
5862 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
5863 Check(cast<FixedVectorType>(
Call.getArgOperand(0)->getType())
5864 ->getNumElements() ==
5866 "First argument of a matrix operation does not match specified "
5868 Check(cast<FixedVectorType>(
Call.getArgOperand(1)->getType())
5869 ->getNumElements() ==
5871 "Second argument of a matrix operation does not match specified "
5874 ResultTy = cast<VectorType>(
Call.getType());
5876 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5878 cast<VectorType>(
Call.getArgOperand(1)->getType())->getElementType();
5881 case Intrinsic::matrix_transpose:
5882 NumRows = cast<ConstantInt>(
Call.getArgOperand(1));
5883 NumColumns = cast<ConstantInt>(
Call.getArgOperand(2));
5884 ResultTy = cast<VectorType>(
Call.getType());
5886 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5888 case Intrinsic::matrix_column_major_load: {
5889 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(1));
5890 NumRows = cast<ConstantInt>(
Call.getArgOperand(3));
5891 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
5892 ResultTy = cast<VectorType>(
Call.getType());
5895 case Intrinsic::matrix_column_major_store: {
5896 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(2));
5897 NumRows = cast<ConstantInt>(
Call.getArgOperand(4));
5898 NumColumns = cast<ConstantInt>(
Call.getArgOperand(5));
5899 ResultTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
5901 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
5908 Check(ResultTy->getElementType()->isIntegerTy() ||
5909 ResultTy->getElementType()->isFloatingPointTy(),
5910 "Result type must be an integer or floating-point type!", IF);
5913 Check(ResultTy->getElementType() == Op0ElemTy,
5914 "Vector element type mismatch of the result and first operand "
5919 Check(ResultTy->getElementType() == Op1ElemTy,
5920 "Vector element type mismatch of the result and second operand "
5924 Check(cast<FixedVectorType>(ResultTy)->getNumElements() ==
5926 "Result of a matrix operation does not fit in the returned vector!");
5930 "Stride must be greater or equal than the number of rows!", IF);
5934 case Intrinsic::experimental_vector_splice: {
5936 int64_t
Idx = cast<ConstantInt>(
Call.getArgOperand(2))->getSExtValue();
5937 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
5938 if (
Call.getParent() &&
Call.getParent()->getParent()) {
5940 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
5941 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
5943 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
5944 (
Idx >= 0 &&
Idx < KnownMinNumElements),
5945 "The splice index exceeds the range [-VL, VL-1] where VL is the "
5946 "known minimum number of elements in the vector. For scalable "
5947 "vectors the minimum number of elements is determined from "
5952 case Intrinsic::experimental_stepvector: {
5954 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
5955 VecTy->getScalarSizeInBits() >= 8,
5956 "experimental_stepvector only supported for vectors of integers "
5957 "with a bitwidth of at least 8.",
5961 case Intrinsic::vector_insert: {
5965 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
5972 Check(VecTy->getElementType() == SubVecTy->getElementType(),
5973 "vector_insert parameters must have the same element "
5977 "vector_insert index must be a constant multiple of "
5978 "the subvector's known minimum vector length.");
5986 "subvector operand of vector_insert would overrun the "
5987 "vector being inserted into.");
5991 case Intrinsic::vector_extract: {
5994 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6002 Check(ResultTy->getElementType() == VecTy->getElementType(),
6003 "vector_extract result must have the same element "
6004 "type as the input vector.",
6007 "vector_extract index must be a constant multiple of "
6008 "the result type's known minimum vector length.");
6016 "vector_extract would overrun.");
6020 case Intrinsic::experimental_noalias_scope_decl: {
6021 NoAliasScopeDecls.
push_back(cast<IntrinsicInst>(&Call));
6024 case Intrinsic::preserve_array_access_index:
6025 case Intrinsic::preserve_struct_access_index:
6026 case Intrinsic::aarch64_ldaxr:
6027 case Intrinsic::aarch64_ldxr:
6028 case Intrinsic::arm_ldaex:
6029 case Intrinsic::arm_ldrex: {
6030 Type *ElemTy =
Call.getParamElementType(0);
6031 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6035 case Intrinsic::aarch64_stlxr:
6036 case Intrinsic::aarch64_stxr:
6037 case Intrinsic::arm_stlex:
6038 case Intrinsic::arm_strex: {
6039 Type *ElemTy =
Call.getAttributes().getParamElementType(1);
6041 "Intrinsic requires elementtype attribute on second argument.",
6045 case Intrinsic::aarch64_prefetch: {
6046 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
6047 "write argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6048 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
6049 "target argument to llvm.aarch64.prefetch must be 0-3", Call);
6050 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
6051 "stream argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6052 Check(cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue() < 2,
6053 "isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6056 case Intrinsic::callbr_landingpad: {
6057 const auto *CBR = dyn_cast<CallBrInst>(
Call.getOperand(0));
6058 Check(CBR,
"intrinstic requires callbr operand", &Call);
6065 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &Call);
6069 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6075 return IndDest == LandingPadBB;
6077 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6078 "block in indirect destination list",
6081 Check(&
First == &Call,
"No other instructions may proceed intrinsic",
6085 case Intrinsic::amdgcn_cs_chain: {
6086 auto CallerCC =
Call.getCaller()->getCallingConv();
6093 CheckFailed(
"Intrinsic can only be used from functions with the "
6094 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6095 "calling conventions",
6100 Check(
Call.paramHasAttr(2, Attribute::InReg),
6101 "SGPR arguments must have the `inreg` attribute", &Call);
6102 Check(!
Call.paramHasAttr(3, Attribute::InReg),
6103 "VGPR arguments must not have the `inreg` attribute", &Call);
6106 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6107 auto CallerCC =
Call.getCaller()->getCallingConv();
6113 CheckFailed(
"Intrinsic can only be used from functions with the "
6114 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6115 "calling conventions",
6120 unsigned InactiveIdx = 1;
6121 Check(!
Call.paramHasAttr(InactiveIdx, Attribute::InReg),
6122 "Value for inactive lanes must not have the `inreg` attribute",
6124 Check(isa<Argument>(
Call.getArgOperand(InactiveIdx)),
6125 "Value for inactive lanes must be a function argument", &Call);
6126 Check(!cast<Argument>(
Call.getArgOperand(InactiveIdx))->hasInRegAttr(),
6127 "Value for inactive lanes must be a VGPR function argument", &Call);
6130 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6131 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6133 unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
6134 Check(RegCount % 8 == 0,
6135 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6136 Check((RegCount >= 24 && RegCount <= 256),
6137 "reg_count argument to nvvm.setmaxnreg must be within [24, 256]");
6140 case Intrinsic::experimental_convergence_entry:
6142 case Intrinsic::experimental_convergence_anchor:
6144 case Intrinsic::experimental_convergence_loop:
6146 case Intrinsic::ptrmask: {
6147 Type *Ty0 =
Call.getArgOperand(0)->getType();
6148 Type *Ty1 =
Call.getArgOperand(1)->getType();
6150 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6155 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6158 Check(cast<VectorType>(Ty0)->getElementCount() ==
6159 cast<VectorType>(Ty1)->getElementCount(),
6160 "llvm.ptrmask intrinsic arguments must have the same number of "
6164 "llvm.ptrmask intrinsic second argument bitwidth must match "
6165 "pointer index type size of first argument",
6174 if (
F->hasPersonalityFn() &&
6178 if (BlockEHFuncletColors.
empty())
6182 bool InEHFunclet =
false;
6187 if (dyn_cast_or_null<FuncletPadInst>(ColorFirstBB->getFirstNonPHI()))
6191 bool HasToken =
false;
6192 for (
unsigned I = 0,
E =
Call.getNumOperandBundles();
I !=
E; ++
I)
6198 Check(HasToken,
"Missing funclet token on intrinsic call", &Call);
6211 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
6214 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
6218 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
6222void Verifier::visit(
DPLabel &DPL) {
6224 "invalid #dbg_label intrinsic variable", &DPL, DPL.
getRawLabel());
6228 if (!isa<DILocation>(
N))
6237 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DPL, BB,
F);
6241 if (!LabelSP || !LocSP)
6245 "mismatched subprogram between #dbg_label label and !dbg attachment",
6246 &DPL, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6247 Loc->getScope()->getSubprogram());
6250void Verifier::visit(
DPValue &DPV) {
6257 "invalid #dbg record type", &DPV, DPV.
getType());
6262 CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6263 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())),
6264 "invalid #dbg record address/value", &DPV, MD);
6265 if (
auto *VAM = dyn_cast<ValueAsMetadata>(MD))
6266 visitValueAsMetadata(*VAM,
F);
6267 else if (
auto *AL = dyn_cast<DIArgList>(MD))
6268 visitDIArgList(*AL,
F);
6282 AreDebugLocsAllowed::No);
6289 isa<ValueAsMetadata>(RawAddr) ||
6290 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6292 if (
auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr))
6293 visitValueAsMetadata(*VAM,
F);
6296 "invalid #dbg_assign address expression", &DPV,
6303 "inst not in same function as #dbg_assign",
I, &DPV);
6312 CheckDI(isa_and_nonnull<DILocation>(DLNode),
"invalid #dbg record DILocation",
6319 if (!VarSP || !LocSP)
6323 "mismatched subprogram between #dbg record variable and DILocation",
6325 Loc->getScope()->getSubprogram());
6330void Verifier::visitVPIntrinsic(
VPIntrinsic &VPI) {
6331 if (
auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6332 auto *
RetTy = cast<VectorType>(VPCast->getType());
6333 auto *ValTy = cast<VectorType>(VPCast->getOperand(0)->getType());
6334 Check(
RetTy->getElementCount() == ValTy->getElementCount(),
6335 "VP cast intrinsic first argument and result vector lengths must be "
6339 switch (VPCast->getIntrinsicID()) {
6342 case Intrinsic::vp_trunc:
6344 "llvm.vp.trunc intrinsic first argument and result element type "
6348 "llvm.vp.trunc intrinsic the bit size of first argument must be "
6349 "larger than the bit size of the return type",
6352 case Intrinsic::vp_zext:
6353 case Intrinsic::vp_sext:
6355 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
6356 "element type must be integer",
6359 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
6360 "argument must be smaller than the bit size of the return type",
6363 case Intrinsic::vp_fptoui:
6364 case Intrinsic::vp_fptosi:
6365 case Intrinsic::vp_lrint:
6366 case Intrinsic::vp_llrint:
6369 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
6370 "type must be floating-point and result element type must be integer",
6373 case Intrinsic::vp_uitofp:
6374 case Intrinsic::vp_sitofp:
6377 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
6378 "type must be integer and result element type must be floating-point",
6381 case Intrinsic::vp_fptrunc:
6383 "llvm.vp.fptrunc intrinsic first argument and result element type "
6384 "must be floating-point",
6387 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
6388 "larger than the bit size of the return type",
6391 case Intrinsic::vp_fpext:
6393 "llvm.vp.fpext intrinsic first argument and result element type "
6394 "must be floating-point",
6397 "llvm.vp.fpext intrinsic the bit size of first argument must be "
6398 "smaller than the bit size of the return type",
6401 case Intrinsic::vp_ptrtoint:
6403 "llvm.vp.ptrtoint intrinsic first argument element type must be "
6404 "pointer and result element type must be integer",
6407 case Intrinsic::vp_inttoptr:
6409 "llvm.vp.inttoptr intrinsic first argument element type must be "
6410 "integer and result element type must be pointer",
6416 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6418 "invalid predicate for VP FP comparison intrinsic", &VPI);
6421 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6423 "invalid predicate for VP integer comparison intrinsic", &VPI);
6426 auto TestMask = cast<ConstantInt>(VPI.
getOperand(1));
6428 "unsupported bits for llvm.vp.is.fpclass test mask");
6433 unsigned NumOperands;
6436#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
6437 case Intrinsic::INTRINSIC: \
6438 NumOperands = NARG; \
6439 HasRoundingMD = ROUND_MODE; \
6441#include "llvm/IR/ConstrainedOps.def"
6445 NumOperands += (1 + HasRoundingMD);
6447 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
6450 "invalid arguments for constrained FP intrinsic", &FPI);
6453 case Intrinsic::experimental_constrained_lrint:
6454 case Intrinsic::experimental_constrained_llrint: {
6458 "Intrinsic does not support vectors", &FPI);
6462 case Intrinsic::experimental_constrained_lround:
6463 case Intrinsic::experimental_constrained_llround: {
6467 "Intrinsic does not support vectors", &FPI);
6471 case Intrinsic::experimental_constrained_fcmp:
6472 case Intrinsic::experimental_constrained_fcmps: {
6473 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
6475 "invalid predicate for constrained FP comparison intrinsic", &FPI);
6479 case Intrinsic::experimental_constrained_fptosi:
6480 case Intrinsic::experimental_constrained_fptoui: {
6484 "Intrinsic first argument must be floating point", &FPI);
6485 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6486 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6491 "Intrinsic first argument and result disagree on vector use", &FPI);
6493 "Intrinsic result must be an integer", &FPI);
6494 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6495 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6496 "Intrinsic first argument and result vector lengths must be equal",
6502 case Intrinsic::experimental_constrained_sitofp:
6503 case Intrinsic::experimental_constrained_uitofp: {
6507 "Intrinsic first argument must be integer", &FPI);
6508 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6509 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6514 "Intrinsic first argument and result disagree on vector use", &FPI);
6516 "Intrinsic result must be a floating point", &FPI);
6517 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6518 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6519 "Intrinsic first argument and result vector lengths must be equal",
6524 case Intrinsic::experimental_constrained_fptrunc:
6525 case Intrinsic::experimental_constrained_fpext: {
6531 "Intrinsic first argument must be FP or FP vector", &FPI);
6533 "Intrinsic result must be FP or FP vector", &FPI);
6535 "Intrinsic first argument and result disagree on vector use", &FPI);
6537 Check(cast<VectorType>(OperandTy)->getElementCount() ==
6538 cast<VectorType>(ResultTy)->getElementCount(),
6539 "Intrinsic first argument and result vector lengths must be equal",
6542 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
6544 "Intrinsic first argument's type must be larger than result type",
6548 "Intrinsic first argument's type must be smaller than result type",
6564 "invalid exception behavior argument", &FPI);
6565 if (HasRoundingMD) {
6573 CheckDI(isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6574 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
6575 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
6577 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
6580 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
6583 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(&DII)) {
6584 CheckDI(isa<DIAssignID>(DAI->getRawAssignID()),
6585 "invalid llvm.dbg.assign intrinsic DIAssignID", &DII,
6586 DAI->getRawAssignID());
6587 const auto *RawAddr = DAI->getRawAddress();
6589 isa<ValueAsMetadata>(RawAddr) ||
6590 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6591 "invalid llvm.dbg.assign intrinsic address", &DII,
6592 DAI->getRawAddress());
6593 CheckDI(isa<DIExpression>(DAI->getRawAddressExpression()),
6594 "invalid llvm.dbg.assign intrinsic address expression", &DII,
6595 DAI->getRawAddressExpression());
6598 CheckDI(DAI->getFunction() ==
I->getFunction(),
6599 "inst not in same function as dbg.assign",
I, DAI);
6604 if (!isa<DILocation>(
N))
6613 CheckDI(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
6618 if (!VarSP || !LocSP)
6622 "mismatched subprogram between llvm.dbg." + Kind +
6623 " variable and !dbg attachment",
6625 Loc->getScope()->getSubprogram());
6635 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DLI,
6640 if (!isa<DILocation>(
N))
6649 Check(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment", &DLI,
6654 if (!LabelSP || !LocSP)
6658 "mismatched subprogram between llvm.dbg." + Kind +
6659 " label and !dbg attachment",
6660 &DLI, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6661 Loc->getScope()->getSubprogram());
6666 DIExpression *
E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6669 if (!V || !
E || !
E->isValid())
6673 auto Fragment =
E->getFragmentInfo();
6683 if (
V->isArtificial())
6686 verifyFragmentExpression(*V, *Fragment, &
I);
6688void Verifier::verifyFragmentExpression(
const DPValue &DPV) {
6693 if (!V || !
E || !
E->isValid())
6697 auto Fragment =
E->getFragmentInfo();
6707 if (
V->isArtificial())
6710 verifyFragmentExpression(*V, *Fragment, &DPV);
6713template <
typename ValueOrMetadata>
6714void Verifier::verifyFragmentExpression(
const DIVariable &V,
6716 ValueOrMetadata *
Desc) {
6719 auto VarSize =
V.getSizeInBits();
6725 CheckDI(FragSize + FragOffset <= *VarSize,
6726 "fragment is larger than or outside of variable",
Desc, &V);
6727 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
6738 if (
I.getDebugLoc()->getInlinedAt())
6742 CheckDI(Var,
"dbg intrinsic without variable");
6744 unsigned ArgNo = Var->
getArg();
6750 if (DebugFnArgs.
size() < ArgNo)
6751 DebugFnArgs.
resize(ArgNo,
nullptr);
6753 auto *Prev = DebugFnArgs[ArgNo - 1];
6754 DebugFnArgs[ArgNo - 1] = Var;
6755 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &
I,
6758void Verifier::verifyFnArgs(
const DPValue &DPV) {
6770 CheckDI(Var,
"#dbg record without variable");
6772 unsigned ArgNo = Var->
getArg();
6778 if (DebugFnArgs.
size() < ArgNo)
6779 DebugFnArgs.
resize(ArgNo,
nullptr);
6781 auto *Prev = DebugFnArgs[ArgNo - 1];
6782 DebugFnArgs[ArgNo - 1] = Var;
6783 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DPV,
6788 DIExpression *
E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6791 if (!
E || !
E->isValid())
6794 if (isa<ValueAsMetadata>(
I.getRawLocation())) {
6795 Value *VarValue =
I.getVariableLocationOp(0);
6796 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6800 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6801 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6806 "Entry values are only allowed in MIR unless they target a "
6807 "swiftasync Argument",
6810void Verifier::verifyNotEntryValue(
const DPValue &DPV) {
6814 if (!
E || !
E->isValid())
6819 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6823 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6824 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6829 "Entry values are only allowed in MIR unless they target a "
6830 "swiftasync Argument",
6834void Verifier::verifyCompileUnits() {
6838 if (
M.getContext().isODRUniquingDebugTypes())
6840 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
6843 Listed.
insert(CUs->op_begin(), CUs->op_end());
6844 for (
const auto *
CU : CUVisited)
6849void Verifier::verifyDeoptimizeCallingConvs() {
6850 if (DeoptimizeDeclarations.
empty())
6854 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
6855 Check(
First->getCallingConv() ==
F->getCallingConv(),
6856 "All llvm.experimental.deoptimize declarations must have the same "
6857 "calling convention",
6862void Verifier::verifyAttachedCallBundle(
const CallBase &Call,
6866 Check((FTy->getReturnType()->isPointerTy() ||
6867 (
Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())),
6868 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
6869 "function returning a pointer or a non-returning function that has a "
6874 "operand bundle \"clang.arc.attachedcall\" requires one function as "
6878 auto *Fn = cast<Function>(BU.
Inputs.front());
6882 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
6883 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
6884 "invalid function argument", Call);
6887 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
6888 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
6889 "invalid function argument", Call);
6893void Verifier::verifyNoAliasScopeDecl() {
6894 if (NoAliasScopeDecls.
empty())
6898 for (
auto *II : NoAliasScopeDecls) {
6899 assert(II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
6900 "Not a llvm.experimental.noalias.scope.decl ?");
6901 const auto *ScopeListMV = dyn_cast<MetadataAsValue>(
6903 Check(ScopeListMV !=
nullptr,
6904 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
6908 const auto *ScopeListMD = dyn_cast<MDNode>(ScopeListMV->getMetadata());
6909 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode", II);
6910 Check(ScopeListMD->getNumOperands() == 1,
6911 "!id.scope.list must point to a list with a single scope", II);
6912 visitAliasScopeListMetadata(ScopeListMD);
6923 const auto *ScopeListMV = cast<MetadataAsValue>(
6925 return &cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
6931 return GetScope(Lhs) < GetScope(Rhs);
6938 auto ItCurrent = NoAliasScopeDecls.begin();
6939 while (ItCurrent != NoAliasScopeDecls.end()) {
6940 auto CurScope = GetScope(*ItCurrent);
6941 auto ItNext = ItCurrent;
6944 }
while (ItNext != NoAliasScopeDecls.end() &&
6945 GetScope(*ItNext) == CurScope);
6950 if (ItNext - ItCurrent < 32)
6955 "llvm.experimental.noalias.scope.decl dominates another one "
6956 "with the same scope",
6974 return !V.verify(
F);
6978 bool *BrokenDebugInfo) {
6982 bool Broken =
false;
6984 Broken |= !V.verify(
F);
6986 Broken |= !V.verify();
6987 if (BrokenDebugInfo)
6988 *BrokenDebugInfo = V.hasBrokenDebugInfo();
6999 std::unique_ptr<Verifier> V;
7000 bool FatalErrors =
true;
7005 explicit VerifierLegacyPass(
bool FatalErrors)
7007 FatalErrors(FatalErrors) {
7011 bool doInitialization(
Module &M)
override {
7012 V = std::make_unique<Verifier>(
7018 if (!
V->verify(
F) && FatalErrors) {
7019 errs() <<
"in function " <<
F.getName() <<
'\n';
7025 bool doFinalization(
Module &M)
override {
7026 bool HasErrors =
false;
7028 if (
F.isDeclaration())
7029 HasErrors |= !
V->verify(
F);
7031 HasErrors |= !
V->verify();
7032 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7045template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7050#define CheckTBAA(C, ...) \
7053 CheckFailed(__VA_ARGS__); \
7061TBAAVerifier::TBAABaseNodeSummary
7065 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7069 auto Itr = TBAABaseNodes.find(BaseNode);
7070 if (Itr != TBAABaseNodes.end())
7073 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7074 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7076 assert(InsertResult.second &&
"We just checked!");
7080TBAAVerifier::TBAABaseNodeSummary
7083 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7087 return isValidScalarTBAANode(BaseNode)
7088 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7094 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7095 "multiple of 3!", BaseNode);
7100 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7108 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7110 if (!TypeSizeNode) {
7111 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7117 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
7118 CheckFailed(
"Struct tag nodes have a string as their first operand",
7125 std::optional<APInt> PrevOffset;
7130 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7131 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7133 Idx += NumOpsPerField) {
7136 if (!isa<MDNode>(FieldTy)) {
7137 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7142 auto *OffsetEntryCI =
7143 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
7144 if (!OffsetEntryCI) {
7145 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7151 BitWidth = OffsetEntryCI->getBitWidth();
7153 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7155 "Bitwidth between the offsets and struct type entries must match", &
I,
7167 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7170 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7174 PrevOffset = OffsetEntryCI->getValue();
7177 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7179 if (!MemberSizeNode) {
7180 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7187 return Failed ? InvalidNode
7188 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7209 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
7210 return Parent && Visited.
insert(Parent).second &&
7214bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7215 auto ResultIt = TBAAScalarNodes.find(MD);
7216 if (ResultIt != TBAAScalarNodes.end())
7217 return ResultIt->second;
7221 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7223 assert(InsertResult.second &&
"Just checked!");
7242 return cast<MDNode>(BaseNode->
getOperand(1));
7244 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7245 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7247 Idx += NumOpsPerField) {
7248 auto *OffsetEntryCI =
7249 mdconst::extract<ConstantInt>(BaseNode->
getOperand(
Idx + 1));
7250 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7251 if (
Idx == FirstFieldOpNo) {
7252 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7257 unsigned PrevIdx =
Idx - NumOpsPerField;
7258 auto *PrevOffsetEntryCI =
7259 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
7260 Offset -= PrevOffsetEntryCI->getValue();
7261 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
7266 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
7268 Offset -= LastOffsetEntryCI->getValue();
7269 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
7273 if (!
Type ||
Type->getNumOperands() < 3)
7278 return isa_and_nonnull<MDNode>(
Type->getOperand(0));
7285 CheckTBAA(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<CallInst>(
I) ||
7286 isa<VAArgInst>(
I) || isa<AtomicRMWInst>(
I) ||
7287 isa<AtomicCmpXchgInst>(
I),
7288 "This instruction shall not have a TBAA access tag!", &
I);
7290 bool IsStructPathTBAA =
7294 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7304 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7307 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7312 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7314 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7318 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7320 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
7323 "Immutability tag on struct tag metadata must be a constant", &
I,
7326 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7327 "Immutability part of the struct tag metadata must be either 0 or 1",
7332 "Malformed struct tag metadata: base and access-type "
7333 "should be non-null and point to Metadata nodes",
7334 &
I, MD, BaseNode, AccessType);
7337 CheckTBAA(isValidScalarTBAANode(AccessType),
7338 "Access type node must be a valid scalar type", &
I, MD,
7342 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
7343 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7346 bool SeenAccessTypeInPath =
false;
7351 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7353 if (!StructPath.
insert(BaseNode).second) {
7354 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7359 unsigned BaseNodeBitWidth;
7360 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7368 SeenAccessTypeInPath |= BaseNode == AccessType;
7370 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7371 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7375 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7376 (IsNewFormat && BaseNodeBitWidth == ~0u),
7377 "Access bit-width not the same as description bit-width", &
I, MD,
7378 BaseNodeBitWidth,
Offset.getBitWidth());
7380 if (IsNewFormat && SeenAccessTypeInPath)
7384 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7389char VerifierLegacyPass::ID = 0;
7390INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7393 return new VerifierLegacyPass(FatalErrors);
7411 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7419 if (res.IRBroken && FatalErrors)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
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...
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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")
Analysis containing CSE Info
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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 provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file implements a map that provides insertion order iteration.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the SmallVector class.
This defines the Use 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)
#define Check(C,...)
We know that cond should be true, if not print an error message.
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 DISubprogram * getSubprogram(Metadata *LocalScope)
Carefully grab the subprogram from a local scope.
static bool isTypeCongruent(Type *L, Type *R)
Two types are "congruent" if they are identical, or if they are both pointer types with different poi...
static bool IsRootTBAANode(const MDNode *MD)
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
static Value * getParentPad(Value *EHPad)
static bool hasConflictingReferenceFlags(unsigned Flags)
Detect mutually exclusive flags.
static AttrBuilder getParameterABIAttributes(LLVMContext &C, unsigned I, AttributeList Attrs)
bool isFiniteNonZero() const
const fltSemantics & getSemantics() const
Class for arbitrary precision integers.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
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.
bool isMaxValue() const
Determine if this is the largest unsigned value.
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
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.
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.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
static bool isFPOperation(BinOp Op)
BinOp getOperation() const
static 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.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
std::string getAsString(bool InAttrGrp=false) const
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static bool canUseAsRetAttr(AttrKind Kind)
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
static bool canUseAsFnAttr(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
static bool isIntAttrKind(AttrKind Kind)
static bool canUseAsParamAttr(AttrKind Kind)
bool isValid() const
Return true if the attribute is any kind of attribute.
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 LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Instruction & front() const
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
const Function * getParent() const
Return the enclosing method, or null if none.
InstListType::iterator iterator
Instruction iterators...
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This class represents a no-op cast from one type to another.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
bool isConditional() const
Value * getCondition() const
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.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
bool isMustTailCall() const
static 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)
ConstantArray - Constant Array Declarations.
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
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.
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.
This class represents a range of values.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This is an important base class in LLVM.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
This is the common base class for constrained floating point intrinsics.
std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
std::optional< RoundingMode > getRoundingMode() const
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
An imported module (C++ using directive or similar).
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
DILocalScope * getScope() const
Get the local scope for this variable.
Metadata * getRawScope() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Base class for scope-like contexts.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
Base class for template parameters.
Base class for variables.
Metadata * getRawType() const
Metadata * getRawScope() const
Records a position in IR for a source label (DILabel).
MDNode * getRawLabel() const
DILabel * getLabel() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIExpression * getExpression() const
MDNode * getRawVariable() const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
DIExpression * getAddressExpression() const
LocationType getType() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAssignID() const
Value * getVariableLocationOp(unsigned OpIdx) const
Metadata * getRawAddress() const
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
DILocalVariable * getVariable() const
This class represents an Operation in the Expression.
uint64_t getNumOperands() const
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.label instruction.
Metadata * getRawLabel() const
DILabel * getLabel() const
Base class for non-instruction debug metadata records that have positions within IR.
void print(raw_ostream &O, bool IsForDebug=false) const
DebugLoc getDebugLoc() const
const BasicBlock * getParent() const
This is the common base class for debug info intrinsics for variables.
Metadata * getRawLocation() const
DILocalVariable * getVariable() const
Metadata * getRawVariable() const
Metadata * getRawExpression() const
MDNode * getAsMDNode() const
Return this as a bar MDNode.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction compares its operands according to the predicate given to the constructor.
This class represents an extension of floating point types.
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.
An instruction for ordering other memory operations.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Value * getParentPad() const
Convenience accessors.
FunctionPass class - This class is used to implement most global optimizations.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
const std::string & getGC() const
Represents calls to the gc.relocate intrinsic.
Value * getBasePtr() const
Value * getDerivedPtr() const
void initialize(raw_ostream *OS, function_ref< void(const Twine &Message)> FailureCB, const FunctionT &F)
void verify(const DominatorTreeT &DT)
void visit(const BlockT &BB)
Generic tagged DWARF-like metadata node.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static 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
const Function * getResolverFunction() const
static FunctionType * getResolverFunctionType(Type *IFuncValTy)
static bool isValidLinkage(LinkageTypes L)
const Constant * getResolver() const
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool hasExternalLinkage() const
bool isImplicitDSOLocal() const
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.
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.
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.
Indirect Branch Instruction.
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 bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
This instruction inserts a struct field of array element value into an aggregate value.
Value * getAggregateOperand()
ArrayRef< unsigned > getIndices() const
Base class for instruction visitors.
RetTy visitTerminator(Instruction &I)
RetTy visitCallBase(CallBase &I)
void visitFunction(Function &F)
void visitBasicBlock(BasicBlock &BB)
void visit(Iterator Start, Iterator End)
RetTy visitFuncletPadInst(FuncletPadInst &I)
void visitInstruction(Instruction &I)
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.
bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
const BasicBlock * getParent() const
const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
A wrapper class for inspecting calls to intrinsic functions.
static 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.
BasicBlock * getUnwindDest() const
This is an important class for using LLVM in a threaded context.
@ OB_clang_arc_attachedcall
The landingpad instruction holds all of the information necessary to generate correct exception handl...
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.
An instruction for reading from memory.
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
Tracking metadata reference owned by Metadata.
StringRef getString() const
Typed, array-like tuple of metadata.
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.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
@ Warning
Emits a warning if two values disagree.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
@ Min
Takes the min of the two values, which are required to be integers.
@ Append
Appends the two values, which are required to be metadata nodes.
@ Max
Takes the max of the two values, which are required to be integers.
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
StringRef getName() const
void print(raw_ostream &ROS, bool IsForDebug=false) const
iterator_range< op_iterator > operands()
op_range incoming_values()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
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.
Simple wrapper around std::function<void(raw_ostream&)>.
This class represents a cast from a pointer to an integer.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Resume the propagation of an exception.
Value * getValue() const
Convenience accessor.
Return a value (possibly void), from a function.
This class represents a sign extension of integer types.
This class represents a cast from signed integer to floating point.
This class represents the LLVM 'select' instruction.
static 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 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 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.
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
An instruction for storing to memory.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
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.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
static constexpr size_t npos
Class to represent struct types.
unsigned getNumElements() const
Random access to the elements.
bool containsScalableVectorType(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Returns true if this struct contains a scalable vector.
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Verify that the TBAA Metadatas are valid.
bool visitTBAAMetadata(Instruction &I, const MDNode *MD)
Visit an instruction and return true if it is valid, return false if an invalid TBAA is attached.
@ CanBeGlobal
This type may be used as the value type of a global variable.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
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 isVectorTy() const
True if this is an instance of VectorType.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isArrayTy() const
True if this is an instance of ArrayType.
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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this 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 isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
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 isTokenTy() const
Return true if this is 'token'.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isMetadataTy() const
Return true if this is 'metadata'.
This class represents a cast unsigned integer to floating point.
A Use represents the edge between a Value definition and its users.
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...
This is the common base class for vector predication intrinsics.
LLVM Value Representation.
iterator_range< user_iterator > materialized_users()
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
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
LLVMContext & getContext() const
All values hold a context through their type.
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.
Result run(Module &M, ModuleAnalysisManager &)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class represents zero extension of integer types.
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.
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
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.
@ AMDGPU_CS
Used for Mesa/AMDPAL compute shaders.
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ AMDGPU_CS_ChainPreserve
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
@ X86_INTR
x86 hardware interrupt context.
@ AMDGPU_CS_Chain
Used on AMDGPUs to give the middle-end more control over argument placement.
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ PTX_Device
Call to a PTX device function.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ C
The default llvm calling convention, compatible with C.
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
MatchIntrinsicTypesResult
@ MatchIntrinsicTypes_NoMatchRet
@ MatchIntrinsicTypes_NoMatchArg
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
static const int NoAliasScopeDeclScopeArg
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
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)
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
bool isFortran(SourceLanguage S)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
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.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
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()
void initializeVerifierLegacyPassPass(PassRegistry &)
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.
DenseMap< BasicBlock *, ColorVector > colorEHFunclets(Function &F)
If an EH funclet personality is in use (see isFuncletEHPersonality), this will recompute which blocks...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ ArgMem
Access to memory via argument pointers.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
FunctionPass * createVerifierPass(bool FatalErrors=true)
@ Invalid
Denotes invalid value.
@ Dynamic
Denotes mode unknown at compile time.
@ MaskAll
A bitmask that includes all valid flags.
constexpr unsigned BitWidth
std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
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 verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
static const fltSemantics & IEEEsingle() LLVM_READNONE
This struct is a compact representation of a valid (non-zero power of two) alignment.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Holds the characteristics of one fragment of a larger variable.
Description of the encoding of one expression Op.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
A lightweight accessor for an operand bundle meant to be passed around by value.
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).