97#include "llvm/IR/IntrinsicsAArch64.h"
98#include "llvm/IR/IntrinsicsAMDGPU.h"
99#include "llvm/IR/IntrinsicsARM.h"
100#include "llvm/IR/IntrinsicsNVPTX.h"
101#include "llvm/IR/IntrinsicsWebAssembly.h"
136 cl::desc(
"Ensure that llvm.experimental.noalias.scope.decl for identical "
137 "scopes are not dominating"));
165 void Write(
const Value *V) {
170 void Write(
const Value &V) {
171 if (isa<Instruction>(V)) {
175 V.printAsOperand(*
OS,
true,
MST);
225 void Write(
Type *
T) {
237 void Write(
const APInt *AI) {
243 void Write(
const unsigned i) { *
OS << i <<
'\n'; }
249 *
OS <<
A->getAsString() <<
'\n';
269 for (
const T &V : Vs)
273 template <
typename T1,
typename... Ts>
274 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
279 template <
typename... Ts>
void WriteTs() {}
288 *
OS << Message <<
'\n';
296 template <
typename T1,
typename... Ts>
306 *
OS << Message <<
'\n';
312 template <
typename T1,
typename... Ts>
333 static constexpr unsigned ParamMaxAlignment = 1 << 14;
353 Type *LandingPadResultTy;
360 bool HasDebugInfo =
false;
406 SawFrameEscape(
false), TBAAVerifyHelper(this) {
407 TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
414 "An instance of this class only works with a specific module!");
426 if (!BB.empty() && BB.back().isTerminator())
430 *
OS <<
"Basic Block in function '" <<
F.getName()
431 <<
"' does not have terminator!\n";
432 BB.printAsOperand(*
OS,
true, MST);
438 auto FailureCB = [
this](
const Twine &Message) {
446 verifySiblingFuncletUnwinds();
449 ConvergenceVerifyHelper.
verify(DT);
451 InstsInThisBlock.
clear();
453 LandingPadResultTy =
nullptr;
454 SawFrameEscape =
false;
455 SiblingFuncletInfo.
clear();
456 verifyNoAliasScopeDecl();
457 NoAliasScopeDecls.
clear();
468 if (
F.getIntrinsicID() == Intrinsic::experimental_deoptimize)
473 verifyFrameRecoverIndices();
475 visitGlobalVariable(GV);
478 visitGlobalAlias(GA);
481 visitGlobalIFunc(GI);
484 visitNamedMDNode(NMD);
487 visitComdat(SMEC.getValue());
491 visitModuleCommandLines();
493 verifyCompileUnits();
495 verifyDeoptimizeCallingConvs();
496 DISubprogramAttachments.
clear();
502 enum class AreDebugLocsAllowed {
No,
Yes };
513 void visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs);
517 void visitComdat(
const Comdat &
C);
518 void visitModuleIdents();
519 void visitModuleCommandLines();
520 void visitModuleFlags();
521 void visitModuleFlag(
const MDNode *
Op,
524 void visitModuleFlagCGProfileEntry(
const MDOperand &MDO);
528 bool IsAbsoluteSymbol);
532 void visitCallStackMetadata(
MDNode *MD);
537 void visitAnnotationMetadata(
MDNode *Annotation);
538 void visitAliasScopeMetadata(
const MDNode *MD);
539 void visitAliasScopeListMetadata(
const MDNode *MD);
540 void visitAccessGroupMetadata(
const MDNode *MD);
542 template <
class Ty>
bool isValidMetadataArray(
const MDTuple &
N);
543#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
544#include "llvm/IR/Metadata.def"
545 void visitDIScope(
const DIScope &
N);
572 void visitPHINode(
PHINode &PN);
581 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
619 void verifySwiftErrorCall(
CallBase &Call,
const Value *SwiftErrorVal);
620 void verifySwiftErrorValue(
const Value *SwiftErrorVal);
622 void verifyMustTailCall(
CallInst &CI);
623 bool verifyAttributeCount(
AttributeList Attrs,
unsigned Params);
629 const Value *V,
bool IsIntrinsic,
bool IsInlineAsm);
630 void verifyFunctionMetadata(
ArrayRef<std::pair<unsigned, MDNode *>> MDs);
632 void visitConstantExprsRecursively(
const Constant *EntryC);
635 void verifyInlineAsmCall(
const CallBase &Call);
636 void verifyStatepoint(
const CallBase &Call);
637 void verifyFrameRecoverIndices();
638 void verifySiblingFuncletUnwinds();
642 template <
typename ValueOrMetadata>
643 void verifyFragmentExpression(
const DIVariable &V,
645 ValueOrMetadata *
Desc);
652 void verifyCompileUnits();
656 void verifyDeoptimizeCallingConvs();
658 void verifyAttachedCallBundle(
const CallBase &Call,
662 void verifyNoAliasScopeDecl();
668#define Check(C, ...) \
671 CheckFailed(__VA_ARGS__); \
678#define CheckDI(C, ...) \
681 DebugInfoCheckFailed(__VA_ARGS__); \
689 CheckDI(
I.DebugMarker->MarkedInstr == &
I,
690 "Instruction has invalid DebugMarker", &
I);
691 CheckDI(!isa<PHINode>(&
I) || !
I.hasDbgRecords(),
692 "PHI Node must not have any attached DbgRecords", &
I);
695 "DbgRecord had invalid DebugMarker", &
I, &DR);
698 visitMDNode(*Loc, AreDebugLocsAllowed::Yes);
699 if (
auto *DVR = dyn_cast<DbgVariableRecord>(&DR)) {
703 verifyFragmentExpression(*DVR);
704 verifyNotEntryValue(*DVR);
705 }
else if (
auto *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
713 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
714 Check(
I.getOperand(i) !=
nullptr,
"Operand is null", &
I);
727 while (!WorkList.
empty()) {
729 if (!Visited.
insert(Cur).second)
736void Verifier::visitGlobalValue(
const GlobalValue &GV) {
738 "Global is external, but doesn't have external or weak linkage!", &GV);
740 if (
const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
744 "huge alignment values are unsupported", GO);
747 if (
const MDNode *Associated =
748 GO->getMetadata(LLVMContext::MD_associated)) {
749 Check(Associated->getNumOperands() == 1,
750 "associated metadata must have one operand", &GV, Associated);
751 const Metadata *
Op = Associated->getOperand(0).get();
752 Check(
Op,
"associated metadata must have a global value", GO, Associated);
754 const auto *VM = dyn_cast_or_null<ValueAsMetadata>(
Op);
755 Check(VM,
"associated metadata must be ValueAsMetadata", GO, Associated);
757 Check(isa<PointerType>(VM->getValue()->getType()),
758 "associated value must be pointer typed", GV, Associated);
761 Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
762 "associated metadata must point to a GlobalObject", GO, Stripped);
763 Check(Stripped != GO,
764 "global values should not associate to themselves", GO,
770 if (
const MDNode *AbsoluteSymbol =
771 GO->getMetadata(LLVMContext::MD_absolute_symbol)) {
772 verifyRangeMetadata(*GO, AbsoluteSymbol,
DL.getIntPtrType(GO->getType()),
778 "Only global variables can have appending linkage!", &GV);
783 "Only global arrays can have appending linkage!", GVar);
787 Check(!GV.
hasComdat(),
"Declaration may not be in a Comdat!", &GV);
791 "dllexport GlobalValue must have default or protected visibility",
796 "dllimport GlobalValue must have default visibility", &GV);
797 Check(!GV.
isDSOLocal(),
"GlobalValue with DLLImport Storage is dso_local!",
803 "Global is marked as dllimport, but not external", &GV);
808 "GlobalValue with local linkage or non-default "
809 "visibility must be dso_local!",
814 if (!
I->getParent() || !
I->getParent()->getParent())
815 CheckFailed(
"Global is referenced by parentless instruction!", &GV, &M,
817 else if (
I->getParent()->getParent()->getParent() != &M)
818 CheckFailed(
"Global is referenced in a different module!", &GV, &M,
I,
819 I->getParent()->getParent(),
820 I->getParent()->getParent()->getParent());
822 }
else if (
const Function *
F = dyn_cast<Function>(V)) {
823 if (
F->getParent() != &M)
824 CheckFailed(
"Global is used by function in a different module", &GV, &M,
835 "Global variable initializer type does not match global "
842 "'common' global must have a zero initializer!", &GV);
845 Check(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
850 GV.
getName() ==
"llvm.global_dtors")) {
852 "invalid linkage for intrinsic global variable", &GV);
854 "invalid uses of intrinsic global variable", &GV);
859 StructType *STy = dyn_cast<StructType>(ATy->getElementType());
865 "wrong type for intrinsic global variable", &GV);
867 "the third field of the element type is mandatory, "
868 "specify ptr null to migrate from the obsoleted 2-field form");
876 GV.
getName() ==
"llvm.compiler.used")) {
878 "invalid linkage for intrinsic global variable", &GV);
880 "invalid uses of intrinsic global variable", &GV);
883 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
884 PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
885 Check(PTy,
"wrong type for intrinsic global variable", &GV);
889 Check(InitArray,
"wrong initalizer for intrinsic global variable",
893 Check(isa<GlobalVariable>(V) || isa<Function>(V) ||
897 Twine(
"members of ") + GV.
getName() +
" must be named", V);
906 for (
auto *MD : MDs) {
907 if (
auto *GVE = dyn_cast<DIGlobalVariableExpression>(MD))
908 visitDIGlobalVariableExpression(*GVE);
910 CheckDI(
false,
"!dbg attachment of global variable must be a "
911 "DIGlobalVariableExpression");
917 "Globals cannot contain scalable types", &GV);
921 if (
auto *TTy = dyn_cast<TargetExtType>(GV.
getValueType()))
923 "Global @" + GV.
getName() +
" has illegal target extension type",
927 visitGlobalValue(GV);
934 visitGlobalValue(GV);
940 visitAliaseeSubExpr(Visited, GA,
C);
946 Check(isa<GlobalValue>(
C) &&
947 cast<GlobalValue>(
C).hasAvailableExternallyLinkage(),
948 "available_externally alias must point to available_externally "
952 if (
const auto *GV = dyn_cast<GlobalValue>(&
C)) {
958 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
959 Check(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
961 Check(!GA2->isInterposable(),
962 "Alias cannot point to an interposable alias", &GA);
970 if (
const auto *CE = dyn_cast<ConstantExpr>(&
C))
971 visitConstantExprsRecursively(CE);
973 for (
const Use &U :
C.operands()) {
975 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
976 visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee());
977 else if (
const auto *C2 = dyn_cast<Constant>(V))
978 visitAliaseeSubExpr(Visited, GA, *C2);
982void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
984 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
985 "weak_odr, external, or available_externally linkage!",
988 Check(Aliasee,
"Aliasee cannot be NULL!", &GA);
990 "Alias and aliasee types should match!", &GA);
992 Check(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
993 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
995 visitAliaseeSubExpr(GA, *Aliasee);
997 visitGlobalValue(GA);
1000void Verifier::visitGlobalIFunc(
const GlobalIFunc &GI) {
1002 "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
1003 "weak_odr, or external linkage!",
1008 Check(
Resolver,
"IFunc must have a Function resolver", &GI);
1010 "IFunc resolver must be a definition", &GI);
1016 Check(isa<PointerType>(
Resolver->getFunctionType()->getReturnType()),
1017 "IFunc resolver must return a pointer", &GI);
1019 const Type *ResolverFuncTy =
1022 "IFunc resolver has incorrect type", &GI);
1025void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
1030 "unrecognized named metadata node in the llvm.dbg namespace", &NMD);
1032 if (NMD.
getName() ==
"llvm.dbg.cu")
1033 CheckDI(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
1038 visitMDNode(*MD, AreDebugLocsAllowed::Yes);
1042void Verifier::visitMDNode(
const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
1045 if (!MDNodes.
insert(&MD).second)
1049 "MDNode context does not match Module context!", &MD);
1054 case Metadata::MDTupleKind:
1056#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
1057 case Metadata::CLASS##Kind: \
1058 visit##CLASS(cast<CLASS>(MD)); \
1060#include "llvm/IR/Metadata.def"
1066 Check(!isa<LocalAsMetadata>(
Op),
"Invalid operand for global metadata!",
1068 CheckDI(!isa<DILocation>(
Op) || AllowLocs == AreDebugLocsAllowed::Yes,
1069 "DILocation not allowed within this metadata node", &MD,
Op);
1070 if (
auto *
N = dyn_cast<MDNode>(
Op)) {
1071 visitMDNode(*
N, AllowLocs);
1074 if (
auto *V = dyn_cast<ValueAsMetadata>(
Op)) {
1075 visitValueAsMetadata(*V,
nullptr);
1088 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
1090 auto *
L = dyn_cast<LocalAsMetadata>(&MD);
1094 Check(
F,
"function-local metadata used outside a function", L);
1099 if (
Instruction *
I = dyn_cast<Instruction>(
L->getValue())) {
1100 Check(
I->getParent(),
"function-local metadata not in basic block", L,
I);
1101 ActualF =
I->getParent()->getParent();
1102 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(
L->getValue()))
1104 else if (
Argument *
A = dyn_cast<Argument>(
L->getValue()))
1105 ActualF =
A->getParent();
1106 assert(ActualF &&
"Unimplemented function local metadata case!");
1108 Check(ActualF ==
F,
"function-local metadata used in wrong function", L);
1113 visitValueAsMetadata(*VAM,
F);
1118 if (
auto *
N = dyn_cast<MDNode>(MD)) {
1119 visitMDNode(*
N, AreDebugLocsAllowed::No);
1125 if (!MDNodes.
insert(MD).second)
1128 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
1129 visitValueAsMetadata(*V,
F);
1131 if (
auto *AL = dyn_cast<DIArgList>(MD))
1132 visitDIArgList(*AL,
F);
1139void Verifier::visitDILocation(
const DILocation &
N) {
1140 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1141 "location requires a valid scope", &
N,
N.getRawScope());
1142 if (
auto *IA =
N.getRawInlinedAt())
1143 CheckDI(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
1144 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1145 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1152void Verifier::visitDIScope(
const DIScope &
N) {
1153 if (
auto *
F =
N.getRawFile())
1154 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1157void Verifier::visitDISubrange(
const DISubrange &
N) {
1158 CheckDI(
N.getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
1160 CheckDI(HasAssumedSizedArraySupport ||
N.getRawCountNode() ||
1161 N.getRawUpperBound(),
1162 "Subrange must contain count or upperBound", &
N);
1163 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1164 "Subrange can have any one of count or upperBound", &
N);
1165 auto *CBound =
N.getRawCountNode();
1166 CheckDI(!CBound || isa<ConstantAsMetadata>(CBound) ||
1167 isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1168 "Count must be signed constant or DIVariable or DIExpression", &
N);
1169 auto Count =
N.getCount();
1170 CheckDI(!Count || !isa<ConstantInt *>(Count) ||
1171 cast<ConstantInt *>(Count)->getSExtValue() >= -1,
1172 "invalid subrange count", &
N);
1173 auto *LBound =
N.getRawLowerBound();
1174 CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||
1175 isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1176 "LowerBound must be signed constant or DIVariable or DIExpression",
1178 auto *UBound =
N.getRawUpperBound();
1179 CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) ||
1180 isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1181 "UpperBound must be signed constant or DIVariable or DIExpression",
1183 auto *Stride =
N.getRawStride();
1184 CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) ||
1185 isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1186 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1190 CheckDI(
N.getTag() == dwarf::DW_TAG_generic_subrange,
"invalid tag", &
N);
1191 CheckDI(
N.getRawCountNode() ||
N.getRawUpperBound(),
1192 "GenericSubrange must contain count or upperBound", &
N);
1193 CheckDI(!
N.getRawCountNode() || !
N.getRawUpperBound(),
1194 "GenericSubrange can have any one of count or upperBound", &
N);
1195 auto *CBound =
N.getRawCountNode();
1196 CheckDI(!CBound || isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
1197 "Count must be signed constant or DIVariable or DIExpression", &
N);
1198 auto *LBound =
N.getRawLowerBound();
1199 CheckDI(LBound,
"GenericSubrange must contain lowerBound", &
N);
1200 CheckDI(isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
1201 "LowerBound must be signed constant or DIVariable or DIExpression",
1203 auto *UBound =
N.getRawUpperBound();
1204 CheckDI(!UBound || isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
1205 "UpperBound must be signed constant or DIVariable or DIExpression",
1207 auto *Stride =
N.getRawStride();
1208 CheckDI(Stride,
"GenericSubrange must contain stride", &
N);
1209 CheckDI(isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
1210 "Stride must be signed constant or DIVariable or DIExpression", &
N);
1214 CheckDI(
N.getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
1218 CheckDI(
N.getTag() == dwarf::DW_TAG_base_type ||
1219 N.getTag() == dwarf::DW_TAG_unspecified_type ||
1220 N.getTag() == dwarf::DW_TAG_string_type,
1225 CheckDI(
N.getTag() == dwarf::DW_TAG_string_type,
"invalid tag", &
N);
1226 CheckDI(!(
N.isBigEndian() &&
N.isLittleEndian()),
"has conflicting flags",
1234 CheckDI(
N.getTag() == dwarf::DW_TAG_typedef ||
1235 N.getTag() == dwarf::DW_TAG_pointer_type ||
1236 N.getTag() == dwarf::DW_TAG_ptr_to_member_type ||
1237 N.getTag() == dwarf::DW_TAG_reference_type ||
1238 N.getTag() == dwarf::DW_TAG_rvalue_reference_type ||
1239 N.getTag() == dwarf::DW_TAG_const_type ||
1240 N.getTag() == dwarf::DW_TAG_immutable_type ||
1241 N.getTag() == dwarf::DW_TAG_volatile_type ||
1242 N.getTag() == dwarf::DW_TAG_restrict_type ||
1243 N.getTag() == dwarf::DW_TAG_atomic_type ||
1244 N.getTag() == dwarf::DW_TAG_LLVM_ptrauth_type ||
1245 N.getTag() == dwarf::DW_TAG_member ||
1246 (
N.getTag() == dwarf::DW_TAG_variable &&
N.isStaticMember()) ||
1247 N.getTag() == dwarf::DW_TAG_inheritance ||
1248 N.getTag() == dwarf::DW_TAG_friend ||
1249 N.getTag() == dwarf::DW_TAG_set_type ||
1250 N.getTag() == dwarf::DW_TAG_template_alias,
1252 if (
N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
1253 CheckDI(
isType(
N.getRawExtraData()),
"invalid pointer to member type", &
N,
1254 N.getRawExtraData());
1257 if (
N.getTag() == dwarf::DW_TAG_set_type) {
1258 if (
auto *
T =
N.getRawBaseType()) {
1259 auto *
Enum = dyn_cast_or_null<DICompositeType>(
T);
1260 auto *
Basic = dyn_cast_or_null<DIBasicType>(
T);
1262 (Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type) ||
1263 (
Basic && (
Basic->getEncoding() == dwarf::DW_ATE_unsigned ||
1264 Basic->getEncoding() == dwarf::DW_ATE_signed ||
1265 Basic->getEncoding() == dwarf::DW_ATE_unsigned_char ||
1266 Basic->getEncoding() == dwarf::DW_ATE_signed_char ||
1267 Basic->getEncoding() == dwarf::DW_ATE_boolean)),
1268 "invalid set base type", &
N,
T);
1274 N.getRawBaseType());
1276 if (
N.getDWARFAddressSpace()) {
1277 CheckDI(
N.getTag() == dwarf::DW_TAG_pointer_type ||
1278 N.getTag() == dwarf::DW_TAG_reference_type ||
1279 N.getTag() == dwarf::DW_TAG_rvalue_reference_type,
1280 "DWARF address space only applies to pointer or reference types",
1287 return ((Flags & DINode::FlagLValueReference) &&
1288 (Flags & DINode::FlagRValueReference)) ||
1289 ((Flags & DINode::FlagTypePassByValue) &&
1290 (Flags & DINode::FlagTypePassByReference));
1293void Verifier::visitTemplateParams(
const MDNode &
N,
const Metadata &RawParams) {
1294 auto *Params = dyn_cast<MDTuple>(&RawParams);
1295 CheckDI(Params,
"invalid template params", &
N, &RawParams);
1297 CheckDI(
Op && isa<DITemplateParameter>(
Op),
"invalid template parameter",
1306 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type ||
1307 N.getTag() == dwarf::DW_TAG_structure_type ||
1308 N.getTag() == dwarf::DW_TAG_union_type ||
1309 N.getTag() == dwarf::DW_TAG_enumeration_type ||
1310 N.getTag() == dwarf::DW_TAG_class_type ||
1311 N.getTag() == dwarf::DW_TAG_variant_part ||
1312 N.getTag() == dwarf::DW_TAG_namelist,
1317 N.getRawBaseType());
1319 CheckDI(!
N.getRawElements() || isa<MDTuple>(
N.getRawElements()),
1320 "invalid composite elements", &
N,
N.getRawElements());
1322 N.getRawVTableHolder());
1324 "invalid reference flags", &
N);
1325 unsigned DIBlockByRefStruct = 1 << 4;
1326 CheckDI((
N.getFlags() & DIBlockByRefStruct) == 0,
1327 "DIBlockByRefStruct on DICompositeType is no longer supported", &
N);
1330 const DINodeArray
Elements =
N.getElements();
1332 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type,
1333 "invalid vector, expected one element of type subrange", &
N);
1336 if (
auto *Params =
N.getRawTemplateParams())
1337 visitTemplateParams(
N, *Params);
1339 if (
auto *
D =
N.getRawDiscriminator()) {
1340 CheckDI(isa<DIDerivedType>(
D) &&
N.getTag() == dwarf::DW_TAG_variant_part,
1341 "discriminator can only appear on variant part");
1344 if (
N.getRawDataLocation()) {
1345 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1346 "dataLocation can only appear in array type");
1349 if (
N.getRawAssociated()) {
1350 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1351 "associated can only appear in array type");
1354 if (
N.getRawAllocated()) {
1355 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1356 "allocated can only appear in array type");
1359 if (
N.getRawRank()) {
1360 CheckDI(
N.getTag() == dwarf::DW_TAG_array_type,
1361 "rank can only appear in array type");
1364 if (
N.getTag() == dwarf::DW_TAG_array_type) {
1365 CheckDI(
N.getRawBaseType(),
"array types must have a base type", &
N);
1370 CheckDI(
N.getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
1371 if (
auto *Types =
N.getRawTypeArray()) {
1372 CheckDI(isa<MDTuple>(Types),
"invalid composite elements", &
N, Types);
1373 for (
Metadata *Ty :
N.getTypeArray()->operands()) {
1374 CheckDI(
isType(Ty),
"invalid subroutine type ref", &
N, Types, Ty);
1378 "invalid reference flags", &
N);
1381void Verifier::visitDIFile(
const DIFile &
N) {
1382 CheckDI(
N.getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
1383 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum =
N.getChecksum();
1386 "invalid checksum kind", &
N);
1388 switch (Checksum->Kind) {
1399 CheckDI(Checksum->Value.size() ==
Size,
"invalid checksum length", &
N);
1401 "invalid checksum", &
N);
1406 CheckDI(
N.isDistinct(),
"compile units must be distinct", &
N);
1407 CheckDI(
N.getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
1411 CheckDI(
N.getRawFile() && isa<DIFile>(
N.getRawFile()),
"invalid file", &
N,
1413 CheckDI(!
N.getFile()->getFilename().empty(),
"invalid filename", &
N,
1419 "invalid emission kind", &
N);
1421 if (
auto *Array =
N.getRawEnumTypes()) {
1422 CheckDI(isa<MDTuple>(Array),
"invalid enum list", &
N, Array);
1423 for (
Metadata *
Op :
N.getEnumTypes()->operands()) {
1424 auto *
Enum = dyn_cast_or_null<DICompositeType>(
Op);
1425 CheckDI(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
1426 "invalid enum type", &
N,
N.getEnumTypes(),
Op);
1429 if (
auto *Array =
N.getRawRetainedTypes()) {
1430 CheckDI(isa<MDTuple>(Array),
"invalid retained type list", &
N, Array);
1431 for (
Metadata *
Op :
N.getRetainedTypes()->operands()) {
1433 Op && (isa<DIType>(
Op) || (isa<DISubprogram>(
Op) &&
1434 !cast<DISubprogram>(
Op)->isDefinition())),
1435 "invalid retained type", &
N,
Op);
1438 if (
auto *Array =
N.getRawGlobalVariables()) {
1439 CheckDI(isa<MDTuple>(Array),
"invalid global variable list", &
N, Array);
1440 for (
Metadata *
Op :
N.getGlobalVariables()->operands()) {
1441 CheckDI(
Op && (isa<DIGlobalVariableExpression>(
Op)),
1442 "invalid global variable ref", &
N,
Op);
1445 if (
auto *Array =
N.getRawImportedEntities()) {
1446 CheckDI(isa<MDTuple>(Array),
"invalid imported entity list", &
N, Array);
1447 for (
Metadata *
Op :
N.getImportedEntities()->operands()) {
1448 CheckDI(
Op && isa<DIImportedEntity>(
Op),
"invalid imported entity ref",
1452 if (
auto *Array =
N.getRawMacros()) {
1453 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1455 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1462 CheckDI(
N.getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
1464 if (
auto *
F =
N.getRawFile())
1465 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1467 CheckDI(
N.getLine() == 0,
"line specified with no file", &
N,
N.getLine());
1468 if (
auto *
T =
N.getRawType())
1469 CheckDI(isa<DISubroutineType>(
T),
"invalid subroutine type", &
N,
T);
1470 CheckDI(
isType(
N.getRawContainingType()),
"invalid containing type", &
N,
1471 N.getRawContainingType());
1472 if (
auto *Params =
N.getRawTemplateParams())
1473 visitTemplateParams(
N, *Params);
1474 if (
auto *S =
N.getRawDeclaration())
1475 CheckDI(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
1476 "invalid subprogram declaration", &
N, S);
1477 if (
auto *RawNode =
N.getRawRetainedNodes()) {
1478 auto *
Node = dyn_cast<MDTuple>(RawNode);
1479 CheckDI(
Node,
"invalid retained nodes list", &
N, RawNode);
1481 CheckDI(
Op && (isa<DILocalVariable>(
Op) || isa<DILabel>(
Op) ||
1482 isa<DIImportedEntity>(
Op)),
1483 "invalid retained nodes, expected DILocalVariable, DILabel or "
1489 "invalid reference flags", &
N);
1491 auto *Unit =
N.getRawUnit();
1492 if (
N.isDefinition()) {
1494 CheckDI(
N.isDistinct(),
"subprogram definitions must be distinct", &
N);
1495 CheckDI(Unit,
"subprogram definitions must have a compile unit", &
N);
1496 CheckDI(isa<DICompileUnit>(Unit),
"invalid unit type", &
N, Unit);
1499 auto *CT = dyn_cast_or_null<DICompositeType>(
N.getRawScope());
1500 if (CT && CT->getRawIdentifier() &&
1501 M.getContext().isODRUniquingDebugTypes())
1503 "definition subprograms cannot be nested within DICompositeType "
1504 "when enabling ODR",
1508 CheckDI(!Unit,
"subprogram declarations must not have a compile unit", &
N);
1510 "subprogram declaration must not have a declaration field");
1513 if (
auto *RawThrownTypes =
N.getRawThrownTypes()) {
1514 auto *ThrownTypes = dyn_cast<MDTuple>(RawThrownTypes);
1515 CheckDI(ThrownTypes,
"invalid thrown types list", &
N, RawThrownTypes);
1517 CheckDI(
Op && isa<DIType>(
Op),
"invalid thrown type", &
N, ThrownTypes,
1521 if (
N.areAllCallsDescribed())
1523 "DIFlagAllCallsDescribed must be attached to a definition");
1527 CheckDI(
N.getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1528 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1529 "invalid local scope", &
N,
N.getRawScope());
1530 if (
auto *SP = dyn_cast<DISubprogram>(
N.getRawScope()))
1531 CheckDI(SP->isDefinition(),
"scope points into the type hierarchy", &
N);
1535 visitDILexicalBlockBase(
N);
1538 "cannot have column info without line info", &
N);
1542 visitDILexicalBlockBase(
N);
1546 CheckDI(
N.getTag() == dwarf::DW_TAG_common_block,
"invalid tag", &
N);
1547 if (
auto *S =
N.getRawScope())
1548 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1549 if (
auto *S =
N.getRawDecl())
1550 CheckDI(isa<DIGlobalVariable>(S),
"invalid declaration", &
N, S);
1554 CheckDI(
N.getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1555 if (
auto *S =
N.getRawScope())
1556 CheckDI(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1559void Verifier::visitDIMacro(
const DIMacro &
N) {
1562 "invalid macinfo type", &
N);
1563 CheckDI(!
N.getName().empty(),
"anonymous macro", &
N);
1564 if (!
N.getValue().empty()) {
1565 assert(
N.getValue().data()[0] !=
' ' &&
"Macro value has a space prefix");
1571 "invalid macinfo type", &
N);
1572 if (
auto *
F =
N.getRawFile())
1573 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1575 if (
auto *Array =
N.getRawElements()) {
1576 CheckDI(isa<MDTuple>(Array),
"invalid macro list", &
N, Array);
1577 for (
Metadata *
Op :
N.getElements()->operands()) {
1578 CheckDI(
Op && isa<DIMacroNode>(
Op),
"invalid macro ref", &
N,
Op);
1583void Verifier::visitDIModule(
const DIModule &
N) {
1584 CheckDI(
N.getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1585 CheckDI(!
N.getName().empty(),
"anonymous module", &
N);
1593 visitDITemplateParameter(
N);
1595 CheckDI(
N.getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1599void Verifier::visitDITemplateValueParameter(
1601 visitDITemplateParameter(
N);
1603 CheckDI(
N.getTag() == dwarf::DW_TAG_template_value_parameter ||
1604 N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1605 N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1609void Verifier::visitDIVariable(
const DIVariable &
N) {
1610 if (
auto *S =
N.getRawScope())
1611 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1612 if (
auto *
F =
N.getRawFile())
1613 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1620 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1623 if (
N.isDefinition())
1624 CheckDI(
N.getType(),
"missing global variable type", &
N);
1625 if (
auto *Member =
N.getRawStaticDataMemberDeclaration()) {
1626 CheckDI(isa<DIDerivedType>(Member),
1627 "invalid static data member declaration", &
N, Member);
1636 CheckDI(
N.getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1637 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1638 "local variable requires a valid scope", &
N,
N.getRawScope());
1639 if (
auto Ty =
N.getType())
1640 CheckDI(!isa<DISubroutineType>(Ty),
"invalid type", &
N,
N.getType());
1643void Verifier::visitDIAssignID(
const DIAssignID &
N) {
1644 CheckDI(!
N.getNumOperands(),
"DIAssignID has no arguments", &
N);
1645 CheckDI(
N.isDistinct(),
"DIAssignID must be distinct", &
N);
1648void Verifier::visitDILabel(
const DILabel &
N) {
1649 if (
auto *S =
N.getRawScope())
1650 CheckDI(isa<DIScope>(S),
"invalid scope", &
N, S);
1651 if (
auto *
F =
N.getRawFile())
1652 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1654 CheckDI(
N.getTag() == dwarf::DW_TAG_label,
"invalid tag", &
N);
1655 CheckDI(
N.getRawScope() && isa<DILocalScope>(
N.getRawScope()),
1656 "label requires a valid scope", &
N,
N.getRawScope());
1660 CheckDI(
N.isValid(),
"invalid expression", &
N);
1663void Verifier::visitDIGlobalVariableExpression(
1667 visitDIGlobalVariable(*Var);
1669 visitDIExpression(*Expr);
1670 if (
auto Fragment = Expr->getFragmentInfo())
1671 verifyFragmentExpression(*GVE.
getVariable(), *Fragment, &GVE);
1676 CheckDI(
N.getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1677 if (
auto *
T =
N.getRawType())
1679 if (
auto *
F =
N.getRawFile())
1680 CheckDI(isa<DIFile>(
F),
"invalid file", &
N,
F);
1684 CheckDI(
N.getTag() == dwarf::DW_TAG_imported_module ||
1685 N.getTag() == dwarf::DW_TAG_imported_declaration,
1687 if (
auto *S =
N.getRawScope())
1688 CheckDI(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1693void Verifier::visitComdat(
const Comdat &
C) {
1696 if (
TT.isOSBinFormatCOFF())
1702void Verifier::visitModuleIdents() {
1703 const NamedMDNode *Idents =
M.getNamedMetadata(
"llvm.ident");
1710 Check(
N->getNumOperands() == 1,
1711 "incorrect number of operands in llvm.ident metadata",
N);
1712 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1713 (
"invalid value for llvm.ident metadata entry operand"
1714 "(the operand should be a string)"),
1719void Verifier::visitModuleCommandLines() {
1720 const NamedMDNode *CommandLines =
M.getNamedMetadata(
"llvm.commandline");
1728 Check(
N->getNumOperands() == 1,
1729 "incorrect number of operands in llvm.commandline metadata",
N);
1730 Check(dyn_cast_or_null<MDString>(
N->getOperand(0)),
1731 (
"invalid value for llvm.commandline metadata entry operand"
1732 "(the operand should be a string)"),
1737void Verifier::visitModuleFlags() {
1747 visitModuleFlag(MDN, SeenIDs, Requirements);
1748 if (MDN->getNumOperands() != 3)
1750 if (
const auto *FlagName = dyn_cast_or_null<MDString>(MDN->getOperand(1))) {
1751 if (FlagName->getString() ==
"aarch64-elf-pauthabi-platform") {
1752 if (
const auto *PAP =
1753 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1754 PAuthABIPlatform = PAP->getZExtValue();
1755 }
else if (FlagName->getString() ==
"aarch64-elf-pauthabi-version") {
1756 if (
const auto *PAV =
1757 mdconst::dyn_extract_or_null<ConstantInt>(MDN->getOperand(2)))
1758 PAuthABIVersion = PAV->getZExtValue();
1763 if ((PAuthABIPlatform ==
uint64_t(-1)) != (PAuthABIVersion ==
uint64_t(-1)))
1764 CheckFailed(
"either both or no 'aarch64-elf-pauthabi-platform' and "
1765 "'aarch64-elf-pauthabi-version' module flags must be present");
1768 for (
const MDNode *Requirement : Requirements) {
1769 const MDString *
Flag = cast<MDString>(Requirement->getOperand(0));
1770 const Metadata *ReqValue = Requirement->getOperand(1);
1774 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1779 if (
Op->getOperand(2) != ReqValue) {
1780 CheckFailed((
"invalid requirement on flag, "
1781 "flag does not have the required value"),
1789Verifier::visitModuleFlag(
const MDNode *
Op,
1795 "incorrect number of operands in module flag",
Op);
1798 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)),
1799 "invalid behavior operand in module flag (expected constant integer)",
1802 "invalid behavior operand in module flag (unexpected constant)",
1805 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
1806 Check(
ID,
"invalid ID operand in module flag (expected metadata string)",
1818 auto *
V = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1819 Check(V &&
V->getValue().isNonNegative(),
1820 "invalid value for 'min' module flag (expected constant non-negative "
1827 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2)),
1828 "invalid value for 'max' module flag (expected constant integer)",
1838 "invalid value for 'require' module flag (expected metadata pair)",
1841 (
"invalid value for 'require' module flag "
1842 "(first value operand should be a string)"),
1843 Value->getOperand(0));
1854 Check(isa<MDNode>(
Op->getOperand(2)),
1855 "invalid value for 'append'-type module flag "
1856 "(expected a metadata node)",
1866 "module flag identifiers must be unique (or of 'require' type)",
ID);
1869 if (
ID->getString() ==
"wchar_size") {
1871 = mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1872 Check(
Value,
"wchar_size metadata requires constant integer argument");
1875 if (
ID->getString() ==
"Linker Options") {
1879 Check(
M.getNamedMetadata(
"llvm.linker.options"),
1880 "'Linker Options' named metadata no longer supported");
1883 if (
ID->getString() ==
"SemanticInterposition") {
1885 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(2));
1887 "SemanticInterposition metadata requires constant integer argument");
1890 if (
ID->getString() ==
"CG Profile") {
1891 for (
const MDOperand &MDO : cast<MDNode>(
Op->getOperand(2))->operands())
1892 visitModuleFlagCGProfileEntry(MDO);
1896void Verifier::visitModuleFlagCGProfileEntry(
const MDOperand &MDO) {
1897 auto CheckFunction = [&](
const MDOperand &FuncMDO) {
1900 auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
1901 Check(
F && isa<Function>(
F->getValue()->stripPointerCasts()),
1902 "expected a Function or null", FuncMDO);
1904 auto Node = dyn_cast_or_null<MDNode>(MDO);
1905 Check(
Node &&
Node->getNumOperands() == 3,
"expected a MDNode triple", MDO);
1906 CheckFunction(
Node->getOperand(0));
1907 CheckFunction(
Node->getOperand(1));
1908 auto Count = dyn_cast_or_null<ConstantAsMetadata>(
Node->getOperand(2));
1909 Check(Count && Count->getType()->isIntegerTy(),
1910 "expected an integer constant",
Node->getOperand(2));
1916 if (
A.isStringAttribute()) {
1917#define GET_ATTR_NAMES
1918#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME)
1919#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
1920 if (A.getKindAsString() == #DISPLAY_NAME) { \
1921 auto V = A.getValueAsString(); \
1922 if (!(V.empty() || V == "true" || V == "false")) \
1923 CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \
1927#include "llvm/IR/Attributes.inc"
1932 CheckFailed(
"Attribute '" +
A.getAsString() +
"' should have an Argument",
1943 if (!
Attrs.hasAttributes())
1946 verifyAttributeTypes(Attrs, V);
1949 Check(Attr.isStringAttribute() ||
1951 "Attribute '" + Attr.getAsString() +
"' does not apply to parameters",
1954 if (
Attrs.hasAttribute(Attribute::ImmArg)) {
1956 "Attribute 'immarg' is incompatible with other attributes", V);
1961 unsigned AttrCount = 0;
1962 AttrCount +=
Attrs.hasAttribute(Attribute::ByVal);
1963 AttrCount +=
Attrs.hasAttribute(Attribute::InAlloca);
1964 AttrCount +=
Attrs.hasAttribute(Attribute::Preallocated);
1965 AttrCount +=
Attrs.hasAttribute(Attribute::StructRet) ||
1966 Attrs.hasAttribute(Attribute::InReg);
1967 AttrCount +=
Attrs.hasAttribute(Attribute::Nest);
1968 AttrCount +=
Attrs.hasAttribute(Attribute::ByRef);
1969 Check(AttrCount <= 1,
1970 "Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', "
1971 "'byref', and 'sret' are incompatible!",
1974 Check(!(
Attrs.hasAttribute(Attribute::InAlloca) &&
1975 Attrs.hasAttribute(Attribute::ReadOnly)),
1977 "'inalloca and readonly' are incompatible!",
1980 Check(!(
Attrs.hasAttribute(Attribute::StructRet) &&
1981 Attrs.hasAttribute(Attribute::Returned)),
1983 "'sret and returned' are incompatible!",
1986 Check(!(
Attrs.hasAttribute(Attribute::ZExt) &&
1987 Attrs.hasAttribute(Attribute::SExt)),
1989 "'zeroext and signext' are incompatible!",
1992 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1993 Attrs.hasAttribute(Attribute::ReadOnly)),
1995 "'readnone and readonly' are incompatible!",
1998 Check(!(
Attrs.hasAttribute(Attribute::ReadNone) &&
1999 Attrs.hasAttribute(Attribute::WriteOnly)),
2001 "'readnone and writeonly' are incompatible!",
2004 Check(!(
Attrs.hasAttribute(Attribute::ReadOnly) &&
2005 Attrs.hasAttribute(Attribute::WriteOnly)),
2007 "'readonly and writeonly' are incompatible!",
2010 Check(!(
Attrs.hasAttribute(Attribute::NoInline) &&
2011 Attrs.hasAttribute(Attribute::AlwaysInline)),
2013 "'noinline and alwaysinline' are incompatible!",
2016 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2017 Attrs.hasAttribute(Attribute::ReadNone)),
2018 "Attributes writable and readnone are incompatible!", V);
2020 Check(!(
Attrs.hasAttribute(Attribute::Writable) &&
2021 Attrs.hasAttribute(Attribute::ReadOnly)),
2022 "Attributes writable and readonly are incompatible!", V);
2026 if (!Attr.isStringAttribute() &&
2027 IncompatibleAttrs.
contains(Attr.getKindAsEnum())) {
2028 CheckFailed(
"Attribute '" + Attr.getAsString() +
2029 "' applied to incompatible type!", V);
2034 if (isa<PointerType>(Ty)) {
2035 if (
Attrs.hasAttribute(Attribute::ByVal)) {
2036 if (
Attrs.hasAttribute(Attribute::Alignment)) {
2037 Align AttrAlign =
Attrs.getAlignment().valueOrOne();
2038 Align MaxAlign(ParamMaxAlignment);
2039 Check(AttrAlign <= MaxAlign,
2040 "Attribute 'align' exceed the max size 2^14", V);
2043 Check(
Attrs.getByValType()->isSized(&Visited),
2044 "Attribute 'byval' does not support unsized types!", V);
2046 if (
Attrs.hasAttribute(Attribute::ByRef)) {
2048 Check(
Attrs.getByRefType()->isSized(&Visited),
2049 "Attribute 'byref' does not support unsized types!", V);
2051 if (
Attrs.hasAttribute(Attribute::InAlloca)) {
2053 Check(
Attrs.getInAllocaType()->isSized(&Visited),
2054 "Attribute 'inalloca' does not support unsized types!", V);
2056 if (
Attrs.hasAttribute(Attribute::Preallocated)) {
2058 Check(
Attrs.getPreallocatedType()->isSized(&Visited),
2059 "Attribute 'preallocated' does not support unsized types!", V);
2063 if (
Attrs.hasAttribute(Attribute::Initializes)) {
2064 auto Inits =
Attrs.getAttribute(Attribute::Initializes).getInitializes();
2065 Check(!Inits.empty(),
"Attribute 'initializes' does not support empty list",
2068 "Attribute 'initializes' does not support unordered ranges", V);
2071 if (
Attrs.hasAttribute(Attribute::NoFPClass)) {
2072 uint64_t Val =
Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt();
2073 Check(Val != 0,
"Attribute 'nofpclass' must have at least one test bit set",
2076 "Invalid value for 'nofpclass' test mask", V);
2078 if (
Attrs.hasAttribute(Attribute::Range)) {
2080 Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2082 "Range bit width must match type bit width!", V);
2088 if (
Attrs.hasFnAttr(Attr)) {
2092 CheckFailed(
"\"" + Attr +
"\" takes an unsigned integer: " + S, V);
2099 const Value *V,
bool IsIntrinsic,
2101 if (
Attrs.isEmpty())
2104 if (AttributeListsVisited.
insert(
Attrs.getRawPointer()).second) {
2106 "Attribute list does not match Module context!", &Attrs, V);
2107 for (
const auto &AttrSet : Attrs) {
2108 Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context),
2109 "Attribute set does not match Module context!", &AttrSet, V);
2110 for (
const auto &
A : AttrSet) {
2111 Check(
A.hasParentContext(Context),
2112 "Attribute does not match Module context!", &
A, V);
2117 bool SawNest =
false;
2118 bool SawReturned =
false;
2119 bool SawSRet =
false;
2120 bool SawSwiftSelf =
false;
2121 bool SawSwiftAsync =
false;
2122 bool SawSwiftError =
false;
2129 "Attribute '" +
RetAttr.getAsString() +
2130 "' does not apply to function return values",
2133 unsigned MaxParameterWidth = 0;
2134 auto GetMaxParameterWidth = [&MaxParameterWidth](
Type *Ty) {
2136 if (
auto *VT = dyn_cast<FixedVectorType>(Ty)) {
2137 unsigned Size = VT->getPrimitiveSizeInBits().getFixedValue();
2138 if (
Size > MaxParameterWidth)
2139 MaxParameterWidth =
Size;
2143 GetMaxParameterWidth(FT->getReturnType());
2144 verifyParameterAttrs(RetAttrs, FT->getReturnType(), V);
2147 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2148 Type *Ty = FT->getParamType(i);
2153 "immarg attribute only applies to intrinsics", V);
2156 "Attribute 'elementtype' can only be applied to intrinsics"
2161 verifyParameterAttrs(ArgAttrs, Ty, V);
2162 GetMaxParameterWidth(Ty);
2165 Check(!SawNest,
"More than one parameter has attribute nest!", V);
2170 Check(!SawReturned,
"More than one parameter has attribute returned!", V);
2172 "Incompatible argument and return types for 'returned' attribute",
2178 Check(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
2179 Check(i == 0 || i == 1,
2180 "Attribute 'sret' is not on first or second parameter!", V);
2185 Check(!SawSwiftSelf,
"Cannot have multiple 'swiftself' parameters!", V);
2186 SawSwiftSelf =
true;
2190 Check(!SawSwiftAsync,
"Cannot have multiple 'swiftasync' parameters!", V);
2191 SawSwiftAsync =
true;
2195 Check(!SawSwiftError,
"Cannot have multiple 'swifterror' parameters!", V);
2196 SawSwiftError =
true;
2200 Check(i == FT->getNumParams() - 1,
2201 "inalloca isn't on the last parameter!", V);
2205 if (!
Attrs.hasFnAttrs())
2208 verifyAttributeTypes(
Attrs.getFnAttrs(), V);
2212 "Attribute '" +
FnAttr.getAsString() +
2213 "' does not apply to functions!",
2216 Check(!(
Attrs.hasFnAttr(Attribute::NoInline) &&
2217 Attrs.hasFnAttr(Attribute::AlwaysInline)),
2218 "Attributes 'noinline and alwaysinline' are incompatible!", V);
2220 if (
Attrs.hasFnAttr(Attribute::OptimizeNone)) {
2222 "Attribute 'optnone' requires 'noinline'!", V);
2224 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2225 "Attributes 'optsize and optnone' are incompatible!", V);
2228 "Attributes 'minsize and optnone' are incompatible!", V);
2230 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForDebugging),
2231 "Attributes 'optdebug and optnone' are incompatible!", V);
2234 if (
Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {
2235 Check(!
Attrs.hasFnAttr(Attribute::OptimizeForSize),
2236 "Attributes 'optsize and optdebug' are incompatible!", V);
2239 "Attributes 'minsize and optdebug' are incompatible!", V);
2242 Check(!
Attrs.hasAttrSomewhere(Attribute::Writable) ||
2244 "Attribute writable and memory without argmem: write are incompatible!",
2247 if (
Attrs.hasFnAttr(
"aarch64_pstate_sm_enabled")) {
2248 Check(!
Attrs.hasFnAttr(
"aarch64_pstate_sm_compatible"),
2249 "Attributes 'aarch64_pstate_sm_enabled and "
2250 "aarch64_pstate_sm_compatible' are incompatible!",
2254 Check((
Attrs.hasFnAttr(
"aarch64_new_za") +
Attrs.hasFnAttr(
"aarch64_in_za") +
2255 Attrs.hasFnAttr(
"aarch64_inout_za") +
2256 Attrs.hasFnAttr(
"aarch64_out_za") +
2257 Attrs.hasFnAttr(
"aarch64_preserves_za")) <= 1,
2258 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
2259 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive",
2263 (
Attrs.hasFnAttr(
"aarch64_new_zt0") +
Attrs.hasFnAttr(
"aarch64_in_zt0") +
2264 Attrs.hasFnAttr(
"aarch64_inout_zt0") +
2265 Attrs.hasFnAttr(
"aarch64_out_zt0") +
2266 Attrs.hasFnAttr(
"aarch64_preserves_zt0")) <= 1,
2267 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
2268 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive",
2271 if (
Attrs.hasFnAttr(Attribute::JumpTable)) {
2274 "Attribute 'jumptable' requires 'unnamed_addr'", V);
2277 if (
auto Args =
Attrs.getFnAttrs().getAllocSizeArgs()) {
2279 if (ParamNo >= FT->getNumParams()) {
2280 CheckFailed(
"'allocsize' " +
Name +
" argument is out of bounds", V);
2284 if (!FT->getParamType(ParamNo)->isIntegerTy()) {
2285 CheckFailed(
"'allocsize' " +
Name +
2286 " argument must refer to an integer parameter",
2294 if (!CheckParam(
"element size",
Args->first))
2297 if (
Args->second && !CheckParam(
"number of elements", *
Args->second))
2301 if (
Attrs.hasFnAttr(Attribute::AllocKind)) {
2309 "'allockind()' requires exactly one of alloc, realloc, and free");
2313 CheckFailed(
"'allockind(\"free\")' doesn't allow uninitialized, zeroed, "
2314 "or aligned modifiers.");
2316 if ((K & ZeroedUninit) == ZeroedUninit)
2317 CheckFailed(
"'allockind()' can't be both zeroed and uninitialized");
2320 if (
Attrs.hasFnAttr(Attribute::VScaleRange)) {
2321 unsigned VScaleMin =
Attrs.getFnAttrs().getVScaleRangeMin();
2323 CheckFailed(
"'vscale_range' minimum must be greater than 0", V);
2325 CheckFailed(
"'vscale_range' minimum must be power-of-two value", V);
2326 std::optional<unsigned> VScaleMax =
Attrs.getFnAttrs().getVScaleRangeMax();
2327 if (VScaleMax && VScaleMin > VScaleMax)
2328 CheckFailed(
"'vscale_range' minimum cannot be greater than maximum", V);
2330 CheckFailed(
"'vscale_range' maximum must be power-of-two value", V);
2333 if (
Attrs.hasFnAttr(
"frame-pointer")) {
2335 if (
FP !=
"all" &&
FP !=
"non-leaf" &&
FP !=
"none" &&
FP !=
"reserved")
2336 CheckFailed(
"invalid value for 'frame-pointer' attribute: " +
FP, V);
2340 if (MaxParameterWidth >= 512 &&
Attrs.hasFnAttr(
"target-features") &&
2342 StringRef TF =
Attrs.getFnAttr(
"target-features").getValueAsString();
2344 "512-bit vector arguments require 'evex512' for AVX512", V);
2347 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-prefix", V);
2348 checkUnsignedBaseTenFuncAttr(Attrs,
"patchable-function-entry", V);
2349 checkUnsignedBaseTenFuncAttr(Attrs,
"warn-stack-size", V);
2351 if (
auto A =
Attrs.getFnAttr(
"sign-return-address");
A.isValid()) {
2353 if (S !=
"none" && S !=
"all" && S !=
"non-leaf")
2354 CheckFailed(
"invalid value for 'sign-return-address' attribute: " + S, V);
2357 if (
auto A =
Attrs.getFnAttr(
"sign-return-address-key");
A.isValid()) {
2359 if (S !=
"a_key" && S !=
"b_key")
2360 CheckFailed(
"invalid value for 'sign-return-address-key' attribute: " + S,
2364 if (
auto A =
Attrs.getFnAttr(
"branch-target-enforcement");
A.isValid()) {
2366 if (S !=
"true" && S !=
"false")
2368 "invalid value for 'branch-target-enforcement' attribute: " + S, V);
2371 if (
auto A =
Attrs.getFnAttr(
"vector-function-abi-variant");
A.isValid()) {
2375 CheckFailed(
"invalid name for a VFABI variant: " + S, V);
2379void Verifier::verifyFunctionMetadata(
2380 ArrayRef<std::pair<unsigned, MDNode *>> MDs) {
2381 for (
const auto &Pair : MDs) {
2382 if (Pair.first == LLVMContext::MD_prof) {
2383 MDNode *MD = Pair.second;
2385 "!prof annotations should have no less than 2 operands", MD);
2388 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null",
2391 "expected string with name of the !prof annotation", MD);
2394 Check(ProfName ==
"function_entry_count" ||
2395 ProfName ==
"synthetic_function_entry_count",
2396 "first operand should be 'function_entry_count'"
2397 " or 'synthetic_function_entry_count'",
2401 Check(MD->
getOperand(1) !=
nullptr,
"second operand should not be null",
2404 "expected integer argument to function_entry_count", MD);
2405 }
else if (Pair.first == LLVMContext::MD_kcfi_type) {
2406 MDNode *MD = Pair.second;
2408 "!kcfi_type must have exactly one operand", MD);
2409 Check(MD->
getOperand(0) !=
nullptr,
"!kcfi_type operand must not be null",
2412 "expected a constant operand for !kcfi_type", MD);
2414 Check(isa<ConstantInt>(
C) && isa<IntegerType>(
C->getType()),
2415 "expected a constant integer operand for !kcfi_type", MD);
2417 "expected a 32-bit integer constant operand for !kcfi_type", MD);
2422void Verifier::visitConstantExprsRecursively(
const Constant *EntryC) {
2423 if (!ConstantExprVisited.
insert(EntryC).second)
2427 Stack.push_back(EntryC);
2429 while (!
Stack.empty()) {
2433 if (
const auto *CE = dyn_cast<ConstantExpr>(
C))
2434 visitConstantExpr(CE);
2436 if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C))
2437 visitConstantPtrAuth(CPA);
2439 if (
const auto *GV = dyn_cast<GlobalValue>(
C)) {
2442 Check(GV->
getParent() == &M,
"Referencing global in another module!",
2448 for (
const Use &U :
C->operands()) {
2449 const auto *OpC = dyn_cast<Constant>(U);
2452 if (!ConstantExprVisited.
insert(OpC).second)
2454 Stack.push_back(OpC);
2459void Verifier::visitConstantExpr(
const ConstantExpr *CE) {
2460 if (
CE->getOpcode() == Instruction::BitCast)
2463 "Invalid bitcast", CE);
2468 "signed ptrauth constant base pointer must have pointer type");
2471 "signed ptrauth constant must have same type as its base pointer");
2474 "signed ptrauth constant key must be i32 constant integer");
2477 "signed ptrauth constant address discriminator must be a pointer");
2480 "signed ptrauth constant discriminator must be i64 constant integer");
2483bool Verifier::verifyAttributeCount(
AttributeList Attrs,
unsigned Params) {
2486 return Attrs.getNumAttrSets() <= Params + 2;
2489void Verifier::verifyInlineAsmCall(
const CallBase &Call) {
2492 unsigned LabelNo = 0;
2503 if (CI.isIndirect) {
2504 const Value *Arg =
Call.getArgOperand(ArgNo);
2506 "Operand for indirect constraint must have pointer type", &Call);
2509 "Operand for indirect constraint must have elementtype attribute",
2512 Check(!
Call.paramHasAttr(ArgNo, Attribute::ElementType),
2513 "Elementtype attribute can only be applied for indirect "
2521 if (
auto *CallBr = dyn_cast<CallBrInst>(&Call)) {
2522 Check(LabelNo == CallBr->getNumIndirectDests(),
2523 "Number of label constraints does not match number of callbr dests",
2526 Check(LabelNo == 0,
"Label constraints can only be used with callbr",
2532void Verifier::verifyStatepoint(
const CallBase &Call) {
2534 Call.getCalledFunction()->getIntrinsicID() ==
2535 Intrinsic::experimental_gc_statepoint);
2537 Check(!
Call.doesNotAccessMemory() && !
Call.onlyReadsMemory() &&
2538 !
Call.onlyAccessesArgMemory(),
2539 "gc.statepoint must read and write all memory to preserve "
2540 "reordering restrictions required by safepoint semantics",
2543 const int64_t NumPatchBytes =
2544 cast<ConstantInt>(
Call.getArgOperand(1))->getSExtValue();
2545 assert(isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
2546 Check(NumPatchBytes >= 0,
2547 "gc.statepoint number of patchable bytes must be "
2551 Type *TargetElemType =
Call.getParamElementType(2);
2552 Check(TargetElemType,
2553 "gc.statepoint callee argument must have elementtype attribute", Call);
2554 FunctionType *TargetFuncType = dyn_cast<FunctionType>(TargetElemType);
2555 Check(TargetFuncType,
2556 "gc.statepoint callee elementtype must be function type", Call);
2558 const int NumCallArgs = cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue();
2559 Check(NumCallArgs >= 0,
2560 "gc.statepoint number of arguments to underlying call "
2563 const int NumParams = (int)TargetFuncType->getNumParams();
2564 if (TargetFuncType->isVarArg()) {
2565 Check(NumCallArgs >= NumParams,
2566 "gc.statepoint mismatch in number of vararg call args", Call);
2569 Check(TargetFuncType->getReturnType()->isVoidTy(),
2570 "gc.statepoint doesn't support wrapping non-void "
2571 "vararg functions yet",
2574 Check(NumCallArgs == NumParams,
2575 "gc.statepoint mismatch in number of call args", Call);
2578 = cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue();
2580 "unknown flag used in gc.statepoint flags argument", Call);
2585 for (
int i = 0; i < NumParams; i++) {
2586 Type *ParamType = TargetFuncType->getParamType(i);
2587 Type *ArgType =
Call.getArgOperand(5 + i)->getType();
2588 Check(ArgType == ParamType,
2589 "gc.statepoint call argument does not match wrapped "
2593 if (TargetFuncType->isVarArg()) {
2596 "Attribute 'sret' cannot be used for vararg call arguments!", Call);
2600 const int EndCallArgsInx = 4 + NumCallArgs;
2602 const Value *NumTransitionArgsV =
Call.getArgOperand(EndCallArgsInx + 1);
2603 Check(isa<ConstantInt>(NumTransitionArgsV),
2604 "gc.statepoint number of transition arguments "
2605 "must be constant integer",
2607 const int NumTransitionArgs =
2608 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
2609 Check(NumTransitionArgs == 0,
2610 "gc.statepoint w/inline transition bundle is deprecated", Call);
2611 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
2613 const Value *NumDeoptArgsV =
Call.getArgOperand(EndTransitionArgsInx + 1);
2614 Check(isa<ConstantInt>(NumDeoptArgsV),
2615 "gc.statepoint number of deoptimization arguments "
2616 "must be constant integer",
2618 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
2619 Check(NumDeoptArgs == 0,
2620 "gc.statepoint w/inline deopt operands is deprecated", Call);
2622 const int ExpectedNumArgs = 7 + NumCallArgs;
2623 Check(ExpectedNumArgs == (
int)
Call.arg_size(),
2624 "gc.statepoint too many arguments", Call);
2629 for (
const User *U :
Call.users()) {
2630 const CallInst *UserCall = dyn_cast<const CallInst>(U);
2631 Check(UserCall,
"illegal use of statepoint token", Call, U);
2634 Check(isa<GCRelocateInst>(UserCall) || isa<GCResultInst>(UserCall),
2635 "gc.result or gc.relocate are the only value uses "
2636 "of a gc.statepoint",
2638 if (isa<GCResultInst>(UserCall)) {
2640 "gc.result connected to wrong gc.statepoint", Call, UserCall);
2641 }
else if (isa<GCRelocateInst>(Call)) {
2643 "gc.relocate connected to wrong gc.statepoint", Call, UserCall);
2657void Verifier::verifyFrameRecoverIndices() {
2658 for (
auto &Counts : FrameEscapeInfo) {
2660 unsigned EscapedObjectCount = Counts.second.first;
2661 unsigned MaxRecoveredIndex = Counts.second.second;
2662 Check(MaxRecoveredIndex <= EscapedObjectCount,
2663 "all indices passed to llvm.localrecover must be less than the "
2664 "number of arguments passed to llvm.localescape in the parent "
2672 if (
auto *
II = dyn_cast<InvokeInst>(Terminator))
2673 UnwindDest =
II->getUnwindDest();
2674 else if (
auto *CSI = dyn_cast<CatchSwitchInst>(Terminator))
2675 UnwindDest = CSI->getUnwindDest();
2677 UnwindDest = cast<CleanupReturnInst>(Terminator)->getUnwindDest();
2681void Verifier::verifySiblingFuncletUnwinds() {
2684 for (
const auto &Pair : SiblingFuncletInfo) {
2686 if (Visited.
count(PredPad))
2692 if (Active.
count(SuccPad)) {
2698 Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad];
2699 if (CycleTerminator != CyclePad)
2702 }
while (CyclePad != SuccPad);
2703 Check(
false,
"EH pads can't handle each other's exceptions",
2707 if (!Visited.
insert(SuccPad).second)
2711 auto TermI = SiblingFuncletInfo.find(PredPad);
2712 if (TermI == SiblingFuncletInfo.end())
2725void Verifier::visitFunction(
const Function &
F) {
2726 visitGlobalValue(
F);
2730 unsigned NumArgs =
F.arg_size();
2732 Check(&Context == &
F.getContext(),
2733 "Function context does not match Module context!", &
F);
2735 Check(!
F.hasCommonLinkage(),
"Functions may not have common linkage", &
F);
2736 Check(FT->getNumParams() == NumArgs,
2737 "# formal arguments must match # of arguments for function type!", &
F,
2739 Check(
F.getReturnType()->isFirstClassType() ||
2740 F.getReturnType()->isVoidTy() ||
F.getReturnType()->isStructTy(),
2741 "Functions cannot return aggregate values!", &
F);
2743 Check(!
F.hasStructRetAttr() ||
F.getReturnType()->isVoidTy(),
2744 "Invalid struct return type!", &
F);
2748 Check(verifyAttributeCount(Attrs, FT->getNumParams()),
2749 "Attribute after last parameter!", &
F);
2751 CheckDI(
F.IsNewDbgInfoFormat ==
F.getParent()->IsNewDbgInfoFormat,
2752 "Function debug format should match parent module", &
F,
2753 F.IsNewDbgInfoFormat,
F.getParent(),
2754 F.getParent()->IsNewDbgInfoFormat);
2756 bool IsIntrinsic =
F.isIntrinsic();
2759 verifyFunctionAttrs(FT, Attrs, &
F, IsIntrinsic,
false);
2765 "Attribute 'builtin' can only be applied to a callsite.", &
F);
2767 Check(!
Attrs.hasAttrSomewhere(Attribute::ElementType),
2768 "Attribute 'elementtype' can only be applied to a callsite.", &
F);
2773 switch (
F.getCallingConv()) {
2778 Check(
F.arg_empty() ||
Attrs.hasParamAttr(0, Attribute::ByVal),
2779 "Calling convention parameter requires byval", &
F);
2786 Check(
F.getReturnType()->isVoidTy(),
2787 "Calling convention requires void return type", &
F);
2794 Check(!
F.hasStructRetAttr(),
"Calling convention does not allow sret", &
F);
2796 const unsigned StackAS =
DL.getAllocaAddrSpace();
2799 Check(!
Attrs.hasParamAttr(i, Attribute::ByVal),
2800 "Calling convention disallows byval", &
F);
2801 Check(!
Attrs.hasParamAttr(i, Attribute::Preallocated),
2802 "Calling convention disallows preallocated", &
F);
2803 Check(!
Attrs.hasParamAttr(i, Attribute::InAlloca),
2804 "Calling convention disallows inalloca", &
F);
2806 if (
Attrs.hasParamAttr(i, Attribute::ByRef)) {
2809 Check(Arg.getType()->getPointerAddressSpace() != StackAS,
2810 "Calling convention disallows stack byref", &
F);
2824 "Calling convention does not support varargs or "
2825 "perfect forwarding!",
2833 Check(Arg.getType() == FT->getParamType(i),
2834 "Argument value does not match function argument type!", &Arg,
2835 FT->getParamType(i));
2836 Check(Arg.getType()->isFirstClassType(),
2837 "Function arguments must have first-class types!", &Arg);
2839 Check(!Arg.getType()->isMetadataTy(),
2840 "Function takes metadata but isn't an intrinsic", &Arg, &
F);
2841 Check(!Arg.getType()->isTokenTy(),
2842 "Function takes token but isn't an intrinsic", &Arg, &
F);
2843 Check(!Arg.getType()->isX86_AMXTy(),
2844 "Function takes x86_amx but isn't an intrinsic", &Arg, &
F);
2848 if (
Attrs.hasParamAttr(i, Attribute::SwiftError)) {
2849 verifySwiftErrorValue(&Arg);
2855 Check(!
F.getReturnType()->isTokenTy(),
2856 "Function returns a token but isn't an intrinsic", &
F);
2857 Check(!
F.getReturnType()->isX86_AMXTy(),
2858 "Function returns a x86_amx but isn't an intrinsic", &
F);
2863 F.getAllMetadata(MDs);
2864 assert(
F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
2865 verifyFunctionMetadata(MDs);
2868 if (
F.hasPersonalityFn()) {
2869 auto *Per = dyn_cast<Function>(
F.getPersonalityFn()->stripPointerCasts());
2871 Check(Per->getParent() ==
F.getParent(),
2872 "Referencing personality function in another module!", &
F,
2873 F.getParent(), Per, Per->getParent());
2877 BlockEHFuncletColors.
clear();
2879 if (
F.isMaterializable()) {
2881 Check(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
2883 }
else if (
F.isDeclaration()) {
2884 for (
const auto &
I : MDs) {
2886 CheckDI(
I.first != LLVMContext::MD_dbg ||
2887 !cast<DISubprogram>(
I.second)->isDistinct(),
2888 "function declaration may only have a unique !dbg attachment",
2890 Check(
I.first != LLVMContext::MD_prof,
2891 "function declaration may not have a !prof attachment", &
F);
2894 visitMDNode(*
I.second, AreDebugLocsAllowed::Yes);
2896 Check(!
F.hasPersonalityFn(),
2897 "Function declaration shouldn't have a personality routine", &
F);
2901 Check(!IsIntrinsic,
"llvm intrinsics cannot be defined!", &
F);
2906 "Entry block to function must not have predecessors!", Entry);
2909 if (
Entry->hasAddressTaken()) {
2911 "blockaddress may not be used with the entry block!", Entry);
2914 unsigned NumDebugAttachments = 0, NumProfAttachments = 0,
2915 NumKCFIAttachments = 0;
2917 for (
const auto &
I : MDs) {
2919 auto AllowLocs = AreDebugLocsAllowed::No;
2923 case LLVMContext::MD_dbg: {
2924 ++NumDebugAttachments;
2925 CheckDI(NumDebugAttachments == 1,
2926 "function must have a single !dbg attachment", &
F,
I.second);
2927 CheckDI(isa<DISubprogram>(
I.second),
2928 "function !dbg attachment must be a subprogram", &
F,
I.second);
2929 CheckDI(cast<DISubprogram>(
I.second)->isDistinct(),
2930 "function definition may only have a distinct !dbg attachment",
2933 auto *SP = cast<DISubprogram>(
I.second);
2934 const Function *&AttachedTo = DISubprogramAttachments[SP];
2935 CheckDI(!AttachedTo || AttachedTo == &
F,
2936 "DISubprogram attached to more than one function", SP, &
F);
2938 AllowLocs = AreDebugLocsAllowed::Yes;
2941 case LLVMContext::MD_prof:
2942 ++NumProfAttachments;
2943 Check(NumProfAttachments == 1,
2944 "function must have a single !prof attachment", &
F,
I.second);
2946 case LLVMContext::MD_kcfi_type:
2947 ++NumKCFIAttachments;
2948 Check(NumKCFIAttachments == 1,
2949 "function must have a single !kcfi_type attachment", &
F,
2955 visitMDNode(*
I.second, AllowLocs);
2963 if (
F.isIntrinsic() &&
F.getParent()->isMaterialized()) {
2965 if (
F.hasAddressTaken(&U,
false,
true,
false,
2967 Check(
false,
"Invalid user of intrinsic instruction!", U);
2971 switch (
F.getIntrinsicID()) {
2972 case Intrinsic::experimental_gc_get_pointer_base: {
2974 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2975 Check(isa<PointerType>(
F.getReturnType()),
2976 "gc.get.pointer.base must return a pointer",
F);
2977 Check(FT->getParamType(0) ==
F.getReturnType(),
2978 "gc.get.pointer.base operand and result must be of the same type",
F);
2981 case Intrinsic::experimental_gc_get_pointer_offset: {
2983 Check(FT->getNumParams() == 1,
"wrong number of parameters",
F);
2984 Check(isa<PointerType>(FT->getParamType(0)),
2985 "gc.get.pointer.offset operand must be a pointer",
F);
2986 Check(
F.getReturnType()->isIntegerTy(),
2987 "gc.get.pointer.offset must return integer",
F);
2992 auto *
N =
F.getSubprogram();
2993 HasDebugInfo = (
N !=
nullptr);
3012 CheckDI(Parent && isa<DILocalScope>(Parent),
3013 "DILocation's scope must be a DILocalScope",
N, &
F, &
I,
DL, Parent);
3016 Check(Scope,
"Failed to find DILocalScope",
DL);
3018 if (!Seen.
insert(Scope).second)
3025 if (SP && ((Scope != SP) && !Seen.
insert(SP).second))
3029 "!dbg attachment points at wrong subprogram for function",
N, &
F,
3033 for (
auto &
I : BB) {
3034 VisitDebugLoc(
I,
I.getDebugLoc().getAsMDNode());
3036 if (
auto MD =
I.getMetadata(LLVMContext::MD_loop))
3038 VisitDebugLoc(
I, dyn_cast_or_null<MDNode>(MD->
getOperand(i)));
3039 if (BrokenDebugInfo)
3046void Verifier::visitBasicBlock(
BasicBlock &BB) {
3047 InstsInThisBlock.
clear();
3048 ConvergenceVerifyHelper.
visit(BB);
3055 if (isa<PHINode>(BB.
front())) {
3060 Check(PN.getNumIncomingValues() == Preds.size(),
3061 "PHINode should have one entry for each predecessor of its "
3062 "parent basic block!",
3067 Values.
reserve(PN.getNumIncomingValues());
3068 for (
unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
3070 std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i)));
3073 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
3078 Check(i == 0 || Values[i].first != Values[i - 1].first ||
3079 Values[i].second == Values[i - 1].second,
3080 "PHI node has multiple entries for the same basic block with "
3081 "different incoming values!",
3082 &PN, Values[i].first, Values[i].second, Values[i - 1].second);
3086 Check(Values[i].first == Preds[i],
3087 "PHI node entries do not match predecessors!", &PN,
3088 Values[i].first, Preds[i]);
3096 Check(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
3099 CheckDI(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
3100 "BB debug format should match parent function", &BB,
3101 BB.IsNewDbgInfoFormat, BB.getParent(),
3102 BB.getParent()->IsNewDbgInfoFormat);
3105 if (BB.IsNewDbgInfoFormat)
3106 CheckDI(!BB.getTrailingDbgRecords(),
"Basic Block has trailing DbgRecords!",
3112 Check(&
I ==
I.getParent()->getTerminator(),
3113 "Terminator found in the middle of a basic block!",
I.getParent());
3117void Verifier::visitBranchInst(
BranchInst &BI) {
3120 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
3125void Verifier::visitReturnInst(
ReturnInst &RI) {
3128 if (
F->getReturnType()->isVoidTy())
3130 "Found return instr that returns non-void in Function of void "
3132 &RI,
F->getReturnType());
3135 "Function return type does not match operand "
3136 "type of return inst!",
3137 &RI,
F->getReturnType());
3144void Verifier::visitSwitchInst(
SwitchInst &SI) {
3145 Check(
SI.getType()->isVoidTy(),
"Switch must have void result type!", &SI);
3148 Type *SwitchTy =
SI.getCondition()->getType();
3150 for (
auto &Case :
SI.cases()) {
3151 Check(isa<ConstantInt>(
SI.getOperand(Case.getCaseIndex() * 2 + 2)),
3152 "Case value is not a constant integer.", &SI);
3153 Check(Case.getCaseValue()->getType() == SwitchTy,
3154 "Switch constants must all be same type as switch value!", &SI);
3156 "Duplicate integer as switch case", &SI, Case.getCaseValue());
3164 "Indirectbr operand must have pointer type!", &BI);
3167 "Indirectbr destinations must all have pointer type!", &BI);
3172void Verifier::visitCallBrInst(
CallBrInst &CBI) {
3173 Check(CBI.
isInlineAsm(),
"Callbr is currently only used for asm-goto!", &CBI);
3175 Check(!
IA->canThrow(),
"Unwinding from Callbr is not allowed");
3177 verifyInlineAsmCall(CBI);
3181void Verifier::visitSelectInst(
SelectInst &SI) {
3184 "Invalid operands for select instruction!", &SI);
3186 Check(
SI.getTrueValue()->getType() ==
SI.getType(),
3187 "Select values must have same type as select instruction!", &SI);
3195 Check(
false,
"User-defined operators should not live outside of a pass!", &
I);
3200 Type *SrcTy =
I.getOperand(0)->getType();
3201 Type *DestTy =
I.getType();
3210 "trunc source and destination must both be a vector or neither", &
I);
3211 Check(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &
I);
3216void Verifier::visitZExtInst(
ZExtInst &
I) {
3218 Type *SrcTy =
I.getOperand(0)->getType();
3219 Type *DestTy =
I.getType();
3225 "zext source and destination must both be a vector or neither", &
I);
3229 Check(SrcBitSize < DestBitSize,
"Type too small for ZExt", &
I);
3234void Verifier::visitSExtInst(
SExtInst &
I) {
3236 Type *SrcTy =
I.getOperand(0)->getType();
3237 Type *DestTy =
I.getType();
3246 "sext source and destination must both be a vector or neither", &
I);
3247 Check(SrcBitSize < DestBitSize,
"Type too small for SExt", &
I);
3254 Type *SrcTy =
I.getOperand(0)->getType();
3255 Type *DestTy =
I.getType();
3263 "fptrunc source and destination must both be a vector or neither", &
I);
3264 Check(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &
I);
3271 Type *SrcTy =
I.getOperand(0)->getType();
3272 Type *DestTy =
I.getType();
3281 "fpext source and destination must both be a vector or neither", &
I);
3282 Check(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &
I);
3289 Type *SrcTy =
I.getOperand(0)->getType();
3290 Type *DestTy =
I.getType();
3295 Check(SrcVec == DstVec,
3296 "UIToFP source and dest must both be vector or scalar", &
I);
3298 "UIToFP source must be integer or integer vector", &
I);
3302 if (SrcVec && DstVec)
3303 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3304 cast<VectorType>(DestTy)->getElementCount(),
3305 "UIToFP source and dest vector length mismatch", &
I);
3312 Type *SrcTy =
I.getOperand(0)->getType();
3313 Type *DestTy =
I.getType();
3318 Check(SrcVec == DstVec,
3319 "SIToFP source and dest must both be vector or scalar", &
I);
3321 "SIToFP source must be integer or integer vector", &
I);
3325 if (SrcVec && DstVec)
3326 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3327 cast<VectorType>(DestTy)->getElementCount(),
3328 "SIToFP source and dest vector length mismatch", &
I);
3335 Type *SrcTy =
I.getOperand(0)->getType();
3336 Type *DestTy =
I.getType();
3341 Check(SrcVec == DstVec,
3342 "FPToUI source and dest must both be vector or scalar", &
I);
3345 "FPToUI result must be integer or integer vector", &
I);
3347 if (SrcVec && DstVec)
3348 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3349 cast<VectorType>(DestTy)->getElementCount(),
3350 "FPToUI source and dest vector length mismatch", &
I);
3357 Type *SrcTy =
I.getOperand(0)->getType();
3358 Type *DestTy =
I.getType();
3363 Check(SrcVec == DstVec,
3364 "FPToSI source and dest must both be vector or scalar", &
I);
3367 "FPToSI result must be integer or integer vector", &
I);
3369 if (SrcVec && DstVec)
3370 Check(cast<VectorType>(SrcTy)->getElementCount() ==
3371 cast<VectorType>(DestTy)->getElementCount(),
3372 "FPToSI source and dest vector length mismatch", &
I);
3379 Type *SrcTy =
I.getOperand(0)->getType();
3380 Type *DestTy =
I.getType();
3389 auto *VSrc = cast<VectorType>(SrcTy);
3390 auto *VDest = cast<VectorType>(DestTy);
3391 Check(VSrc->getElementCount() == VDest->getElementCount(),
3392 "PtrToInt Vector width mismatch", &
I);
3400 Type *SrcTy =
I.getOperand(0)->getType();
3401 Type *DestTy =
I.getType();
3409 auto *VSrc = cast<VectorType>(SrcTy);
3410 auto *VDest = cast<VectorType>(DestTy);
3411 Check(VSrc->getElementCount() == VDest->getElementCount(),
3412 "IntToPtr Vector width mismatch", &
I);
3420 "Invalid bitcast", &
I);
3425 Type *SrcTy =
I.getOperand(0)->getType();
3426 Type *DestTy =
I.getType();
3433 "AddrSpaceCast must be between different address spaces", &
I);
3434 if (
auto *SrcVTy = dyn_cast<VectorType>(SrcTy))
3435 Check(SrcVTy->getElementCount() ==
3436 cast<VectorType>(DestTy)->getElementCount(),
3437 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
3443void Verifier::visitPHINode(
PHINode &PN) {
3450 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
3459 "PHI node operands are not the same type as the result!", &PN);
3467void Verifier::visitCallBase(
CallBase &Call) {
3468 Check(
Call.getCalledOperand()->getType()->isPointerTy(),
3469 "Called function must be a pointer!", Call);
3473 if (FTy->isVarArg())
3474 Check(
Call.arg_size() >= FTy->getNumParams(),
3475 "Called function requires more parameters than were provided!", Call);
3477 Check(
Call.arg_size() == FTy->getNumParams(),
3478 "Incorrect number of arguments passed to called function!", Call);
3481 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3482 Check(
Call.getArgOperand(i)->getType() == FTy->getParamType(i),
3483 "Call parameter type does not match function signature!",
3484 Call.getArgOperand(i), FTy->getParamType(i), Call);
3488 Check(verifyAttributeCount(Attrs,
Call.arg_size()),
3489 "Attribute after last parameter!", Call);
3492 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
3496 "Intrinsic called with incompatible signature", Call);
3500 auto CC =
Call.getCallingConv();
3503 "Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions "
3504 "not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.",
3507 auto VerifyTypeAlign = [&](
Type *Ty,
const Twine &Message) {
3510 Align ABIAlign =
DL.getABITypeAlign(Ty);
3511 Align MaxAlign(ParamMaxAlignment);
3512 Check(ABIAlign <= MaxAlign,
3513 "Incorrect alignment of " + Message +
" to called function!", Call);
3517 VerifyTypeAlign(FTy->getReturnType(),
"return type");
3518 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3519 Type *Ty = FTy->getParamType(i);
3520 VerifyTypeAlign(Ty,
"argument passed");
3524 if (
Attrs.hasFnAttr(Attribute::Speculatable)) {
3528 "speculatable attribute may not apply to call sites", Call);
3531 if (
Attrs.hasFnAttr(Attribute::Preallocated)) {
3532 Check(
Call.getCalledFunction()->getIntrinsicID() ==
3533 Intrinsic::call_preallocated_arg,
3534 "preallocated as a call site attribute can only be on "
3535 "llvm.call.preallocated.arg");
3539 verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic,
Call.isInlineAsm());
3544 if (
Call.hasInAllocaArgument()) {
3545 Value *InAllocaArg =
Call.getArgOperand(FTy->getNumParams() - 1);
3547 Check(AI->isUsedWithInAlloca(),
3548 "inalloca argument for call has mismatched alloca", AI, Call);
3554 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3555 if (
Call.paramHasAttr(i, Attribute::SwiftError)) {
3556 Value *SwiftErrorArg =
Call.getArgOperand(i);
3558 Check(AI->isSwiftError(),
3559 "swifterror argument for call has mismatched alloca", AI, Call);
3562 auto ArgI = dyn_cast<Argument>(SwiftErrorArg);
3563 Check(ArgI,
"swifterror argument should come from an alloca or parameter",
3564 SwiftErrorArg, Call);
3565 Check(ArgI->hasSwiftErrorAttr(),
3566 "swifterror argument for call has mismatched parameter", ArgI,
3570 if (
Attrs.hasParamAttr(i, Attribute::ImmArg)) {
3573 Check(Callee &&
Callee->hasParamAttribute(i, Attribute::ImmArg),
3574 "immarg may not apply only to call sites",
Call.getArgOperand(i),
3578 if (
Call.paramHasAttr(i, Attribute::ImmArg)) {
3580 Check(isa<ConstantInt>(ArgVal) || isa<ConstantFP>(ArgVal),
3581 "immarg operand has non-immediate parameter", ArgVal, Call);
3584 if (
Call.paramHasAttr(i, Attribute::Preallocated)) {
3588 bool isMustTail =
Call.isMustTailCall();
3589 Check(hasOB != isMustTail,
3590 "preallocated operand either requires a preallocated bundle or "
3591 "the call to be musttail (but not both)",
3596 if (FTy->isVarArg()) {
3598 bool SawNest =
false;
3599 bool SawReturned =
false;
3601 for (
unsigned Idx = 0;
Idx < FTy->getNumParams(); ++
Idx) {
3602 if (
Attrs.hasParamAttr(
Idx, Attribute::Nest))
3604 if (
Attrs.hasParamAttr(
Idx, Attribute::Returned))
3609 for (
unsigned Idx = FTy->getNumParams();
Idx <
Call.arg_size(); ++
Idx) {
3612 verifyParameterAttrs(ArgAttrs, Ty, &Call);
3615 Check(!SawNest,
"More than one parameter has attribute nest!", Call);
3620 Check(!SawReturned,
"More than one parameter has attribute returned!",
3623 "Incompatible argument and return types for 'returned' "
3631 if (!
Call.getCalledFunction() ||
3632 Call.getCalledFunction()->getIntrinsicID() !=
3633 Intrinsic::experimental_gc_statepoint)
3635 "Attribute 'sret' cannot be used for vararg call arguments!",
3640 "inalloca isn't on the last argument!", Call);
3646 for (
Type *ParamTy : FTy->params()) {
3647 Check(!ParamTy->isMetadataTy(),
3648 "Function has metadata parameter but isn't an intrinsic", Call);
3649 Check(!ParamTy->isTokenTy(),
3650 "Function has token parameter but isn't an intrinsic", Call);
3655 if (!
Call.getCalledFunction()) {
3656 Check(!FTy->getReturnType()->isTokenTy(),
3657 "Return type cannot be token for indirect call!");
3658 Check(!FTy->getReturnType()->isX86_AMXTy(),
3659 "Return type cannot be x86_amx for indirect call!");
3664 visitIntrinsicCall(
ID, Call);
3669 bool FoundDeoptBundle =
false, FoundFuncletBundle =
false,
3670 FoundGCTransitionBundle =
false, FoundCFGuardTargetBundle =
false,
3671 FoundPreallocatedBundle =
false, FoundGCLiveBundle =
false,
3672 FoundPtrauthBundle =
false, FoundKCFIBundle =
false,
3673 FoundAttachedCallBundle =
false;
3674 for (
unsigned i = 0, e =
Call.getNumOperandBundles(); i < e; ++i) {
3678 Check(!FoundDeoptBundle,
"Multiple deopt operand bundles", Call);
3679 FoundDeoptBundle =
true;
3681 Check(!FoundGCTransitionBundle,
"Multiple gc-transition operand bundles",
3683 FoundGCTransitionBundle =
true;
3685 Check(!FoundFuncletBundle,
"Multiple funclet operand bundles", Call);
3686 FoundFuncletBundle =
true;
3688 "Expected exactly one funclet bundle operand", Call);
3690 "Funclet bundle operands should correspond to a FuncletPadInst",
3693 Check(!FoundCFGuardTargetBundle,
"Multiple CFGuardTarget operand bundles",
3695 FoundCFGuardTargetBundle =
true;
3697 "Expected exactly one cfguardtarget bundle operand", Call);
3699 Check(!FoundPtrauthBundle,
"Multiple ptrauth operand bundles", Call);
3700 FoundPtrauthBundle =
true;
3702 "Expected exactly two ptrauth bundle operands", Call);
3704 BU.
Inputs[0]->getType()->isIntegerTy(32),
3705 "Ptrauth bundle key operand must be an i32 constant", Call);
3707 "Ptrauth bundle discriminator operand must be an i64", Call);
3709 Check(!FoundKCFIBundle,
"Multiple kcfi operand bundles", Call);
3710 FoundKCFIBundle =
true;
3711 Check(BU.
Inputs.size() == 1,
"Expected exactly one kcfi bundle operand",
3714 BU.
Inputs[0]->getType()->isIntegerTy(32),
3715 "Kcfi bundle operand must be an i32 constant", Call);
3717 Check(!FoundPreallocatedBundle,
"Multiple preallocated operand bundles",
3719 FoundPreallocatedBundle =
true;
3721 "Expected exactly one preallocated bundle operand", Call);
3722 auto Input = dyn_cast<IntrinsicInst>(BU.
Inputs.front());
3724 Input->getIntrinsicID() == Intrinsic::call_preallocated_setup,
3725 "\"preallocated\" argument must be a token from "
3726 "llvm.call.preallocated.setup",
3729 Check(!FoundGCLiveBundle,
"Multiple gc-live operand bundles", Call);
3730 FoundGCLiveBundle =
true;
3732 Check(!FoundAttachedCallBundle,
3733 "Multiple \"clang.arc.attachedcall\" operand bundles", Call);
3734 FoundAttachedCallBundle =
true;
3735 verifyAttachedCallBundle(Call, BU);
3740 Check(!(
Call.getCalledFunction() && FoundPtrauthBundle),
3741 "Direct call cannot have a ptrauth bundle", Call);
3748 if (
Call.getFunction()->getSubprogram() &&
Call.getCalledFunction() &&
3749 !
Call.getCalledFunction()->isInterposable() &&
3750 !
Call.getCalledFunction()->isDeclaration() &&
3751 Call.getCalledFunction()->getSubprogram())
3753 "inlinable function call in a function with "
3754 "debug info must have a !dbg location",
3757 if (
Call.isInlineAsm())
3758 verifyInlineAsmCall(Call);
3760 ConvergenceVerifyHelper.
visit(Call);
3765void Verifier::verifyTailCCMustTailAttrs(
const AttrBuilder &Attrs,
3768 Twine(
"inalloca attribute not allowed in ") + Context);
3770 Twine(
"inreg attribute not allowed in ") + Context);
3771 Check(!
Attrs.contains(Attribute::SwiftError),
3772 Twine(
"swifterror attribute not allowed in ") + Context);
3773 Check(!
Attrs.contains(Attribute::Preallocated),
3774 Twine(
"preallocated attribute not allowed in ") + Context);
3776 Twine(
"byref attribute not allowed in ") + Context);
3788 return PL->getAddressSpace() == PR->getAddressSpace();
3793 Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca,
3794 Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf,
3795 Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated,
3798 for (
auto AK : ABIAttrs) {
3799 Attribute Attr = Attrs.getParamAttrs(
I).getAttribute(AK);
3801 Copy.addAttribute(Attr);
3805 if (Attrs.hasParamAttr(
I, Attribute::Alignment) &&
3806 (Attrs.hasParamAttr(
I, Attribute::ByVal) ||
3807 Attrs.hasParamAttr(
I, Attribute::ByRef)))
3808 Copy.addAlignmentAttr(Attrs.getParamAlignment(
I));
3812void Verifier::verifyMustTailCall(
CallInst &CI) {
3818 Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),
3819 "cannot guarantee tail call due to mismatched varargs", &CI);
3821 "cannot guarantee tail call due to mismatched return types", &CI);
3825 "cannot guarantee tail call due to mismatched calling conv", &CI);
3831 Value *RetVal = &CI;
3835 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
3837 "bitcast following musttail call must use the call", BI);
3844 Check(Ret,
"musttail call must precede a ret with an optional bitcast", &CI);
3845 Check(!
Ret->getReturnValue() ||
Ret->getReturnValue() == RetVal ||
3846 isa<UndefValue>(
Ret->getReturnValue()),
3847 "musttail call result must be returned", Ret);
3858 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3861 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3863 for (
unsigned I = 0, E = CalleeTy->getNumParams();
I != E; ++
I) {
3866 verifyTailCCMustTailAttrs(ABIAttrs, Context);
3869 Check(!CallerTy->isVarArg(),
Twine(
"cannot guarantee ") + CCName +
3870 " tail call for varargs function");
3878 Check(CallerTy->getNumParams() == CalleeTy->getNumParams(),
3879 "cannot guarantee tail call due to mismatched parameter counts", &CI);
3880 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3883 "cannot guarantee tail call due to mismatched parameter types", &CI);
3889 for (
unsigned I = 0, E = CallerTy->getNumParams();
I != E; ++
I) {
3892 Check(CallerABIAttrs == CalleeABIAttrs,
3893 "cannot guarantee tail call due to mismatched ABI impacting "
3894 "function attributes",
3899void Verifier::visitCallInst(
CallInst &CI) {
3903 verifyMustTailCall(CI);
3912 II.getUnwindDest()->isEHPad(),
3913 "The unwind destination does not have an exception handling instruction!",
3922 Check(
U.getType() ==
U.getOperand(0)->getType(),
3923 "Unary operators must have same type for"
3924 "operands and result!",
3927 switch (
U.getOpcode()) {
3930 case Instruction::FNeg:
3931 Check(
U.getType()->isFPOrFPVectorTy(),
3932 "FNeg operator only works with float types!", &U);
3945 Check(
B.getOperand(0)->getType() ==
B.getOperand(1)->getType(),
3946 "Both operands to a binary operator are not of the same type!", &
B);
3948 switch (
B.getOpcode()) {
3951 case Instruction::Add:
3952 case Instruction::Sub:
3953 case Instruction::Mul:
3954 case Instruction::SDiv:
3955 case Instruction::UDiv:
3956 case Instruction::SRem:
3957 case Instruction::URem:
3958 Check(
B.getType()->isIntOrIntVectorTy(),
3959 "Integer arithmetic operators only work with integral types!", &
B);
3960 Check(
B.getType() ==
B.getOperand(0)->getType(),
3961 "Integer arithmetic operators must have same type "
3962 "for operands and result!",
3967 case Instruction::FAdd:
3968 case Instruction::FSub:
3969 case Instruction::FMul:
3970 case Instruction::FDiv:
3971 case Instruction::FRem:
3972 Check(
B.getType()->isFPOrFPVectorTy(),
3973 "Floating-point arithmetic operators only work with "
3974 "floating-point types!",
3976 Check(
B.getType() ==
B.getOperand(0)->getType(),
3977 "Floating-point arithmetic operators must have same type "
3978 "for operands and result!",
3982 case Instruction::And:
3983 case Instruction::Or:
3984 case Instruction::Xor:
3985 Check(
B.getType()->isIntOrIntVectorTy(),
3986 "Logical operators only work with integral types!", &
B);
3987 Check(
B.getType() ==
B.getOperand(0)->getType(),
3988 "Logical operators must have same type for operands and result!", &
B);
3990 case Instruction::Shl:
3991 case Instruction::LShr:
3992 case Instruction::AShr:
3993 Check(
B.getType()->isIntOrIntVectorTy(),
3994 "Shifts only work with integral types!", &
B);
3995 Check(
B.getType() ==
B.getOperand(0)->getType(),
3996 "Shift return type must be same as operands!", &
B);
4005void Verifier::visitICmpInst(
ICmpInst &IC) {
4009 Check(Op0Ty == Op1Ty,
4010 "Both operands to ICmp instruction are not of the same type!", &IC);
4013 "Invalid operand types for ICmp instruction", &IC);
4020void Verifier::visitFCmpInst(
FCmpInst &FC) {
4022 Type *Op0Ty =
FC.getOperand(0)->getType();
4023 Type *Op1Ty =
FC.getOperand(1)->getType();
4024 Check(Op0Ty == Op1Ty,
4025 "Both operands to FCmp instruction are not of the same type!", &FC);
4030 Check(
FC.isFPPredicate(),
"Invalid predicate in FCmp instruction!", &FC);
4037 "Invalid extractelement operands!", &EI);
4044 "Invalid insertelement operands!", &IE);
4051 "Invalid shufflevector operands!", &SV);
4056 Type *TargetTy =
GEP.getPointerOperandType()->getScalarType();
4058 Check(isa<PointerType>(TargetTy),
4059 "GEP base pointer is not a vector or a vector of pointers", &
GEP);
4060 Check(
GEP.getSourceElementType()->isSized(),
"GEP into unsized type!", &
GEP);
4062 if (
auto *STy = dyn_cast<StructType>(
GEP.getSourceElementType())) {
4065 "getelementptr cannot target structure that contains scalable vector"
4072 all_of(Idxs, [](
Value *V) {
return V->getType()->isIntOrIntVectorTy(); }),
4073 "GEP indexes must be integers", &
GEP);
4076 Check(ElTy,
"Invalid indices for GEP pointer type!", &
GEP);
4078 Check(
GEP.getType()->isPtrOrPtrVectorTy() &&
4079 GEP.getResultElementType() == ElTy,
4080 "GEP is not of right type for indices!", &
GEP, ElTy);
4082 if (
auto *GEPVTy = dyn_cast<VectorType>(
GEP.getType())) {
4085 if (
GEP.getPointerOperandType()->isVectorTy())
4088 cast<VectorType>(
GEP.getPointerOperandType())->getElementCount(),
4089 "Vector GEP result width doesn't match operand's", &
GEP);
4091 Type *IndexTy =
Idx->getType();
4092 if (
auto *IndexVTy = dyn_cast<VectorType>(IndexTy)) {
4094 Check(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &
GEP);
4097 "All GEP indices should be of integer type");
4101 if (
auto *PTy = dyn_cast<PointerType>(
GEP.getType())) {
4102 Check(
GEP.getAddressSpace() == PTy->getAddressSpace(),
4103 "GEP address space doesn't match type", &
GEP);
4110 return A.getUpper() ==
B.getLower() ||
A.getLower() ==
B.getUpper();
4116 Type *Ty,
bool IsAbsoluteSymbol) {
4117 unsigned NumOperands =
Range->getNumOperands();
4118 Check(NumOperands % 2 == 0,
"Unfinished range!",
Range);
4119 unsigned NumRanges = NumOperands / 2;
4120 Check(NumRanges >= 1,
"It should have at least one range!",
Range);
4123 for (
unsigned i = 0; i < NumRanges; ++i) {
4125 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i));
4126 Check(
Low,
"The lower limit must be an integer!",
Low);
4128 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(2 * i + 1));
4132 "Range types must match instruction type!", &
I);
4140 "The upper and lower limits cannot be the same value", &
I);
4143 Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()),
4144 "Range must not be empty!",
Range);
4146 Check(CurRange.intersectWith(LastRange).isEmptySet(),
4147 "Intervals are overlapping",
Range);
4148 Check(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
4155 if (NumRanges > 2) {
4157 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(0))->getValue();
4159 mdconst::dyn_extract<ConstantInt>(
Range->getOperand(1))->getValue();
4161 Check(FirstRange.intersectWith(LastRange).isEmptySet(),
4162 "Intervals are overlapping",
Range);
4170 "precondition violation");
4171 verifyRangeMetadata(
I,
Range, Ty,
false);
4175 unsigned Size =
DL.getTypeSizeInBits(Ty);
4176 Check(
Size >= 8,
"atomic memory access' size must be byte-sized", Ty,
I);
4178 "atomic memory access' operand must have a power-of-two size", Ty,
I);
4181void Verifier::visitLoadInst(
LoadInst &LI) {
4183 Check(PTy,
"Load operand must be a pointer.", &LI);
4187 "huge alignment values are unsupported", &LI);
4189 Check(ElTy->
isSized(),
"loading unsized types is not allowed", &LI);
4193 "Load cannot have Release ordering", &LI);
4195 "atomic load operand must have integer, pointer, or floating point "
4198 checkAtomicMemAccessSize(ElTy, &LI);
4201 "Non-atomic load cannot have SynchronizationScope specified", &LI);
4207void Verifier::visitStoreInst(
StoreInst &SI) {
4208 PointerType *PTy = dyn_cast<PointerType>(
SI.getOperand(1)->getType());
4209 Check(PTy,
"Store operand must be a pointer.", &SI);
4210 Type *ElTy =
SI.getOperand(0)->getType();
4213 "huge alignment values are unsupported", &SI);
4215 Check(ElTy->
isSized(),
"storing unsized types is not allowed", &SI);
4216 if (
SI.isAtomic()) {
4219 "Store cannot have Acquire ordering", &SI);
4221 "atomic store operand must have integer, pointer, or floating point "
4224 checkAtomicMemAccessSize(ElTy, &SI);
4227 "Non-atomic store cannot have SynchronizationScope specified", &SI);
4233void Verifier::verifySwiftErrorCall(
CallBase &Call,
4234 const Value *SwiftErrorVal) {
4236 if (
I.value() == SwiftErrorVal) {
4237 Check(
Call.paramHasAttr(
I.index(), Attribute::SwiftError),
4238 "swifterror value when used in a callsite should be marked "
4239 "with swifterror attribute",
4240 SwiftErrorVal, Call);
4245void Verifier::verifySwiftErrorValue(
const Value *SwiftErrorVal) {
4248 for (
const User *U : SwiftErrorVal->
users()) {
4249 Check(isa<LoadInst>(U) || isa<StoreInst>(U) || isa<CallInst>(U) ||
4251 "swifterror value can only be loaded and stored from, or "
4252 "as a swifterror argument!",
4255 if (
auto StoreI = dyn_cast<StoreInst>(U))
4256 Check(StoreI->getOperand(1) == SwiftErrorVal,
4257 "swifterror value should be the second operand when used "
4260 if (
auto *Call = dyn_cast<CallBase>(U))
4261 verifySwiftErrorCall(*
const_cast<CallBase *
>(Call), SwiftErrorVal);
4265void Verifier::visitAllocaInst(
AllocaInst &AI) {
4268 "Cannot allocate unsized type", &AI);
4270 "Alloca array size must have integer type", &AI);
4273 "huge alignment values are unsupported", &AI);
4278 "swifterror alloca must have pointer type", &AI);
4280 "swifterror alloca must not be array allocation", &AI);
4281 verifySwiftErrorValue(&AI);
4290 "cmpxchg operand must have integer or pointer type", ElTy, &CXI);
4291 checkAtomicMemAccessSize(ElTy, &CXI);
4297 "atomicrmw instructions cannot be unordered.", &RMWI);
4304 " operand must have integer or floating point type!",
4309 " operand must have floating-point or fixed vector of floating-point "
4315 " operand must have integer type!",
4318 checkAtomicMemAccessSize(ElTy, &RMWI);
4320 "Invalid binary operation!", &RMWI);
4324void Verifier::visitFenceInst(
FenceInst &FI) {
4330 "fence instructions may only have acquire, release, acq_rel, or "
4331 "seq_cst ordering.",
4339 "Invalid ExtractValueInst operands!", &EVI);
4348 "Invalid InsertValueInst operands!", &IVI);
4354 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
4355 return FPI->getParentPad();
4357 return cast<CatchSwitchInst>(EHPad)->getParentPad();
4366 Check(BB != &
F->getEntryBlock(),
"EH pad cannot be in entry block.", &
I);
4368 if (
auto *LPI = dyn_cast<LandingPadInst>(&
I)) {
4373 const auto *
II = dyn_cast<InvokeInst>(PredBB->getTerminator());
4374 Check(
II &&
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4375 "Block containing LandingPadInst must be jumped to "
4376 "only by the unwind edge of an invoke.",
4381 if (
auto *CPI = dyn_cast<CatchPadInst>(&
I)) {
4384 "Block containg CatchPadInst must be jumped to "
4385 "only by its catchswitch.",
4387 Check(BB != CPI->getCatchSwitch()->getUnwindDest(),
4388 "Catchswitch cannot unwind to one of its catchpads",
4389 CPI->getCatchSwitch(), CPI);
4400 if (
auto *
II = dyn_cast<InvokeInst>(TI)) {
4401 Check(
II->getUnwindDest() == BB &&
II->getNormalDest() != BB,
4402 "EH pad must be jumped to via an unwind edge", ToPad,
II);
4404 dyn_cast<Function>(
II->getCalledOperand()->stripPointerCasts());
4405 if (CalledFn && CalledFn->isIntrinsic() &&
II->doesNotThrow() &&
4409 FromPad = Bundle->Inputs[0];
4412 }
else if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
4413 FromPad = CRI->getOperand(0);
4414 Check(FromPad != ToPadParent,
"A cleanupret must exit its cleanup", CRI);
4415 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(TI)) {
4418 Check(
false,
"EH pad must be jumped to via an unwind edge", ToPad, TI);
4424 Check(FromPad != ToPad,
4425 "EH pad cannot handle exceptions raised within it", FromPad, TI);
4426 if (FromPad == ToPadParent) {
4430 Check(!isa<ConstantTokenNone>(FromPad),
4431 "A single unwind edge may only enter one EH pad", TI);
4432 Check(Seen.
insert(FromPad).second,
"EH pad jumps through a cycle of pads",
4437 Check(isa<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(FromPad),
4438 "Parent pad must be catchpad/cleanuppad/catchswitch", TI);
4447 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
4449 visitEHPadPredecessors(LPI);
4451 if (!LandingPadResultTy)
4452 LandingPadResultTy = LPI.
getType();
4455 "The landingpad instruction should have a consistent result type "
4456 "inside a function.",
4460 Check(
F->hasPersonalityFn(),
4461 "LandingPadInst needs to be in a function with a personality.", &LPI);
4466 "LandingPadInst not the first non-PHI instruction in the block.", &LPI);
4472 "Catch operand does not have pointer type!", &LPI);
4474 Check(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
4476 "Filter operand is not an array of constants!", &LPI);
4483void Verifier::visitResumeInst(
ResumeInst &RI) {
4485 "ResumeInst needs to be in a function with a personality.", &RI);
4487 if (!LandingPadResultTy)
4491 "The resume instruction should have a consistent result type "
4492 "inside a function.",
4502 Check(
F->hasPersonalityFn(),
4503 "CatchPadInst needs to be in a function with a personality.", &CPI);
4506 "CatchPadInst needs to be directly nested in a CatchSwitchInst.",
4512 "CatchPadInst not the first non-PHI instruction in the block.", &CPI);
4514 visitEHPadPredecessors(CPI);
4520 "CatchReturnInst needs to be provided a CatchPad", &CatchReturn,
4530 Check(
F->hasPersonalityFn(),
4531 "CleanupPadInst needs to be in a function with a personality.", &CPI);
4536 "CleanupPadInst not the first non-PHI instruction in the block.", &CPI);
4539 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4540 "CleanupPadInst has an invalid parent.", &CPI);
4542 visitEHPadPredecessors(CPI);
4547 User *FirstUser =
nullptr;
4548 Value *FirstUnwindPad =
nullptr;
4552 while (!Worklist.empty()) {
4555 "FuncletPadInst must not be nested within itself", CurrentPad);
4556 Value *UnresolvedAncestorPad =
nullptr;
4559 if (
auto *CRI = dyn_cast<CleanupReturnInst>(U)) {
4560 UnwindDest = CRI->getUnwindDest();
4561 }
else if (
auto *CSI = dyn_cast<CatchSwitchInst>(U)) {
4566 if (CSI->unwindsToCaller())
4568 UnwindDest = CSI->getUnwindDest();
4569 }
else if (
auto *
II = dyn_cast<InvokeInst>(U)) {
4570 UnwindDest =
II->getUnwindDest();
4571 }
else if (isa<CallInst>(U)) {
4576 }
else if (
auto *CPI = dyn_cast<CleanupPadInst>(U)) {
4580 Worklist.push_back(CPI);
4583 Check(isa<CatchReturnInst>(U),
"Bogus funclet pad use", U);
4591 if (!cast<Instruction>(UnwindPad)->isEHPad())
4595 if (UnwindParent == CurrentPad)
4601 Value *ExitedPad = CurrentPad;
4604 if (ExitedPad == &FPI) {
4609 UnresolvedAncestorPad = &FPI;
4613 if (ExitedParent == UnwindParent) {
4617 UnresolvedAncestorPad = ExitedParent;
4620 ExitedPad = ExitedParent;
4621 }
while (!isa<ConstantTokenNone>(ExitedPad));
4626 UnresolvedAncestorPad = &FPI;
4633 Check(UnwindPad == FirstUnwindPad,
4634 "Unwind edges out of a funclet "
4635 "pad must have the same unwind "
4637 &FPI, U, FirstUser);
4640 FirstUnwindPad = UnwindPad;
4642 if (isa<CleanupPadInst>(&FPI) && !isa<ConstantTokenNone>(UnwindPad) &&
4644 SiblingFuncletInfo[&FPI] = cast<Instruction>(U);
4649 if (CurrentPad != &FPI)
4652 if (UnresolvedAncestorPad) {
4653 if (CurrentPad == UnresolvedAncestorPad) {
4657 assert(CurrentPad == &FPI);
4665 Value *ResolvedPad = CurrentPad;
4666 while (!Worklist.empty()) {
4667 Value *UnclePad = Worklist.back();
4671 while (ResolvedPad != AncestorPad) {
4673 if (ResolvedParent == UnresolvedAncestorPad) {
4676 ResolvedPad = ResolvedParent;
4680 if (ResolvedPad != AncestorPad)
4683 Worklist.pop_back();
4688 if (FirstUnwindPad) {
4689 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(FPI.
getParentPad())) {
4690 BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest();
4691 Value *SwitchUnwindPad;
4692 if (SwitchUnwindDest)
4696 Check(SwitchUnwindPad == FirstUnwindPad,
4697 "Unwind edges out of a catch must have the same unwind dest as "
4698 "the parent catchswitch",
4699 &FPI, FirstUser, CatchSwitch);
4710 Check(
F->hasPersonalityFn(),
4711 "CatchSwitchInst needs to be in a function with a personality.",
4717 "CatchSwitchInst not the first non-PHI instruction in the block.",
4721 Check(isa<ConstantTokenNone>(ParentPad) || isa<FuncletPadInst>(ParentPad),
4722 "CatchSwitchInst has an invalid parent.", ParentPad);
4726 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4727 "CatchSwitchInst must unwind to an EH block which is not a "
4733 SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch;
4737 "CatchSwitchInst cannot have empty handler list", &CatchSwitch);
4740 Check(isa<CatchPadInst>(Handler->getFirstNonPHI()),
4741 "CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler);
4744 visitEHPadPredecessors(CatchSwitch);
4750 "CleanupReturnInst needs to be provided a CleanupPad", &CRI,
4755 Check(
I->isEHPad() && !isa<LandingPadInst>(
I),
4756 "CleanupReturnInst must unwind to an EH block which is not a "
4764void Verifier::verifyDominatesUse(
Instruction &
I,
unsigned i) {
4770 if (
II->getNormalDest() ==
II->getUnwindDest())
4781 if (!isa<PHINode>(
I) && InstsInThisBlock.
count(
Op))
4784 const Use &
U =
I.getOperandUse(i);
4789 Check(
I.getType()->isPointerTy(),
4790 "dereferenceable, dereferenceable_or_null "
4791 "apply only to pointer types",
4793 Check((isa<LoadInst>(
I) || isa<IntToPtrInst>(
I)),
4794 "dereferenceable, dereferenceable_or_null apply only to load"
4795 " and inttoptr instructions, use attributes for calls or invokes",
4798 "dereferenceable, dereferenceable_or_null "
4799 "take one operand!",
4804 "dereferenceable_or_null metadata value must be an i64!",
4810 "!prof annotations should have no less than 2 operands", MD);
4813 Check(MD->
getOperand(0) !=
nullptr,
"first operand should not be null", MD);
4815 "expected string with name of the !prof annotation", MD);
4820 if (ProfName ==
"branch_weights") {
4822 if (isa<InvokeInst>(&
I)) {
4823 Check(NumBranchWeights == 1 || NumBranchWeights == 2,
4824 "Wrong number of InvokeInst branch_weights operands", MD);
4826 unsigned ExpectedNumOperands = 0;
4829 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
4830 ExpectedNumOperands =
SI->getNumSuccessors();
4831 else if (isa<CallInst>(&
I))
4832 ExpectedNumOperands = 1;
4834 ExpectedNumOperands = IBI->getNumDestinations();
4835 else if (isa<SelectInst>(&
I))
4836 ExpectedNumOperands = 2;
4837 else if (
CallBrInst *CI = dyn_cast<CallBrInst>(&
I))
4840 CheckFailed(
"!prof branch_weights are not allowed for this instruction",
4843 Check(NumBranchWeights == ExpectedNumOperands,
"Wrong number of operands",
4849 Check(MDO,
"second operand should not be null", MD);
4850 Check(mdconst::dyn_extract<ConstantInt>(MDO),
4851 "!prof brunch_weights operand is not a const int");
4857 assert(
I.hasMetadata(LLVMContext::MD_DIAssignID));
4858 bool ExpectedInstTy =
4859 isa<AllocaInst>(
I) || isa<StoreInst>(
I) || isa<MemIntrinsic>(
I);
4860 CheckDI(ExpectedInstTy,
"!DIAssignID attached to unexpected instruction kind",
4867 "!DIAssignID should only be used by llvm.dbg.assign intrinsics",
4870 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(
User))
4871 CheckDI(DAI->getFunction() ==
I.getFunction(),
4872 "dbg.assign not in same function as inst", DAI, &
I);
4876 cast<DIAssignID>(MD)->getAllDbgVariableRecordUsers()) {
4878 "!DIAssignID should only be used by Assign DVRs.", MD, DVR);
4879 CheckDI(DVR->getFunction() ==
I.getFunction(),
4880 "DVRAssign not in same function as inst", DVR, &
I);
4886 "!mmra metadata attached to unexpected instruction kind",
I, MD);
4896 Check(isa<MDTuple>(MD),
"!mmra expected to be a metadata tuple",
I, MD);
4899 "!mmra metadata tuple operand is not an MMRA tag",
I, MDOp.get());
4902void Verifier::visitCallStackMetadata(
MDNode *MD) {
4906 "call stack metadata should have at least 1 operand", MD);
4909 Check(mdconst::dyn_extract_or_null<ConstantInt>(
Op),
4910 "call stack metadata operand should be constant integer",
Op);
4914 Check(isa<CallBase>(
I),
"!memprof metadata should only exist on calls", &
I);
4916 "!memprof annotations should have at least 1 metadata operand "
4921 for (
auto &MIBOp : MD->
operands()) {
4922 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
4927 "Each !memprof MemInfoBlock should have at least 2 operands", MIB);
4931 "!memprof MemInfoBlock first operand should not be null", MIB);
4933 "!memprof MemInfoBlock first operand should be an MDNode", MIB);
4935 visitCallStackMetadata(StackMD);
4939 [](
const MDOperand &
Op) { return isa<MDString>(Op); }),
4940 "Not all !memprof MemInfoBlock operands 1 to N are MDString", MIB);
4945 Check(isa<CallBase>(
I),
"!callsite metadata should only exist on calls", &
I);
4948 visitCallStackMetadata(MD);
4951void Verifier::visitAnnotationMetadata(
MDNode *Annotation) {
4952 Check(isa<MDTuple>(Annotation),
"annotation must be a tuple");
4954 "annotation must have at least one operand");
4956 bool TupleOfStrings =
4957 isa<MDTuple>(
Op.get()) &&
4958 all_of(cast<MDTuple>(
Op)->operands(), [](
auto &Annotation) {
4961 Check(isa<MDString>(
Op.get()) || TupleOfStrings,
4962 "operands must be a string or a tuple of strings");
4966void Verifier::visitAliasScopeMetadata(
const MDNode *MD) {
4968 Check(NumOps >= 2 && NumOps <= 3,
"scope must have two or three operands",
4971 "first scope operand must be self-referential or string", MD);
4974 "third scope operand must be string (if used)", MD);
4977 Check(
Domain !=
nullptr,
"second scope operand must be MDNode", MD);
4979 unsigned NumDomainOps =
Domain->getNumOperands();
4980 Check(NumDomainOps >= 1 && NumDomainOps <= 2,
4981 "domain must have one or two operands",
Domain);
4983 isa<MDString>(
Domain->getOperand(0)),
4984 "first domain operand must be self-referential or string",
Domain);
4985 if (NumDomainOps == 2)
4987 "second domain operand must be string (if used)",
Domain);
4990void Verifier::visitAliasScopeListMetadata(
const MDNode *MD) {
4992 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
4993 Check(OpMD !=
nullptr,
"scope list must consist of MDNodes", MD);
4994 visitAliasScopeMetadata(OpMD);
4998void Verifier::visitAccessGroupMetadata(
const MDNode *MD) {
4999 auto IsValidAccessScope = [](
const MDNode *MD) {
5004 if (IsValidAccessScope(MD))
5009 const MDNode *OpMD = dyn_cast<MDNode>(
Op);
5010 Check(OpMD !=
nullptr,
"Access scope list must consist of MDNodes", MD);
5011 Check(IsValidAccessScope(OpMD),
5012 "Access scope list contains invalid access scope", MD);
5020 Check(BB,
"Instruction not embedded in basic block!", &
I);
5022 if (!isa<PHINode>(
I)) {
5023 for (
User *U :
I.users()) {
5025 "Only PHI nodes may reference their own value!", &
I);
5030 Check(!
I.getType()->isVoidTy() || !
I.hasName(),
5031 "Instruction has a name, but provides a void value!", &
I);
5035 Check(
I.getType()->isVoidTy() ||
I.getType()->isFirstClassType(),
5036 "Instruction returns a non-scalar type!", &
I);
5040 Check(!
I.getType()->isMetadataTy() || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5041 "Invalid use of metadata!", &
I);
5046 for (
Use &U :
I.uses()) {
5047 if (
Instruction *Used = dyn_cast<Instruction>(
U.getUser()))
5049 "Instruction referencing"
5050 " instruction not embedded in a basic block!",
5053 CheckFailed(
"Use of instruction is not an instruction!", U);
5060 const CallBase *CBI = dyn_cast<CallBase>(&
I);
5062 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
5063 Check(
I.getOperand(i) !=
nullptr,
"Instruction has null operand!", &
I);
5067 if (!
I.getOperand(i)->getType()->isFirstClassType()) {
5068 Check(
false,
"Instruction operands must be first-class values!", &
I);
5071 if (
Function *
F = dyn_cast<Function>(
I.getOperand(i))) {
5076 return CBI && CBI->isOperandBundleOfType(
5084 Check((!
F->isIntrinsic() ||
5085 (CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i)) ||
5086 IsAttachedCallOperand(
F, CBI, i)),
5087 "Cannot take the address of an intrinsic!", &
I);
5088 Check(!
F->isIntrinsic() || isa<CallInst>(
I) ||
5089 F->getIntrinsicID() == Intrinsic::donothing ||
5090 F->getIntrinsicID() == Intrinsic::seh_try_begin ||
5091 F->getIntrinsicID() == Intrinsic::seh_try_end ||
5092 F->getIntrinsicID() == Intrinsic::seh_scope_begin ||
5093 F->getIntrinsicID() == Intrinsic::seh_scope_end ||
5094 F->getIntrinsicID() == Intrinsic::coro_resume ||
5095 F->getIntrinsicID() == Intrinsic::coro_destroy ||
5096 F->getIntrinsicID() == Intrinsic::coro_await_suspend_void ||
5097 F->getIntrinsicID() == Intrinsic::coro_await_suspend_bool ||
5098 F->getIntrinsicID() == Intrinsic::coro_await_suspend_handle ||
5099 F->getIntrinsicID() ==
5100 Intrinsic::experimental_patchpoint_void ||
5101 F->getIntrinsicID() == Intrinsic::experimental_patchpoint ||
5102 F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint ||
5103 F->getIntrinsicID() == Intrinsic::wasm_rethrow ||
5104 IsAttachedCallOperand(
F, CBI, i),
5105 "Cannot invoke an intrinsic other than donothing, patchpoint, "
5106 "statepoint, coro_resume, coro_destroy or clang.arc.attachedcall",
5108 Check(
F->getParent() == &M,
"Referencing function in another module!", &
I,
5109 &M,
F,
F->getParent());
5110 }
else if (
BasicBlock *OpBB = dyn_cast<BasicBlock>(
I.getOperand(i))) {
5112 "Referring to a basic block in another function!", &
I);
5113 }
else if (
Argument *OpArg = dyn_cast<Argument>(
I.getOperand(i))) {
5115 "Referring to an argument in another function!", &
I);
5116 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(
I.getOperand(i))) {
5117 Check(GV->
getParent() == &M,
"Referencing global in another module!", &
I,
5119 }
else if (
Instruction *OpInst = dyn_cast<Instruction>(
I.getOperand(i))) {
5121 "Referring to an instruction in another function!", &
I);
5122 verifyDominatesUse(
I, i);
5123 }
else if (isa<InlineAsm>(
I.getOperand(i))) {
5124 Check(CBI && &CBI->getCalledOperandUse() == &
I.getOperandUse(i),
5125 "Cannot take the address of an inline asm!", &
I);
5126 }
else if (
auto *CPA = dyn_cast<ConstantPtrAuth>(
I.getOperand(i))) {
5127 visitConstantExprsRecursively(CPA);
5128 }
else if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(
I.getOperand(i))) {
5129 if (
CE->getType()->isPtrOrPtrVectorTy()) {
5132 visitConstantExprsRecursively(CE);
5137 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_fpmath)) {
5138 Check(
I.getType()->isFPOrFPVectorTy(),
5139 "fpmath requires a floating point result!", &
I);
5142 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
5143 const APFloat &Accuracy = CFP0->getValueAPF();
5145 "fpmath accuracy must have float type", &
I);
5147 "fpmath accuracy not a positive number!", &
I);
5149 Check(
false,
"invalid fpmath accuracy!", &
I);
5153 if (
MDNode *
Range =
I.getMetadata(LLVMContext::MD_range)) {
5154 Check(isa<LoadInst>(
I) || isa<CallInst>(
I) || isa<InvokeInst>(
I),
5155 "Ranges are only for loads, calls and invokes!", &
I);
5156 visitRangeMetadata(
I,
Range,
I.getType());
5159 if (
I.hasMetadata(LLVMContext::MD_invariant_group)) {
5160 Check(isa<LoadInst>(
I) || isa<StoreInst>(
I),
5161 "invariant.group metadata is only for loads and stores", &
I);
5164 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_nonnull)) {
5165 Check(
I.getType()->isPointerTy(),
"nonnull applies only to pointer types",
5168 "nonnull applies only to load instructions, use attributes"
5169 " for calls or invokes",
5174 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable))
5175 visitDereferenceableMetadata(
I, MD);
5177 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_dereferenceable_or_null))
5178 visitDereferenceableMetadata(
I, MD);
5180 if (
MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa))
5183 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_noalias))
5184 visitAliasScopeListMetadata(MD);
5185 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_alias_scope))
5186 visitAliasScopeListMetadata(MD);
5188 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_access_group))
5189 visitAccessGroupMetadata(MD);
5191 if (
MDNode *AlignMD =
I.getMetadata(LLVMContext::MD_align)) {
5192 Check(
I.getType()->isPointerTy(),
"align applies only to pointer types",
5195 "align applies only to load instructions, "
5196 "use attributes for calls or invokes",
5198 Check(AlignMD->getNumOperands() == 1,
"align takes one operand!", &
I);
5199 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(AlignMD->getOperand(0));
5201 "align metadata value must be an i64!", &
I);
5206 "alignment is larger that implementation defined limit", &
I);
5209 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_prof))
5210 visitProfMetadata(
I, MD);
5212 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_memprof))
5213 visitMemProfMetadata(
I, MD);
5215 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_callsite))
5216 visitCallsiteMetadata(
I, MD);
5218 if (
MDNode *MD =
I.getMetadata(LLVMContext::MD_DIAssignID))
5219 visitDIAssignIDMetadata(
I, MD);
5221 if (
MDNode *MMRA =
I.getMetadata(LLVMContext::MD_mmra))
5222 visitMMRAMetadata(
I, MMRA);
5224 if (
MDNode *Annotation =
I.getMetadata(LLVMContext::MD_annotation))
5225 visitAnnotationMetadata(Annotation);
5227 if (
MDNode *
N =
I.getDebugLoc().getAsMDNode()) {
5228 CheckDI(isa<DILocation>(
N),
"invalid !dbg metadata attachment", &
I,
N);
5229 visitMDNode(*
N, AreDebugLocsAllowed::Yes);
5232 if (
auto *DII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
5233 verifyFragmentExpression(*DII);
5234 verifyNotEntryValue(*DII);
5238 I.getAllMetadata(MDs);
5239 for (
auto Attachment : MDs) {
5240 unsigned Kind = Attachment.first;
5242 (
Kind == LLVMContext::MD_dbg ||
Kind == LLVMContext::MD_loop)
5243 ? AreDebugLocsAllowed::Yes
5244 : AreDebugLocsAllowed::No;
5245 visitMDNode(*Attachment.second, AllowLocs);
5254 Check(
IF->isDeclaration(),
"Intrinsic functions should never be defined!",
5260 bool IsVarArg = IFTy->isVarArg();
5271 "Intrinsic has incorrect return type!", IF);
5273 "Intrinsic has incorrect argument type!", IF);
5278 "Intrinsic was not defined with variable arguments!", IF);
5281 "Callsite was not defined with variable arguments!", IF);
5290 const std::string ExpectedName =
5292 Check(ExpectedName ==
IF->getName(),
5293 "Intrinsic name not mangled correctly for type arguments! "
5301 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
5302 visitMetadataAsValue(*MD,
Call.getCaller());
5303 if (
auto *Const = dyn_cast<Constant>(V))
5305 "const x86_amx is not allowed in argument!");
5311 case Intrinsic::assume: {
5312 for (
auto &Elem :
Call.bundle_op_infos()) {
5313 unsigned ArgCount = Elem.End - Elem.Begin;
5316 if (Elem.Tag->getKey() ==
"separate_storage") {
5317 Check(ArgCount == 2,
5318 "separate_storage assumptions should have 2 arguments", Call);
5319 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy() &&
5320 Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
5321 "arguments to separate_storage assumptions should be pointers",
5325 Check(Elem.Tag->getKey() ==
"ignore" ||
5327 "tags must be valid attribute names", Call);
5330 if (Kind == Attribute::Alignment) {
5331 Check(ArgCount <= 3 && ArgCount >= 2,
5332 "alignment assumptions should have 2 or 3 arguments", Call);
5333 Check(
Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5334 "first argument should be a pointer", Call);
5335 Check(
Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5336 "second argument should be an integer", Call);
5338 Check(
Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
5339 "third argument should be an integer if present", Call);
5342 Check(ArgCount <= 2,
"too many arguments", Call);
5346 Check(ArgCount == 2,
"this attribute should have 2 arguments", Call);
5347 Check(isa<ConstantInt>(
Call.getOperand(Elem.Begin + 1)),
5348 "the second argument should be a constant integral value", Call);
5350 Check((ArgCount) == 1,
"this attribute should have one argument", Call);
5352 Check((ArgCount) == 0,
"this attribute has no argument", Call);
5357 case Intrinsic::ucmp:
5358 case Intrinsic::scmp: {
5359 Type *SrcTy =
Call.getOperand(0)->getType();
5363 "result type must be at least 2 bits wide", Call);
5365 bool IsDestTypeVector = DestTy->
isVectorTy();
5367 "ucmp/scmp argument and result types must both be either vector or "
5370 if (IsDestTypeVector) {
5371 auto SrcVecLen = cast<VectorType>(SrcTy)->getElementCount();
5372 auto DestVecLen = cast<VectorType>(DestTy)->getElementCount();
5373 Check(SrcVecLen == DestVecLen,
5374 "return type and arguments must have the same number of "
5380 case Intrinsic::coro_id: {
5381 auto *InfoArg =
Call.getArgOperand(3)->stripPointerCasts();
5382 if (isa<ConstantPointerNull>(InfoArg))
5384 auto *GV = dyn_cast<GlobalVariable>(InfoArg);
5386 "info argument of llvm.coro.id must refer to an initialized "
5389 Check(isa<ConstantStruct>(
Init) || isa<ConstantArray>(
Init),
5390 "info argument of llvm.coro.id must refer to either a struct or "
5394 case Intrinsic::is_fpclass: {
5397 "unsupported bits for llvm.is.fpclass test mask");
5400 case Intrinsic::fptrunc_round: {
5403 auto *MAV = dyn_cast<MetadataAsValue>(
Call.getOperand(1));
5405 MD = MAV->getMetadata();
5407 Check(MD !=
nullptr,
"missing rounding mode argument", Call);
5409 Check(isa<MDString>(MD),
5410 (
"invalid value for llvm.fptrunc.round metadata operand"
5411 " (the operand should be a string)"),
5414 std::optional<RoundingMode> RoundMode =
5417 "unsupported rounding mode argument", Call);
5420#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID:
5421#include "llvm/IR/VPIntrinsics.def"
5422#undef BEGIN_REGISTER_VP_INTRINSIC
5423 visitVPIntrinsic(cast<VPIntrinsic>(Call));
5425#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \
5426 case Intrinsic::INTRINSIC:
5427#include "llvm/IR/ConstrainedOps.def"
5429 visitConstrainedFPIntrinsic(cast<ConstrainedFPIntrinsic>(Call));
5431 case Intrinsic::dbg_declare:
5432 Check(isa<MetadataAsValue>(
Call.getArgOperand(0)),
5433 "invalid llvm.dbg.declare intrinsic call 1", Call);
5434 visitDbgIntrinsic(
"declare", cast<DbgVariableIntrinsic>(Call));
5436 case Intrinsic::dbg_value:
5437 visitDbgIntrinsic(
"value", cast<DbgVariableIntrinsic>(Call));
5439 case Intrinsic::dbg_assign:
5440 visitDbgIntrinsic(
"assign", cast<DbgVariableIntrinsic>(Call));
5442 case Intrinsic::dbg_label:
5443 visitDbgLabelIntrinsic(
"label", cast<DbgLabelInst>(Call));
5445 case Intrinsic::memcpy:
5446 case Intrinsic::memcpy_inline:
5447 case Intrinsic::memmove:
5448 case Intrinsic::memset:
5449 case Intrinsic::memset_inline: {
5452 case Intrinsic::memcpy_element_unordered_atomic:
5453 case Intrinsic::memmove_element_unordered_atomic:
5454 case Intrinsic::memset_element_unordered_atomic: {
5455 const auto *AMI = cast<AtomicMemIntrinsic>(&Call);
5458 cast<ConstantInt>(AMI->getRawElementSizeInBytes());
5461 "element size of the element-wise atomic memory intrinsic "
5462 "must be a power of 2",
5465 auto IsValidAlignment = [&](
MaybeAlign Alignment) {
5466 return Alignment && ElementSizeVal.
ule(Alignment->value());
5468 Check(IsValidAlignment(AMI->getDestAlign()),
5469 "incorrect alignment of the destination argument", Call);
5470 if (
const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
5471 Check(IsValidAlignment(AMT->getSourceAlign()),
5472 "incorrect alignment of the source argument", Call);
5476 case Intrinsic::call_preallocated_setup: {
5477 auto *NumArgs = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5478 Check(NumArgs !=
nullptr,
5479 "llvm.call.preallocated.setup argument must be a constant");
5480 bool FoundCall =
false;
5482 auto *UseCall = dyn_cast<CallBase>(U);
5483 Check(UseCall !=
nullptr,
5484 "Uses of llvm.call.preallocated.setup must be calls");
5485 const Function *Fn = UseCall->getCalledFunction();
5486 if (Fn && Fn->
getIntrinsicID() == Intrinsic::call_preallocated_arg) {
5487 auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5488 Check(AllocArgIndex !=
nullptr,
5489 "llvm.call.preallocated.alloc arg index must be a constant");
5490 auto AllocArgIndexInt = AllocArgIndex->getValue();
5491 Check(AllocArgIndexInt.sge(0) &&
5492 AllocArgIndexInt.slt(NumArgs->getValue()),
5493 "llvm.call.preallocated.alloc arg index must be between 0 and "
5495 "llvm.call.preallocated.setup's argument count");
5497 Intrinsic::call_preallocated_teardown) {
5500 Check(!FoundCall,
"Can have at most one call corresponding to a "
5501 "llvm.call.preallocated.setup");
5503 size_t NumPreallocatedArgs = 0;
5504 for (
unsigned i = 0; i < UseCall->arg_size(); i++) {
5505 if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
5506 ++NumPreallocatedArgs;
5509 Check(NumPreallocatedArgs != 0,
5510 "cannot use preallocated intrinsics on a call without "
5511 "preallocated arguments");
5512 Check(NumArgs->equalsInt(NumPreallocatedArgs),
5513 "llvm.call.preallocated.setup arg size must be equal to number "
5514 "of preallocated arguments "
5524 auto PreallocatedBundle =
5526 Check(PreallocatedBundle,
5527 "Use of llvm.call.preallocated.setup outside intrinsics "
5528 "must be in \"preallocated\" operand bundle");
5529 Check(PreallocatedBundle->Inputs.front().get() == &Call,
5530 "preallocated bundle must have token from corresponding "
5531 "llvm.call.preallocated.setup");
5536 case Intrinsic::call_preallocated_arg: {
5537 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5538 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5539 Intrinsic::call_preallocated_setup,
5540 "llvm.call.preallocated.arg token argument must be a "
5541 "llvm.call.preallocated.setup");
5542 Check(
Call.hasFnAttr(Attribute::Preallocated),
5543 "llvm.call.preallocated.arg must be called with a \"preallocated\" "
5544 "call site attribute");
5547 case Intrinsic::call_preallocated_teardown: {
5548 auto *Token = dyn_cast<CallBase>(
Call.getArgOperand(0));
5549 Check(Token && Token->getCalledFunction()->getIntrinsicID() ==
5550 Intrinsic::call_preallocated_setup,
5551 "llvm.call.preallocated.teardown token argument must be a "
5552 "llvm.call.preallocated.setup");
5555 case Intrinsic::gcroot:
5556 case Intrinsic::gcwrite:
5557 case Intrinsic::gcread:
5558 if (
ID == Intrinsic::gcroot) {
5560 dyn_cast<AllocaInst>(
Call.getArgOperand(0)->stripPointerCasts());
5561 Check(AI,
"llvm.gcroot parameter #1 must be an alloca.", Call);
5562 Check(isa<Constant>(
Call.getArgOperand(1)),
5563 "llvm.gcroot parameter #2 must be a constant.", Call);
5565 Check(!isa<ConstantPointerNull>(
Call.getArgOperand(1)),
5566 "llvm.gcroot parameter #1 must either be a pointer alloca, "
5567 "or argument #2 must be a non-null constant.",
5572 Check(
Call.getParent()->getParent()->hasGC(),
5573 "Enclosing function does not use GC.", Call);
5575 case Intrinsic::init_trampoline:
5576 Check(isa<Function>(
Call.getArgOperand(1)->stripPointerCasts()),
5577 "llvm.init_trampoline parameter #2 must resolve to a function.",
5580 case Intrinsic::prefetch:
5581 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
5582 "rw argument to llvm.prefetch must be 0-1", Call);
5583 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
5584 "locality argument to llvm.prefetch must be 0-3", Call);
5585 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
5586 "cache type argument to llvm.prefetch must be 0-1", Call);
5588 case Intrinsic::stackprotector:
5589 Check(isa<AllocaInst>(
Call.getArgOperand(1)->stripPointerCasts()),
5590 "llvm.stackprotector parameter #2 must resolve to an alloca.", Call);
5592 case Intrinsic::localescape: {
5596 Check(!SawFrameEscape,
"multiple calls to llvm.localescape in one function",
5599 if (isa<ConstantPointerNull>(Arg))
5601 auto *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts());
5603 "llvm.localescape only accepts static allocas", Call);
5606 SawFrameEscape =
true;
5609 case Intrinsic::localrecover: {
5610 Value *FnArg =
Call.getArgOperand(0)->stripPointerCasts();
5611 Function *Fn = dyn_cast<Function>(FnArg);
5613 "llvm.localrecover first "
5614 "argument must be function defined in this module",
5616 auto *IdxArg = cast<ConstantInt>(
Call.getArgOperand(2));
5617 auto &
Entry = FrameEscapeInfo[Fn];
5619 std::max(
uint64_t(
Entry.second), IdxArg->getLimitedValue(~0U) + 1));
5623 case Intrinsic::experimental_gc_statepoint:
5624 if (
auto *CI = dyn_cast<CallInst>(&Call))
5625 Check(!CI->isInlineAsm(),
5626 "gc.statepoint support for inline assembly unimplemented", CI);
5627 Check(
Call.getParent()->getParent()->hasGC(),
5628 "Enclosing function does not use GC.", Call);
5630 verifyStatepoint(Call);
5632 case Intrinsic::experimental_gc_result: {
5633 Check(
Call.getParent()->getParent()->hasGC(),
5634 "Enclosing function does not use GC.", Call);
5636 auto *Statepoint =
Call.getArgOperand(0);
5637 if (isa<UndefValue>(Statepoint))
5641 const auto *StatepointCall = dyn_cast<CallBase>(Statepoint);
5643 StatepointCall ? StatepointCall->getCalledFunction() :
nullptr;
5646 Intrinsic::experimental_gc_statepoint,
5647 "gc.result operand #1 must be from a statepoint", Call,
5648 Call.getArgOperand(0));
5651 auto *TargetFuncType =
5652 cast<FunctionType>(StatepointCall->getParamElementType(2));
5653 Check(
Call.getType() == TargetFuncType->getReturnType(),
5654 "gc.result result type does not match wrapped callee", Call);
5657 case Intrinsic::experimental_gc_relocate: {
5658 Check(
Call.arg_size() == 3,
"wrong number of arguments", Call);
5660 Check(isa<PointerType>(
Call.getType()->getScalarType()),
5661 "gc.relocate must return a pointer or a vector of pointers", Call);
5667 dyn_cast<LandingPadInst>(
Call.getArgOperand(0))) {
5670 LandingPad->
getParent()->getUniquePredecessor();
5674 Check(InvokeBB,
"safepoints should have unique landingpads",
5675 LandingPad->getParent());
5679 "gc relocate should be linked to a statepoint", InvokeBB);
5684 auto *Token =
Call.getArgOperand(0);
5685 Check(isa<GCStatepointInst>(Token) || isa<UndefValue>(Token),
5686 "gc relocate is incorrectly tied to the statepoint", Call, Token);
5690 const Value &StatepointCall = *cast<GCRelocateInst>(Call).getStatepoint();
5695 "gc.relocate operand #2 must be integer offset", Call);
5698 Check(isa<ConstantInt>(Derived),
5699 "gc.relocate operand #3 must be integer offset", Call);
5701 const uint64_t BaseIndex = cast<ConstantInt>(
Base)->getZExtValue();
5702 const uint64_t DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
5705 if (isa<UndefValue>(StatepointCall))
5707 if (
auto Opt = cast<GCStatepointInst>(StatepointCall)
5709 Check(BaseIndex < Opt->Inputs.size(),
5710 "gc.relocate: statepoint base index out of bounds", Call);
5711 Check(DerivedIndex < Opt->Inputs.size(),
5712 "gc.relocate: statepoint derived index out of bounds", Call);
5720 auto *ResultType =
Call.getType();
5725 "gc.relocate: relocated value must be a pointer", Call);
5726 Check(DerivedType->isPtrOrPtrVectorTy(),
5727 "gc.relocate: relocated value must be a pointer", Call);
5729 Check(ResultType->isVectorTy() == DerivedType->isVectorTy(),
5730 "gc.relocate: vector relocates to vector and pointer to pointer",
5733 ResultType->getPointerAddressSpace() ==
5734 DerivedType->getPointerAddressSpace(),
5735 "gc.relocate: relocating a pointer shouldn't change its address space",
5739 Check(GC,
"gc.relocate: calling function must have GCStrategy",
5740 Call.getFunction());
5742 auto isGCPtr = [&
GC](
Type *PTy) {
5743 return GC->isGCManagedPointer(PTy->getScalarType()).value_or(
true);
5745 Check(isGCPtr(ResultType),
"gc.relocate: must return gc pointer", Call);
5747 "gc.relocate: relocated value must be a gc pointer", Call);
5748 Check(isGCPtr(DerivedType),
5749 "gc.relocate: relocated value must be a gc pointer", Call);
5753 case Intrinsic::experimental_patchpoint: {
5755 Check(
Call.getType()->isSingleValueType(),
5756 "patchpoint: invalid return type used with anyregcc", Call);
5760 case Intrinsic::eh_exceptioncode:
5761 case Intrinsic::eh_exceptionpointer: {
5762 Check(isa<CatchPadInst>(
Call.getArgOperand(0)),
5763 "eh.exceptionpointer argument must be a catchpad", Call);
5766 case Intrinsic::get_active_lane_mask: {
5768 "get_active_lane_mask: must return a "
5771 auto *ElemTy =
Call.getType()->getScalarType();
5772 Check(ElemTy->isIntegerTy(1),
5773 "get_active_lane_mask: element type is not "
5778 case Intrinsic::experimental_get_vector_length: {
5781 "get_vector_length: VF must be positive", Call);
5784 case Intrinsic::masked_load: {
5785 Check(
Call.getType()->isVectorTy(),
"masked_load: must return a vector",
5790 Value *PassThru =
Call.getArgOperand(3);
5791 Check(
Mask->getType()->isVectorTy(),
"masked_load: mask must be vector",
5794 "masked_load: alignment must be a power of 2", Call);
5796 "masked_load: pass through and return type must match", Call);
5797 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5798 cast<VectorType>(
Call.getType())->getElementCount(),
5799 "masked_load: vector mask must be same length as return", Call);
5802 case Intrinsic::masked_store: {
5806 Check(
Mask->getType()->isVectorTy(),
"masked_store: mask must be vector",
5809 "masked_store: alignment must be a power of 2", Call);
5810 Check(cast<VectorType>(
Mask->getType())->getElementCount() ==
5811 cast<VectorType>(Val->
getType())->getElementCount(),
5812 "masked_store: vector mask must be same length as value", Call);
5816 case Intrinsic::masked_gather: {
5817 const APInt &Alignment =
5820 "masked_gather: alignment must be 0 or a power of 2", Call);
5823 case Intrinsic::masked_scatter: {
5824 const APInt &Alignment =
5825 cast<ConstantInt>(
Call.getArgOperand(2))->getValue();
5827 "masked_scatter: alignment must be 0 or a power of 2", Call);
5831 case Intrinsic::experimental_guard: {
5832 Check(isa<CallInst>(Call),
"experimental_guard cannot be invoked", Call);
5834 "experimental_guard must have exactly one "
5835 "\"deopt\" operand bundle");
5839 case Intrinsic::experimental_deoptimize: {
5840 Check(isa<CallInst>(Call),
"experimental_deoptimize cannot be invoked",
5843 "experimental_deoptimize must have exactly one "
5844 "\"deopt\" operand bundle");
5845 Check(
Call.getType() ==
Call.getFunction()->getReturnType(),
5846 "experimental_deoptimize return type must match caller return type");
5848 if (isa<CallInst>(Call)) {
5849 auto *RI = dyn_cast<ReturnInst>(
Call.getNextNode());
5851 "calls to experimental_deoptimize must be followed by a return");
5853 if (!
Call.getType()->isVoidTy() && RI)
5854 Check(RI->getReturnValue() == &Call,
5855 "calls to experimental_deoptimize must be followed by a return "
5856 "of the value computed by experimental_deoptimize");
5861 case Intrinsic::vastart: {
5863 "va_start called in a non-varargs function");
5866 case Intrinsic::vector_reduce_and:
5867 case Intrinsic::vector_reduce_or:
5868 case Intrinsic::vector_reduce_xor:
5869 case Intrinsic::vector_reduce_add:
5870 case Intrinsic::vector_reduce_mul:
5871 case Intrinsic::vector_reduce_smax:
5872 case Intrinsic::vector_reduce_smin:
5873 case Intrinsic::vector_reduce_umax:
5874 case Intrinsic::vector_reduce_umin: {
5875 Type *ArgTy =
Call.getArgOperand(0)->getType();
5877 "Intrinsic has incorrect argument type!");
5880 case Intrinsic::vector_reduce_fmax:
5881 case Intrinsic::vector_reduce_fmin: {
5882 Type *ArgTy =
Call.getArgOperand(0)->getType();
5884 "Intrinsic has incorrect argument type!");
5887 case Intrinsic::vector_reduce_fadd:
5888 case Intrinsic::vector_reduce_fmul: {
5891 Type *ArgTy =
Call.getArgOperand(1)->getType();
5893 "Intrinsic has incorrect argument type!");
5896 case Intrinsic::smul_fix:
5897 case Intrinsic::smul_fix_sat:
5898 case Intrinsic::umul_fix:
5899 case Intrinsic::umul_fix_sat:
5900 case Intrinsic::sdiv_fix:
5901 case Intrinsic::sdiv_fix_sat:
5902 case Intrinsic::udiv_fix:
5903 case Intrinsic::udiv_fix_sat: {
5907 "first operand of [us][mul|div]_fix[_sat] must be an int type or "
5910 "second operand of [us][mul|div]_fix[_sat] must be an int type or "
5913 auto *Op3 = cast<ConstantInt>(
Call.getArgOperand(2));
5914 Check(Op3->getType()->isIntegerTy(),
5915 "third operand of [us][mul|div]_fix[_sat] must be an int type");
5916 Check(Op3->getBitWidth() <= 32,
5917 "third operand of [us][mul|div]_fix[_sat] must fit within 32 bits");
5919 if (
ID == Intrinsic::smul_fix ||
ID == Intrinsic::smul_fix_sat ||
5920 ID == Intrinsic::sdiv_fix ||
ID == Intrinsic::sdiv_fix_sat) {
5922 "the scale of s[mul|div]_fix[_sat] must be less than the width of "
5926 "the scale of u[mul|div]_fix[_sat] must be less than or equal "
5927 "to the width of the operands");
5931 case Intrinsic::lrint:
5932 case Intrinsic::llrint: {
5933 Type *ValTy =
Call.getArgOperand(0)->getType();
5937 "llvm.lrint, llvm.llrint: argument must be floating-point or vector "
5938 "of floating-points, and result must be integer or vector of integers",
5941 "llvm.lrint, llvm.llrint: argument and result disagree on vector use",
5944 Check(cast<VectorType>(ValTy)->getElementCount() ==
5945 cast<VectorType>(ResultTy)->getElementCount(),
5946 "llvm.lrint, llvm.llrint: argument must be same length as result",
5951 case Intrinsic::lround:
5952 case Intrinsic::llround: {
5953 Type *ValTy =
Call.getArgOperand(0)->getType();
5956 "Intrinsic does not support vectors", &Call);
5959 case Intrinsic::bswap: {
5962 Check(
Size % 16 == 0,
"bswap must be an even number of bytes", &Call);
5965 case Intrinsic::invariant_start: {
5966 ConstantInt *InvariantSize = dyn_cast<ConstantInt>(
Call.getArgOperand(0));
5967 Check(InvariantSize &&
5969 "invariant_start parameter must be -1, 0 or a positive number",
5973 case Intrinsic::matrix_multiply:
5974 case Intrinsic::matrix_transpose:
5975 case Intrinsic::matrix_column_major_load:
5976 case Intrinsic::matrix_column_major_store: {
5982 Type *Op0ElemTy =
nullptr;
5983 Type *Op1ElemTy =
nullptr;
5985 case Intrinsic::matrix_multiply: {
5986 NumRows = cast<ConstantInt>(
Call.getArgOperand(2));
5988 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
5989 Check(cast<FixedVectorType>(
Call.getArgOperand(0)->getType())
5990 ->getNumElements() ==
5992 "First argument of a matrix operation does not match specified "
5994 Check(cast<FixedVectorType>(
Call.getArgOperand(1)->getType())
5995 ->getNumElements() ==
5997 "Second argument of a matrix operation does not match specified "
6000 ResultTy = cast<VectorType>(
Call.getType());
6002 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6004 cast<VectorType>(
Call.getArgOperand(1)->getType())->getElementType();
6007 case Intrinsic::matrix_transpose:
6008 NumRows = cast<ConstantInt>(
Call.getArgOperand(1));
6009 NumColumns = cast<ConstantInt>(
Call.getArgOperand(2));
6010 ResultTy = cast<VectorType>(
Call.getType());
6012 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6014 case Intrinsic::matrix_column_major_load: {
6015 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(1));
6016 NumRows = cast<ConstantInt>(
Call.getArgOperand(3));
6017 NumColumns = cast<ConstantInt>(
Call.getArgOperand(4));
6018 ResultTy = cast<VectorType>(
Call.getType());
6021 case Intrinsic::matrix_column_major_store: {
6022 Stride = dyn_cast<ConstantInt>(
Call.getArgOperand(2));
6023 NumRows = cast<ConstantInt>(
Call.getArgOperand(4));
6024 NumColumns = cast<ConstantInt>(
Call.getArgOperand(5));
6025 ResultTy = cast<VectorType>(
Call.getArgOperand(0)->getType());
6027 cast<VectorType>(
Call.getArgOperand(0)->getType())->getElementType();
6034 Check(ResultTy->getElementType()->isIntegerTy() ||
6035 ResultTy->getElementType()->isFloatingPointTy(),
6036 "Result type must be an integer or floating-point type!", IF);
6039 Check(ResultTy->getElementType() == Op0ElemTy,
6040 "Vector element type mismatch of the result and first operand "
6045 Check(ResultTy->getElementType() == Op1ElemTy,
6046 "Vector element type mismatch of the result and second operand "
6050 Check(cast<FixedVectorType>(ResultTy)->getNumElements() ==
6052 "Result of a matrix operation does not fit in the returned vector!");
6056 "Stride must be greater or equal than the number of rows!", IF);
6060 case Intrinsic::vector_splice: {
6062 int64_t
Idx = cast<ConstantInt>(
Call.getArgOperand(2))->getSExtValue();
6063 int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue();
6064 if (
Call.getParent() &&
Call.getParent()->getParent()) {
6066 if (
Attrs.hasFnAttr(Attribute::VScaleRange))
6067 KnownMinNumElements *=
Attrs.getFnAttrs().getVScaleRangeMin();
6069 Check((
Idx < 0 && std::abs(
Idx) <= KnownMinNumElements) ||
6070 (
Idx >= 0 &&
Idx < KnownMinNumElements),
6071 "The splice index exceeds the range [-VL, VL-1] where VL is the "
6072 "known minimum number of elements in the vector. For scalable "
6073 "vectors the minimum number of elements is determined from "
6078 case Intrinsic::experimental_stepvector: {
6080 Check(VecTy && VecTy->getScalarType()->isIntegerTy() &&
6081 VecTy->getScalarSizeInBits() >= 8,
6082 "experimental_stepvector only supported for vectors of integers "
6083 "with a bitwidth of at least 8.",
6087 case Intrinsic::vector_insert: {
6091 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6098 Check(VecTy->getElementType() == SubVecTy->getElementType(),
6099 "vector_insert parameters must have the same element "
6103 "vector_insert index must be a constant multiple of "
6104 "the subvector's known minimum vector length.");
6112 "subvector operand of vector_insert would overrun the "
6113 "vector being inserted into.");
6117 case Intrinsic::vector_extract: {
6120 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
6128 Check(ResultTy->getElementType() == VecTy->getElementType(),
6129 "vector_extract result must have the same element "
6130 "type as the input vector.",
6133 "vector_extract index must be a constant multiple of "
6134 "the result type's known minimum vector length.");
6142 "vector_extract would overrun.");
6146 case Intrinsic::experimental_noalias_scope_decl: {
6147 NoAliasScopeDecls.
push_back(cast<IntrinsicInst>(&Call));
6150 case Intrinsic::preserve_array_access_index:
6151 case Intrinsic::preserve_struct_access_index:
6152 case Intrinsic::aarch64_ldaxr:
6153 case Intrinsic::aarch64_ldxr:
6154 case Intrinsic::arm_ldaex:
6155 case Intrinsic::arm_ldrex: {
6156 Type *ElemTy =
Call.getParamElementType(0);
6157 Check(ElemTy,
"Intrinsic requires elementtype attribute on first argument.",
6161 case Intrinsic::aarch64_stlxr:
6162 case Intrinsic::aarch64_stxr:
6163 case Intrinsic::arm_stlex:
6164 case Intrinsic::arm_strex: {
6165 Type *ElemTy =
Call.getAttributes().getParamElementType(1);
6167 "Intrinsic requires elementtype attribute on second argument.",
6171 case Intrinsic::aarch64_prefetch: {
6172 Check(cast<ConstantInt>(
Call.getArgOperand(1))->getZExtValue() < 2,
6173 "write argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6174 Check(cast<ConstantInt>(
Call.getArgOperand(2))->getZExtValue() < 4,
6175 "target argument to llvm.aarch64.prefetch must be 0-3", Call);
6176 Check(cast<ConstantInt>(
Call.getArgOperand(3))->getZExtValue() < 2,
6177 "stream argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6178 Check(cast<ConstantInt>(
Call.getArgOperand(4))->getZExtValue() < 2,
6179 "isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call);
6182 case Intrinsic::callbr_landingpad: {
6183 const auto *CBR = dyn_cast<CallBrInst>(
Call.getOperand(0));
6184 Check(CBR,
"intrinstic requires callbr operand", &Call);
6191 CheckFailed(
"Intrinsic in block must have 1 unique predecessor", &Call);
6195 CheckFailed(
"Intrinsic must have corresponding callbr in predecessor",
6201 return IndDest == LandingPadBB;
6203 "Intrinsic's corresponding callbr must have intrinsic's parent basic "
6204 "block in indirect destination list",
6207 Check(&
First == &Call,
"No other instructions may proceed intrinsic",
6211 case Intrinsic::amdgcn_cs_chain: {
6212 auto CallerCC =
Call.getCaller()->getCallingConv();
6219 CheckFailed(
"Intrinsic can only be used from functions with the "
6220 "amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6221 "calling conventions",
6226 Check(
Call.paramHasAttr(2, Attribute::InReg),
6227 "SGPR arguments must have the `inreg` attribute", &Call);
6228 Check(!
Call.paramHasAttr(3, Attribute::InReg),
6229 "VGPR arguments must not have the `inreg` attribute", &Call);
6232 case Intrinsic::amdgcn_set_inactive_chain_arg: {
6233 auto CallerCC =
Call.getCaller()->getCallingConv();
6239 CheckFailed(
"Intrinsic can only be used from functions with the "
6240 "amdgpu_cs_chain or amdgpu_cs_chain_preserve "
6241 "calling conventions",
6246 unsigned InactiveIdx = 1;
6247 Check(!
Call.paramHasAttr(InactiveIdx, Attribute::InReg),
6248 "Value for inactive lanes must not have the `inreg` attribute",
6250 Check(isa<Argument>(
Call.getArgOperand(InactiveIdx)),
6251 "Value for inactive lanes must be a function argument", &Call);
6252 Check(!cast<Argument>(
Call.getArgOperand(InactiveIdx))->hasInRegAttr(),
6253 "Value for inactive lanes must be a VGPR function argument", &Call);
6256 case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
6257 case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
6259 unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
6260 Check(RegCount % 8 == 0,
6261 "reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6262 Check((RegCount >= 24 && RegCount <= 256),
6263 "reg_count argument to nvvm.setmaxnreg must be within [24, 256]");
6266 case Intrinsic::experimental_convergence_entry:
6267 case Intrinsic::experimental_convergence_anchor:
6269 case Intrinsic::experimental_convergence_loop:
6271 case Intrinsic::ptrmask: {
6272 Type *Ty0 =
Call.getArgOperand(0)->getType();
6273 Type *Ty1 =
Call.getArgOperand(1)->getType();
6275 "llvm.ptrmask intrinsic first argument must be pointer or vector "
6280 "llvm.ptrmask intrinsic arguments must be both scalars or both vectors",
6283 Check(cast<VectorType>(Ty0)->getElementCount() ==
6284 cast<VectorType>(Ty1)->getElementCount(),
6285 "llvm.ptrmask intrinsic arguments must have the same number of "
6289 "llvm.ptrmask intrinsic second argument bitwidth must match "
6290 "pointer index type size of first argument",
6294 case Intrinsic::threadlocal_address: {
6295 const Value &Arg0 = *
Call.getArgOperand(0);
6296 Check(isa<GlobalValue>(Arg0),
6297 "llvm.threadlocal.address first argument must be a GlobalValue");
6298 Check(cast<GlobalValue>(Arg0).isThreadLocal(),
6299 "llvm.threadlocal.address operand isThreadLocal() must be true");
6307 if (
F->hasPersonalityFn() &&
6311 if (BlockEHFuncletColors.
empty())
6315 bool InEHFunclet =
false;
6320 if (dyn_cast_or_null<FuncletPadInst>(ColorFirstBB->getFirstNonPHI()))
6324 bool HasToken =
false;
6325 for (
unsigned I = 0, E =
Call.getNumOperandBundles();
I != E; ++
I)
6331 Check(HasToken,
"Missing funclet token on intrinsic call", &Call);
6344 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
6347 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
6351 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
6357 "invalid #dbg_label intrinsic variable", &DLR, DLR.
getRawLabel());
6361 if (!isa<DILocation>(
N))
6370 CheckDI(Loc,
"#dbg_label record requires a !dbg attachment", &DLR, BB,
F);
6374 if (!LabelSP || !LocSP)
6378 "mismatched subprogram between #dbg_label label and !dbg attachment",
6379 &DLR, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6380 Loc->getScope()->getSubprogram());
6390 "invalid #dbg record type", &DVR, DVR.
getType());
6396 CheckDI(MD && (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6397 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands())),
6398 "invalid #dbg record address/value", &DVR, MD);
6399 if (
auto *VAM = dyn_cast<ValueAsMetadata>(MD))
6400 visitValueAsMetadata(*VAM,
F);
6401 else if (
auto *AL = dyn_cast<DIArgList>(MD))
6402 visitDIArgList(*AL,
F);
6416 AreDebugLocsAllowed::No);
6423 isa<ValueAsMetadata>(RawAddr) ||
6424 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6426 if (
auto *VAM = dyn_cast<ValueAsMetadata>(RawAddr))
6427 visitValueAsMetadata(*VAM,
F);
6430 "invalid #dbg_assign address expression", &DVR,
6437 "inst not in same function as #dbg_assign",
I, &DVR);
6446 CheckDI(isa_and_nonnull<DILocation>(DLNode),
"invalid #dbg record DILocation",
6453 if (!VarSP || !LocSP)
6457 "mismatched subprogram between #dbg record variable and DILocation",
6459 Loc->getScope()->getSubprogram());
6464void Verifier::visitVPIntrinsic(
VPIntrinsic &VPI) {
6465 if (
auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6466 auto *
RetTy = cast<VectorType>(VPCast->getType());
6467 auto *ValTy = cast<VectorType>(VPCast->getOperand(0)->getType());
6468 Check(
RetTy->getElementCount() == ValTy->getElementCount(),
6469 "VP cast intrinsic first argument and result vector lengths must be "
6473 switch (VPCast->getIntrinsicID()) {
6476 case Intrinsic::vp_trunc:
6478 "llvm.vp.trunc intrinsic first argument and result element type "
6482 "llvm.vp.trunc intrinsic the bit size of first argument must be "
6483 "larger than the bit size of the return type",
6486 case Intrinsic::vp_zext:
6487 case Intrinsic::vp_sext:
6489 "llvm.vp.zext or llvm.vp.sext intrinsic first argument and result "
6490 "element type must be integer",
6493 "llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first "
6494 "argument must be smaller than the bit size of the return type",
6497 case Intrinsic::vp_fptoui:
6498 case Intrinsic::vp_fptosi:
6499 case Intrinsic::vp_lrint:
6500 case Intrinsic::vp_llrint:
6503 "llvm.vp.fptoui, llvm.vp.fptosi, llvm.vp.lrint or llvm.vp.llrint" "intrinsic first argument element "
6504 "type must be floating-point and result element type must be integer",
6507 case Intrinsic::vp_uitofp:
6508 case Intrinsic::vp_sitofp:
6511 "llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element "
6512 "type must be integer and result element type must be floating-point",
6515 case Intrinsic::vp_fptrunc:
6517 "llvm.vp.fptrunc intrinsic first argument and result element type "
6518 "must be floating-point",
6521 "llvm.vp.fptrunc intrinsic the bit size of first argument must be "
6522 "larger than the bit size of the return type",
6525 case Intrinsic::vp_fpext:
6527 "llvm.vp.fpext intrinsic first argument and result element type "
6528 "must be floating-point",
6531 "llvm.vp.fpext intrinsic the bit size of first argument must be "
6532 "smaller than the bit size of the return type",
6535 case Intrinsic::vp_ptrtoint:
6537 "llvm.vp.ptrtoint intrinsic first argument element type must be "
6538 "pointer and result element type must be integer",
6541 case Intrinsic::vp_inttoptr:
6543 "llvm.vp.inttoptr intrinsic first argument element type must be "
6544 "integer and result element type must be pointer",
6550 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6552 "invalid predicate for VP FP comparison intrinsic", &VPI);
6555 auto Pred = cast<VPCmpIntrinsic>(&VPI)->getPredicate();
6557 "invalid predicate for VP integer comparison intrinsic", &VPI);
6560 auto TestMask = cast<ConstantInt>(VPI.
getOperand(1));
6562 "unsupported bits for llvm.vp.is.fpclass test mask");
6568 bool HasRoundingMD =
6572 NumOperands += (1 + HasRoundingMD);
6575 if (isa<ConstrainedFPCmpIntrinsic>(FPI))
6578 "invalid arguments for constrained FP intrinsic", &FPI);
6581 case Intrinsic::experimental_constrained_lrint:
6582 case Intrinsic::experimental_constrained_llrint: {
6586 "Intrinsic does not support vectors", &FPI);
6590 case Intrinsic::experimental_constrained_lround:
6591 case Intrinsic::experimental_constrained_llround: {
6595 "Intrinsic does not support vectors", &FPI);
6599 case Intrinsic::experimental_constrained_fcmp:
6600 case Intrinsic::experimental_constrained_fcmps: {
6601 auto Pred = cast<ConstrainedFPCmpIntrinsic>(&FPI)->getPredicate();
6603 "invalid predicate for constrained FP comparison intrinsic", &FPI);
6607 case Intrinsic::experimental_constrained_fptosi:
6608 case Intrinsic::experimental_constrained_fptoui: {
6612 "Intrinsic first argument must be floating point", &FPI);
6613 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6614 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6619 "Intrinsic first argument and result disagree on vector use", &FPI);
6621 "Intrinsic result must be an integer", &FPI);
6622 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6623 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6624 "Intrinsic first argument and result vector lengths must be equal",
6630 case Intrinsic::experimental_constrained_sitofp:
6631 case Intrinsic::experimental_constrained_uitofp: {
6635 "Intrinsic first argument must be integer", &FPI);
6636 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6637 SrcEC = cast<VectorType>(OperandT)->getElementCount();
6642 "Intrinsic first argument and result disagree on vector use", &FPI);
6644 "Intrinsic result must be a floating point", &FPI);
6645 if (
auto *OperandT = dyn_cast<VectorType>(Operand->
getType())) {
6646 Check(SrcEC == cast<VectorType>(OperandT)->getElementCount(),
6647 "Intrinsic first argument and result vector lengths must be equal",
6653 case Intrinsic::experimental_constrained_fptrunc:
6654 case Intrinsic::experimental_constrained_fpext: {
6660 "Intrinsic first argument must be FP or FP vector", &FPI);
6662 "Intrinsic result must be FP or FP vector", &FPI);
6664 "Intrinsic first argument and result disagree on vector use", &FPI);
6666 Check(cast<VectorType>(OperandTy)->getElementCount() ==
6667 cast<VectorType>(ResultTy)->getElementCount(),
6668 "Intrinsic first argument and result vector lengths must be equal",
6671 if (FPI.
getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) {
6673 "Intrinsic first argument's type must be larger than result type",
6677 "Intrinsic first argument's type must be smaller than result type",
6693 "invalid exception behavior argument", &FPI);
6694 if (HasRoundingMD) {
6702 CheckDI(isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6703 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
6704 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
6706 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
6709 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
6712 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(&DII)) {
6713 CheckDI(isa<DIAssignID>(DAI->getRawAssignID()),
6714 "invalid llvm.dbg.assign intrinsic DIAssignID", &DII,
6715 DAI->getRawAssignID());
6716 const auto *RawAddr = DAI->getRawAddress();
6718 isa<ValueAsMetadata>(RawAddr) ||
6719 (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands()),
6720 "invalid llvm.dbg.assign intrinsic address", &DII,
6721 DAI->getRawAddress());
6722 CheckDI(isa<DIExpression>(DAI->getRawAddressExpression()),
6723 "invalid llvm.dbg.assign intrinsic address expression", &DII,
6724 DAI->getRawAddressExpression());
6727 CheckDI(DAI->getFunction() ==
I->getFunction(),
6728 "inst not in same function as dbg.assign",
I, DAI);
6733 if (!isa<DILocation>(
N))
6742 CheckDI(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
6747 if (!VarSP || !LocSP)
6751 "mismatched subprogram between llvm.dbg." + Kind +
6752 " variable and !dbg attachment",
6754 Loc->getScope()->getSubprogram());
6764 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DLI,
6769 if (!isa<DILocation>(
N))
6778 Check(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment", &DLI,
6783 if (!LabelSP || !LocSP)
6787 "mismatched subprogram between llvm.dbg." + Kind +
6788 " label and !dbg attachment",
6789 &DLI, BB,
F, Label,
Label->getScope()->getSubprogram(), Loc,
6790 Loc->getScope()->getSubprogram());
6795 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6798 if (!V || !E || !E->
isValid())
6812 if (
V->isArtificial())
6815 verifyFragmentExpression(*V, *Fragment, &
I);
6822 if (!V || !E || !E->
isValid())
6836 if (
V->isArtificial())
6839 verifyFragmentExpression(*V, *Fragment, &DVR);
6842template <
typename ValueOrMetadata>
6843void Verifier::verifyFragmentExpression(
const DIVariable &V,
6845 ValueOrMetadata *
Desc) {
6848 auto VarSize =
V.getSizeInBits();
6854 CheckDI(FragSize + FragOffset <= *VarSize,
6855 "fragment is larger than or outside of variable",
Desc, &V);
6856 CheckDI(FragSize != *VarSize,
"fragment covers entire variable",
Desc, &V);
6867 if (
I.getDebugLoc()->getInlinedAt())
6871 CheckDI(Var,
"dbg intrinsic without variable");
6873 unsigned ArgNo = Var->
getArg();
6879 if (DebugFnArgs.
size() < ArgNo)
6880 DebugFnArgs.
resize(ArgNo,
nullptr);
6882 auto *Prev = DebugFnArgs[ArgNo - 1];
6883 DebugFnArgs[ArgNo - 1] = Var;
6884 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &
I,
6899 CheckDI(Var,
"#dbg record without variable");
6901 unsigned ArgNo = Var->
getArg();
6907 if (DebugFnArgs.
size() < ArgNo)
6908 DebugFnArgs.
resize(ArgNo,
nullptr);
6910 auto *Prev = DebugFnArgs[ArgNo - 1];
6911 DebugFnArgs[ArgNo - 1] = Var;
6912 CheckDI(!Prev || (Prev == Var),
"conflicting debug info for argument", &DVR,
6917 DIExpression *E = dyn_cast_or_null<DIExpression>(
I.getRawExpression());
6923 if (isa<ValueAsMetadata>(
I.getRawLocation())) {
6924 Value *VarValue =
I.getVariableLocationOp(0);
6925 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6929 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6930 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6935 "Entry values are only allowed in MIR unless they target a "
6936 "swiftasync Argument",
6948 if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
6952 if (
auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
6953 ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync))
6958 "Entry values are only allowed in MIR unless they target a "
6959 "swiftasync Argument",
6963void Verifier::verifyCompileUnits() {
6967 if (
M.getContext().isODRUniquingDebugTypes())
6969 auto *CUs =
M.getNamedMetadata(
"llvm.dbg.cu");
6972 Listed.
insert(CUs->op_begin(), CUs->op_end());
6973 for (
const auto *
CU : CUVisited)
6978void Verifier::verifyDeoptimizeCallingConvs() {
6979 if (DeoptimizeDeclarations.
empty())
6983 for (
const auto *
F :
ArrayRef(DeoptimizeDeclarations).slice(1)) {
6984 Check(
First->getCallingConv() ==
F->getCallingConv(),
6985 "All llvm.experimental.deoptimize declarations must have the same "
6986 "calling convention",
6991void Verifier::verifyAttachedCallBundle(
const CallBase &Call,
6995 Check((FTy->getReturnType()->isPointerTy() ||
6996 (
Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())),
6997 "a call with operand bundle \"clang.arc.attachedcall\" must call a "
6998 "function returning a pointer or a non-returning function that has a "
7003 "operand bundle \"clang.arc.attachedcall\" requires one function as "
7007 auto *Fn = cast<Function>(BU.
Inputs.front());
7011 Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
7012 IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
7013 "invalid function argument", Call);
7016 Check((FnName ==
"objc_retainAutoreleasedReturnValue" ||
7017 FnName ==
"objc_unsafeClaimAutoreleasedReturnValue"),
7018 "invalid function argument", Call);
7022void Verifier::verifyNoAliasScopeDecl() {
7023 if (NoAliasScopeDecls.
empty())
7027 for (
auto *
II : NoAliasScopeDecls) {
7028 assert(
II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl &&
7029 "Not a llvm.experimental.noalias.scope.decl ?");
7030 const auto *ScopeListMV = dyn_cast<MetadataAsValue>(
7032 Check(ScopeListMV !=
nullptr,
7033 "llvm.experimental.noalias.scope.decl must have a MetadataAsValue "
7037 const auto *ScopeListMD = dyn_cast<MDNode>(ScopeListMV->getMetadata());
7038 Check(ScopeListMD !=
nullptr,
"!id.scope.list must point to an MDNode",
II);
7039 Check(ScopeListMD->getNumOperands() == 1,
7040 "!id.scope.list must point to a list with a single scope",
II);
7041 visitAliasScopeListMetadata(ScopeListMD);
7052 const auto *ScopeListMV = cast<MetadataAsValue>(
7054 return &cast<MDNode>(ScopeListMV->getMetadata())->getOperand(0);
7060 return GetScope(Lhs) < GetScope(Rhs);
7067 auto ItCurrent = NoAliasScopeDecls.begin();
7068 while (ItCurrent != NoAliasScopeDecls.end()) {
7069 auto CurScope = GetScope(*ItCurrent);
7070 auto ItNext = ItCurrent;
7073 }
while (ItNext != NoAliasScopeDecls.end() &&
7074 GetScope(*ItNext) == CurScope);
7079 if (ItNext - ItCurrent < 32)
7084 "llvm.experimental.noalias.scope.decl dominates another one "
7085 "with the same scope",
7103 return !V.verify(
F);
7107 bool *BrokenDebugInfo) {
7111 bool Broken =
false;
7113 Broken |= !V.verify(
F);
7115 Broken |= !V.verify();
7116 if (BrokenDebugInfo)
7117 *BrokenDebugInfo = V.hasBrokenDebugInfo();
7128 std::unique_ptr<Verifier> V;
7129 bool FatalErrors =
true;
7134 explicit VerifierLegacyPass(
bool FatalErrors)
7136 FatalErrors(FatalErrors) {
7140 bool doInitialization(
Module &M)
override {
7141 V = std::make_unique<Verifier>(
7147 if (!
V->verify(
F) && FatalErrors) {
7148 errs() <<
"in function " <<
F.getName() <<
'\n';
7154 bool doFinalization(
Module &M)
override {
7155 bool HasErrors =
false;
7157 if (
F.isDeclaration())
7158 HasErrors |= !
V->verify(
F);
7160 HasErrors |= !
V->verify();
7161 if (FatalErrors && (HasErrors ||
V->hasBrokenDebugInfo()))
7174template <
typename... Tys>
void TBAAVerifier::CheckFailed(Tys &&... Args) {
7179#define CheckTBAA(C, ...) \
7182 CheckFailed(__VA_ARGS__); \
7190TBAAVerifier::TBAABaseNodeSummary
7194 CheckFailed(
"Base nodes must have at least two operands", &
I, BaseNode);
7198 auto Itr = TBAABaseNodes.find(BaseNode);
7199 if (Itr != TBAABaseNodes.end())
7202 auto Result = verifyTBAABaseNodeImpl(
I, BaseNode, IsNewFormat);
7203 auto InsertResult = TBAABaseNodes.insert({BaseNode, Result});
7205 assert(InsertResult.second &&
"We just checked!");
7209TBAAVerifier::TBAABaseNodeSummary
7212 const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {
true, ~0
u};
7216 return isValidScalarTBAANode(BaseNode)
7217 ? TBAAVerifier::TBAABaseNodeSummary({
false, 0})
7223 CheckFailed(
"Access tag nodes must have the number of operands that is a "
7224 "multiple of 3!", BaseNode);
7229 CheckFailed(
"Struct tag nodes must have an odd number of operands!",
7237 auto *TypeSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7239 if (!TypeSizeNode) {
7240 CheckFailed(
"Type size nodes must be constants!", &
I, BaseNode);
7246 if (!IsNewFormat && !isa<MDString>(BaseNode->
getOperand(0))) {
7247 CheckFailed(
"Struct tag nodes have a string as their first operand",
7254 std::optional<APInt> PrevOffset;
7259 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7260 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7262 Idx += NumOpsPerField) {
7265 if (!isa<MDNode>(FieldTy)) {
7266 CheckFailed(
"Incorrect field entry in struct type node!", &
I, BaseNode);
7271 auto *OffsetEntryCI =
7272 mdconst::dyn_extract_or_null<ConstantInt>(FieldOffset);
7273 if (!OffsetEntryCI) {
7274 CheckFailed(
"Offset entries must be constants!", &
I, BaseNode);
7280 BitWidth = OffsetEntryCI->getBitWidth();
7282 if (OffsetEntryCI->getBitWidth() !=
BitWidth) {
7284 "Bitwidth between the offsets and struct type entries must match", &
I,
7296 !PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue());
7299 CheckFailed(
"Offsets must be increasing!", &
I, BaseNode);
7303 PrevOffset = OffsetEntryCI->getValue();
7306 auto *MemberSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7308 if (!MemberSizeNode) {
7309 CheckFailed(
"Member size entries must be constants!", &
I, BaseNode);
7316 return Failed ? InvalidNode
7317 : TBAAVerifier::TBAABaseNodeSummary(
false,
BitWidth);
7338 auto *Parent = dyn_cast_or_null<MDNode>(MD->
getOperand(1));
7339 return Parent && Visited.
insert(Parent).second &&
7343bool TBAAVerifier::isValidScalarTBAANode(
const MDNode *MD) {
7344 auto ResultIt = TBAAScalarNodes.find(MD);
7345 if (ResultIt != TBAAScalarNodes.end())
7346 return ResultIt->second;
7350 auto InsertResult = TBAAScalarNodes.insert({MD,
Result});
7352 assert(InsertResult.second &&
"Just checked!");
7371 return cast<MDNode>(BaseNode->
getOperand(1));
7373 unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1;
7374 unsigned NumOpsPerField = IsNewFormat ? 3 : 2;
7376 Idx += NumOpsPerField) {
7377 auto *OffsetEntryCI =
7378 mdconst::extract<ConstantInt>(BaseNode->
getOperand(
Idx + 1));
7379 if (OffsetEntryCI->getValue().ugt(
Offset)) {
7380 if (
Idx == FirstFieldOpNo) {
7381 CheckFailed(
"Could not find TBAA parent in struct type node", &
I,
7386 unsigned PrevIdx =
Idx - NumOpsPerField;
7387 auto *PrevOffsetEntryCI =
7388 mdconst::extract<ConstantInt>(BaseNode->
getOperand(PrevIdx + 1));
7389 Offset -= PrevOffsetEntryCI->getValue();
7390 return cast<MDNode>(BaseNode->
getOperand(PrevIdx));
7395 auto *LastOffsetEntryCI = mdconst::extract<ConstantInt>(
7397 Offset -= LastOffsetEntryCI->getValue();
7398 return cast<MDNode>(BaseNode->
getOperand(LastIdx));
7402 if (!
Type ||
Type->getNumOperands() < 3)
7407 return isa_and_nonnull<MDNode>(
Type->getOperand(0));
7414 CheckTBAA(isa<LoadInst>(
I) || isa<StoreInst>(
I) || isa<CallInst>(
I) ||
7415 isa<VAArgInst>(
I) || isa<AtomicRMWInst>(
I) ||
7416 isa<AtomicCmpXchgInst>(
I),
7417 "This instruction shall not have a TBAA access tag!", &
I);
7419 bool IsStructPathTBAA =
7423 "Old-style TBAA is no longer allowed, use struct-path TBAA instead",
7433 "Access tag metadata must have either 4 or 5 operands", &
I, MD);
7436 "Struct tag metadata must have either 3 or 4 operands", &
I, MD);
7441 auto *AccessSizeNode = mdconst::dyn_extract_or_null<ConstantInt>(
7443 CheckTBAA(AccessSizeNode,
"Access size field must be a constant", &
I, MD);
7447 unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3;
7449 auto *IsImmutableCI = mdconst::dyn_extract_or_null<ConstantInt>(
7452 "Immutability tag on struct tag metadata must be a constant", &
I,
7455 IsImmutableCI->isZero() || IsImmutableCI->isOne(),
7456 "Immutability part of the struct tag metadata must be either 0 or 1",
7461 "Malformed struct tag metadata: base and access-type "
7462 "should be non-null and point to Metadata nodes",
7463 &
I, MD, BaseNode, AccessType);
7466 CheckTBAA(isValidScalarTBAANode(AccessType),
7467 "Access type node must be a valid scalar type", &
I, MD,
7471 auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->
getOperand(2));
7472 CheckTBAA(OffsetCI,
"Offset must be constant integer", &
I, MD);
7475 bool SeenAccessTypeInPath =
false;
7480 BaseNode = getFieldNodeFromTBAABaseNode(
I, BaseNode,
Offset,
7482 if (!StructPath.
insert(BaseNode).second) {
7483 CheckFailed(
"Cycle detected in struct path", &
I, MD);
7488 unsigned BaseNodeBitWidth;
7489 std::tie(
Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(
I, BaseNode,
7497 SeenAccessTypeInPath |= BaseNode == AccessType;
7499 if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
7500 CheckTBAA(
Offset == 0,
"Offset not zero at the point of scalar access",
7504 (BaseNodeBitWidth == 0 &&
Offset == 0) ||
7505 (IsNewFormat && BaseNodeBitWidth == ~0u),
7506 "Access bit-width not the same as description bit-width", &
I, MD,
7507 BaseNodeBitWidth,
Offset.getBitWidth());
7509 if (IsNewFormat && SeenAccessTypeInPath)
7513 CheckTBAA(SeenAccessTypeInPath,
"Did not see access type in access path!", &
I,
7518char VerifierLegacyPass::ID = 0;
7519INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
7522 return new VerifierLegacyPass(FatalErrors);
7540 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
7548 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")
Analysis containing CSE Info
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.
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
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.
This file contains the declarations for profiling metadata utility functions.
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 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...
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.
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
A signed pointer, in the ptrauth sense.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
Constant * getPointer() const
The pointer that is signed in this ptrauth signed pointer.
ConstantInt * getKey() const
The Key ID, an i32 constant.
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
static bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
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
unsigned getNonMetadataArgCount() const
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
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
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
Records a position in IR for a source label (DILabel).
MDNode * getRawLabel() const
DILabel * getLabel() const
Base class for non-instruction debug metadata records that have positions within IR.
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
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LocationType getType() const
MDNode * getRawExpression() const
MDNode * getRawAddressExpression() const
DIExpression * getExpression() const
Metadata * getRawAssignID() const
Value * getVariableLocationOp(unsigned OpIdx) const
MDNode * getRawVariable() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAddress() const
@ End
Marks the end of the concrete types.
@ Any
To indicate all LocationTypes in searches.
DIExpression * getAddressExpression() 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 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.
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.
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.
const ParentTy * getParent() const
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class implements an extremely fast bulk output stream that can only output to a stream.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
@ 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
bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...
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.
bool canInstructionHaveMMRAs(const Instruction &I)
unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
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.
unsigned getNumBranchWeights(const MDNode &ProfileData)
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)
@ 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).