84 struct VerifierSupport {
92 : OS(OS), M(nullptr), Broken(
false) {}
98 if (isa<Instruction>(V)) {
139 template <
typename T1,
typename... Ts>
140 void WriteTs(
const T1 &V1,
const Ts &... Vs) {
145 template <
typename... Ts>
void WriteTs() {}
152 void CheckFailed(
const Twine &Message) {
153 OS << Message <<
'\n';
161 template <
typename T1,
typename... Ts>
162 void CheckFailed(
const Twine &Message,
const T1 &V1,
const Ts &... Vs) {
163 CheckFailed(Message);
168 class Verifier :
public InstVisitor<Verifier>, VerifierSupport {
197 : VerifierSupport(OS), Context(nullptr), SawFrameEscape(
false) {}
206 OS <<
"Function '" << F.
getName()
207 <<
"' does not contain an entry block!\n";
211 if (
I->empty() || !
I->back().isTerminator()) {
212 OS <<
"Basic Block in function '" << F.
getName()
213 <<
"' does not have terminator!\n";
214 I->printAsOperand(OS,
true);
225 DT.recalculate(const_cast<Function &>(F));
229 visit(const_cast<Function &>(F));
230 InstsInThisBlock.clear();
231 SawFrameEscape =
false;
243 visitGlobalValue(*
I);
246 if (
I->isDeclaration())
252 verifyFrameRecoverIndices();
256 visitGlobalVariable(*
I);
260 visitGlobalAlias(*
I);
265 visitNamedMDNode(*
I);
268 visitComdat(SMEC.getValue());
271 visitModuleIdents(M);
288 void visitMDNode(
const MDNode &MD);
291 void visitComdat(
const Comdat &
C);
292 void visitModuleIdents(
const Module &M);
293 void visitModuleFlags(
const Module &M);
294 void visitModuleFlag(
const MDNode *Op,
297 void visitFunction(
const Function &F);
302 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
303 #include "llvm/IR/Metadata.def"
304 void visitDIScope(
const DIScope &
N);
350 void visitPHINode(
PHINode &PN);
357 void visitVAArgInst(
VAArgInst &VAA) { visitInstruction(VAA); }
374 template <
class DbgIntrinsicTy>
385 void verifyMustTailCall(
CallInst &CI);
387 unsigned ArgNo, std::string &Suffix);
390 bool VerifyIntrinsicIsVarArg(
bool isVarArg,
392 bool VerifyAttributeCount(
AttributeSet Attrs,
unsigned Params);
393 void VerifyAttributeTypes(
AttributeSet Attrs,
unsigned Idx,
bool isFunction,
396 bool isReturnValue,
const Value *V);
399 void VerifyFunctionMetadata(
400 const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs);
402 void VerifyConstantExprBitcastType(
const ConstantExpr *CE);
404 void verifyFrameRecoverIndices();
407 void verifyTypeRefs();
408 template <
class MapTy>
410 const MapTy &TypeRefs);
416 #define Assert(C, ...) \
417 do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (0)
426 void Verifier::visitGlobalValue(
const GlobalValue &GV) {
429 "Global is external, but doesn't have external or weak linkage!", &GV);
432 "huge alignment values are unsupported", &GV);
434 "Only global variables can have appending linkage!", &GV);
439 "Only global arrays can have appending linkage!", GVar);
449 "Global variable initializer type does not match global "
457 "'common' global must have a zero initializer!", &GV);
460 Assert(!GV.
hasComdat(),
"'common' global may not be in a Comdat!", &GV);
464 "invalid linkage type for global declaration", &GV);
468 GV.
getName() ==
"llvm.global_dtors")) {
470 "invalid linkage for intrinsic global variable", &GV);
482 "wrong type for intrinsic global variable", &GV);
486 cast<PointerType>(ETy)->getElementType()->isIntegerTy(8),
487 "wrong type for intrinsic global variable", &GV);
493 GV.
getName() ==
"llvm.compiler.used")) {
495 "invalid linkage for intrinsic global variable", &GV);
497 if (
ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
499 Assert(PTy,
"wrong type for intrinsic global variable", &GV);
503 Assert(InitArray,
"wrong initalizer for intrinsic global variable",
505 for (
unsigned i = 0, e = InitArray->
getNumOperands(); i != e; ++i) {
507 Assert(isa<GlobalVariable>(V) || isa<Function>(V) ||
509 "invalid llvm.used member", V);
510 Assert(V->
hasName(),
"members of llvm.used must be named", V);
519 "Global is marked as dllimport, but not external", &GV);
522 visitGlobalValue(GV);
531 while (!WorkStack.
empty()) {
533 if (!Visited.
insert(V).second)
536 if (
const User *U = dyn_cast<User>(V)) {
537 WorkStack.
append(U->op_begin(), U->op_end());
540 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
541 VerifyConstantExprBitcastType(CE);
547 visitGlobalValue(GV);
553 visitAliaseeSubExpr(Visited, GA, C);
558 if (
const auto *GV = dyn_cast<GlobalValue>(&C)) {
561 if (
const auto *GA2 = dyn_cast<GlobalAlias>(GV)) {
562 Assert(Visited.
insert(GA2).second,
"Aliases cannot form a cycle", &GA);
564 Assert(!GA2->mayBeOverridden(),
"Alias cannot point to a weak alias",
573 if (
const auto *CE = dyn_cast<ConstantExpr>(&C))
574 VerifyConstantExprBitcastType(CE);
578 if (
const auto *GA2 = dyn_cast<GlobalAlias>(V))
579 visitAliaseeSubExpr(Visited, GA, *GA2->
getAliasee());
580 else if (
const auto *C2 = dyn_cast<Constant>(V))
581 visitAliaseeSubExpr(Visited, GA, *C2);
585 void Verifier::visitGlobalAlias(
const GlobalAlias &GA) {
587 "Alias should have private, internal, linkonce, weak, linkonce_odr, "
588 "weak_odr, or external linkage!",
591 Assert(Aliasee,
"Aliasee cannot be NULL!", &GA);
593 "Alias and aliasee types should match!", &GA);
595 Assert(isa<GlobalValue>(Aliasee) || isa<ConstantExpr>(Aliasee),
596 "Aliasee should be either GlobalValue or ConstantExpr", &GA);
598 visitAliaseeSubExpr(GA, *Aliasee);
600 visitGlobalValue(GA);
603 void Verifier::visitNamedMDNode(
const NamedMDNode &NMD) {
607 if (NMD.
getName() ==
"llvm.dbg.cu") {
608 Assert(MD && isa<DICompileUnit>(MD),
"invalid compile unit", &NMD, MD);
618 void Verifier::visitMDNode(
const MDNode &MD) {
621 if (!MDNodes.insert(&MD).second)
629 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
630 case Metadata::CLASS##Kind: \
631 visit##CLASS(cast<CLASS>(MD)); \
633 #include "llvm/IR/Metadata.def"
640 Assert(!isa<LocalAsMetadata>(Op),
"Invalid operand for global metadata!",
642 if (
auto *
N = dyn_cast<MDNode>(Op)) {
646 if (
auto *V = dyn_cast<ValueAsMetadata>(Op)) {
647 visitValueAsMetadata(*V,
nullptr);
660 "Unexpected metadata round-trip through values", &MD, MD.
getValue());
666 Assert(F,
"function-local metadata used outside a function", L);
671 if (
Instruction *
I = dyn_cast<Instruction>(L->getValue())) {
672 Assert(
I->getParent(),
"function-local metadata not in basic block", L,
I);
673 ActualF =
I->getParent()->getParent();
674 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(L->getValue()))
675 ActualF = BB->getParent();
676 else if (
Argument *
A = dyn_cast<Argument>(L->getValue()))
677 ActualF =
A->getParent();
678 assert(ActualF &&
"Unimplemented function local metadata case!");
680 Assert(ActualF == F,
"function-local metadata used in wrong function", L);
685 if (
auto *
N = dyn_cast<MDNode>(MD)) {
692 if (!MDNodes.insert(MD).second)
695 if (
auto *V = dyn_cast<ValueAsMetadata>(MD))
696 visitValueAsMetadata(*V, F);
703 if (S->getString().empty())
708 UnresolvedTypeRefs.insert(std::make_pair(S, &N));
714 return !MD || isValidUUID(N, MD) || isa<DIType>(MD);
719 return !MD || isValidUUID(N, MD) || isa<DIScope>(MD);
724 return !MD || isValidUUID(N, MD) || isa<DINode>(MD);
743 return isValidMetadataArrayImpl<Ty>(
N,
false);
748 return isValidMetadataArrayImpl<Ty>(
N,
true);
751 void Verifier::visitDILocation(
const DILocation &N) {
753 "location requires a valid scope", &N, N.
getRawScope());
755 Assert(isa<DILocation>(IA),
"inlined-at should be a location", &
N, IA);
762 void Verifier::visitDIScope(
const DIScope &N) {
764 Assert(isa<DIFile>(F),
"invalid file", &
N,
F);
767 void Verifier::visitDISubrange(
const DISubrange &N) {
768 Assert(N.
getTag() == dwarf::DW_TAG_subrange_type,
"invalid tag", &
N);
772 void Verifier::visitDIEnumerator(
const DIEnumerator &N) {
773 Assert(N.
getTag() == dwarf::DW_TAG_enumerator,
"invalid tag", &
N);
776 void Verifier::visitDIBasicType(
const DIBasicType &N) {
778 N.
getTag() == dwarf::DW_TAG_unspecified_type,
795 Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
796 Tag == dwarf::DW_TAG_pointer_type ||
797 Tag == dwarf::DW_TAG_ptr_to_member_type ||
798 Tag == dwarf::DW_TAG_reference_type ||
799 Tag == dwarf::DW_TAG_rvalue_reference_type ||
800 Tag == dwarf::DW_TAG_restrict_type ||
801 Tag == dwarf::DW_TAG_array_type ||
802 Tag == dwarf::DW_TAG_enumeration_type ||
803 Tag == dwarf::DW_TAG_subroutine_type ||
804 Tag == dwarf::DW_TAG_inheritance || Tag == dwarf::DW_TAG_friend ||
805 Tag == dwarf::DW_TAG_structure_type ||
806 Tag == dwarf::DW_TAG_member || Tag == dwarf::DW_TAG_typedef,
807 "derived/composite type requires a filename", &N, N.
getFile());
813 visitDIDerivedTypeBase(N);
816 N.
getTag() == dwarf::DW_TAG_pointer_type ||
817 N.
getTag() == dwarf::DW_TAG_ptr_to_member_type ||
818 N.
getTag() == dwarf::DW_TAG_reference_type ||
819 N.
getTag() == dwarf::DW_TAG_rvalue_reference_type ||
820 N.
getTag() == dwarf::DW_TAG_const_type ||
821 N.
getTag() == dwarf::DW_TAG_volatile_type ||
822 N.
getTag() == dwarf::DW_TAG_restrict_type ||
823 N.
getTag() == dwarf::DW_TAG_member ||
824 N.
getTag() == dwarf::DW_TAG_inheritance ||
825 N.
getTag() == dwarf::DW_TAG_friend,
827 if (N.
getTag() == dwarf::DW_TAG_ptr_to_member_type) {
828 Assert(isTypeRef(N, N.getExtraData()),
"invalid pointer to member type", &N,
834 return (Flags & DINode::FlagLValueReference) &&
835 (Flags & DINode::FlagRValueReference);
838 void Verifier::visitTemplateParams(
const MDNode &N,
const Metadata &RawParams) {
840 Assert(Params,
"invalid template params", &N, &RawParams);
841 for (
Metadata *Op : Params->operands()) {
842 Assert(Op && isa<DITemplateParameter>(Op),
"invalid template parameter", &N,
849 visitDIDerivedTypeBase(N);
852 N.
getTag() == dwarf::DW_TAG_structure_type ||
853 N.
getTag() == dwarf::DW_TAG_union_type ||
854 N.
getTag() == dwarf::DW_TAG_enumeration_type ||
855 N.
getTag() == dwarf::DW_TAG_subroutine_type ||
856 N.
getTag() == dwarf::DW_TAG_class_type,
868 visitTemplateParams(N, *Params);
872 Assert(N.
getTag() == dwarf::DW_TAG_subroutine_type,
"invalid tag", &
N);
874 Assert(isa<MDTuple>(Types),
"invalid composite elements", &N, Types);
876 Assert(isTypeRef(N, Ty),
"invalid subroutine type ref", &N, Types, Ty);
883 void Verifier::visitDIFile(
const DIFile &N) {
884 Assert(N.
getTag() == dwarf::DW_TAG_file_type,
"invalid tag", &
N);
888 Assert(N.
getTag() == dwarf::DW_TAG_compile_unit,
"invalid tag", &
N);
898 Assert(isa<MDTuple>(Array),
"invalid enum list", &N, Array);
900 auto *
Enum = dyn_cast_or_null<DICompositeType>(Op);
901 Assert(Enum &&
Enum->getTag() == dwarf::DW_TAG_enumeration_type,
902 "invalid enum type", &
N, N.getEnumTypes(), Op);
906 Assert(isa<MDTuple>(Array),
"invalid retained type list", &N, Array);
908 Assert(Op && isa<DIType>(Op),
"invalid retained type", &N, Op);
912 Assert(isa<MDTuple>(Array),
"invalid subprogram list", &N, Array);
914 Assert(Op && isa<DISubprogram>(Op),
"invalid subprogram ref", &N, Op);
918 Assert(isa<MDTuple>(Array),
"invalid global variable list", &N, Array);
920 Assert(Op && isa<DIGlobalVariable>(Op),
"invalid global variable ref", &N,
925 Assert(isa<MDTuple>(Array),
"invalid imported entity list", &N, Array);
927 Assert(Op && isa<DIImportedEntity>(Op),
"invalid imported entity ref", &N,
933 void Verifier::visitDISubprogram(
const DISubprogram &N) {
934 Assert(N.
getTag() == dwarf::DW_TAG_subprogram,
"invalid tag", &
N);
935 Assert(isScopeRef(N, N.getRawScope()),
"invalid scope", &N, N.getRawScope());
936 if (
auto *T = N.getRawType())
937 Assert(isa<DISubroutineType>(T),
"invalid subroutine type", &
N,
T);
938 Assert(isTypeRef(N, N.getRawContainingType()),
"invalid containing type", &N,
939 N.getRawContainingType());
940 if (
auto *RawF = N.getRawFunction()) {
942 auto *F = FMD ? FMD->getValue() :
nullptr;
944 Assert(F && FT && isa<FunctionType>(FT->getElementType()),
945 "invalid function", &N, F, FT);
947 if (
auto *Params = N.getRawTemplateParams())
948 visitTemplateParams(N, *Params);
949 if (
auto *S = N.getRawDeclaration()) {
950 Assert(isa<DISubprogram>(S) && !cast<DISubprogram>(S)->isDefinition(),
951 "invalid subprogram declaration", &N, S);
953 if (
auto *RawVars = N.getRawVariables()) {
955 Assert(Vars,
"invalid variable list", &N, RawVars);
956 for (
Metadata *Op : Vars->operands()) {
957 Assert(Op && isa<DILocalVariable>(Op),
"invalid local variable", &N, Vars,
964 auto *F = N.getFunction();
979 dyn_cast_or_null<DILocation>(
I.getDebugLoc().getAsMDNode());
982 if (!Seen.
insert(DL).second)
986 if (Scope && !Seen.
insert(Scope).second)
990 if (SP && !Seen.
insert(SP).second)
995 "!dbg attachment points at wrong subprogram for function", &
N,
F,
1001 Assert(N.
getTag() == dwarf::DW_TAG_lexical_block,
"invalid tag", &
N);
1007 visitDILexicalBlockBase(N);
1010 "cannot have column info without line info", &
N);
1014 visitDILexicalBlockBase(N);
1017 void Verifier::visitDINamespace(
const DINamespace &N) {
1018 Assert(N.
getTag() == dwarf::DW_TAG_namespace,
"invalid tag", &
N);
1020 Assert(isa<DIScope>(S),
"invalid scope ref", &
N, S);
1023 void Verifier::visitDIModule(
const DIModule &N) {
1024 Assert(N.
getTag() == dwarf::DW_TAG_module,
"invalid tag", &
N);
1033 visitDITemplateParameter(N);
1035 Assert(N.
getTag() == dwarf::DW_TAG_template_type_parameter,
"invalid tag",
1039 void Verifier::visitDITemplateValueParameter(
1041 visitDITemplateParameter(N);
1043 Assert(N.
getTag() == dwarf::DW_TAG_template_value_parameter ||
1044 N.
getTag() == dwarf::DW_TAG_GNU_template_template_param ||
1045 N.
getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
1049 void Verifier::visitDIVariable(
const DIVariable &N) {
1051 Assert(isa<DIScope>(S),
"invalid scope", &
N, S);
1054 Assert(isa<DIFile>(F),
"invalid file", &
N,
F);
1061 Assert(N.
getTag() == dwarf::DW_TAG_variable,
"invalid tag", &
N);
1064 Assert(isa<ConstantAsMetadata>(V) &&
1065 !isa<Function>(cast<ConstantAsMetadata>(V)->getValue()),
1066 "invalid global varaible ref", &N, V);
1069 Assert(isa<DIDerivedType>(Member),
"invalid static data member declaration",
1079 N.
getTag() == dwarf::DW_TAG_arg_variable,
1082 "local variable requires a valid scope", &N, N.
getRawScope());
1085 void Verifier::visitDIExpression(
const DIExpression &N) {
1090 Assert(N.
getTag() == dwarf::DW_TAG_APPLE_property,
"invalid tag", &
N);
1092 Assert(isTypeRef(N, T),
"invalid type ref", &
N,
T);
1094 Assert(isa<DIFile>(F),
"invalid file", &
N,
F);
1099 N.
getTag() == dwarf::DW_TAG_imported_declaration,
1102 Assert(isa<DIScope>(S),
"invalid scope for imported entity", &
N, S);
1107 void Verifier::visitComdat(
const Comdat &C) {
1115 void Verifier::visitModuleIdents(
const Module &M) {
1122 for (
unsigned i = 0, e = Idents->
getNumOperands(); i != e; ++i) {
1125 "incorrect number of operands in llvm.ident metadata",
N);
1127 (
"invalid value for llvm.ident metadata entry operand"
1128 "(the operand should be a string)"),
1133 void Verifier::visitModuleFlags(
const Module &M) {
1141 visitModuleFlag(Flags->
getOperand(
I), SeenIDs, Requirements);
1145 for (
unsigned I = 0, E = Requirements.
size();
I != E; ++
I) {
1146 const MDNode *Requirement = Requirements[
I];
1152 CheckFailed(
"invalid requirement on flag, flag is not present in module",
1158 CheckFailed((
"invalid requirement on flag, "
1159 "flag does not have the required value"),
1167 Verifier::visitModuleFlag(
const MDNode *Op,
1173 "incorrect number of operands in module flag", Op);
1177 mdconst::dyn_extract_or_null<ConstantInt>(Op->
getOperand(0)),
1178 "invalid behavior operand in module flag (expected constant integer)",
1181 "invalid behavior operand in module flag (unexpected constant)",
1185 Assert(ID,
"invalid ID operand in module flag (expected metadata string)",
1201 "invalid value for 'require' module flag (expected metadata pair)",
1204 (
"invalid value for 'require' module flag "
1205 "(first value operand should be a string)"),
1218 "invalid value for 'append'-type module flag "
1219 "(expected a metadata node)",
1227 bool Inserted = SeenIDs.
insert(std::make_pair(ID, Op)).second;
1229 "module flag identifiers must be unique (or of 'require' type)", ID);
1233 void Verifier::VerifyAttributeTypes(
AttributeSet Attrs,
unsigned Idx,
1234 bool isFunction,
const Value *V) {
1235 unsigned Slot = ~0U;
1242 assert(Slot != ~0U &&
"Attribute set inconsistency!");
1246 if (
I->isStringAttribute())
1279 CheckFailed(
"Attribute '" +
I->getAsString() +
1280 "' only applies to functions!", V);
1286 CheckFailed(
"Attribute '" +
I->getAsString() +
1287 "' does not apply to function returns");
1290 }
else if (isFunction) {
1291 CheckFailed(
"Attribute '" +
I->getAsString() +
1292 "' does not apply to functions!", V);
1300 void Verifier::VerifyParameterAttrs(
AttributeSet Attrs,
unsigned Idx,
Type *Ty,
1301 bool isReturnValue,
const Value *V) {
1305 VerifyAttributeTypes(Attrs, Idx,
false, V);
1314 "Attributes 'byval', 'inalloca', 'nest', 'sret', 'nocapture', and "
1315 "'returned' do not apply to return values!",
1320 unsigned AttrCount = 0;
1326 Assert(AttrCount <= 1,
"Attributes 'byval', 'inalloca', 'inreg', 'nest', "
1327 "and 'sret' are incompatible!",
1333 "'inalloca and readonly' are incompatible!",
1339 "'sret and returned' are incompatible!",
1345 "'zeroext and signext' are incompatible!",
1351 "'readnone and readonly' are incompatible!",
1357 "'noinline and alwaysinline' are incompatible!",
1362 "Wrong types for attribute: " +
1363 AttributeSet::get(*Context, Idx,
1367 if (
PointerType *PTy = dyn_cast<PointerType>(Ty)) {
1372 "Attributes 'byval' and 'inalloca' do not support unsized types!",
1377 "Attribute 'byval' only applies to parameters with pointer type!",
1389 bool SawNest =
false;
1390 bool SawReturned =
false;
1391 bool SawSRet =
false;
1393 for (
unsigned i = 0, e = Attrs.
getNumSlots(); i != e; ++i) {
1404 VerifyParameterAttrs(Attrs, Idx, Ty, Idx == 0, V);
1410 Assert(!SawNest,
"More than one parameter has attribute nest!", V);
1415 Assert(!SawReturned,
"More than one parameter has attribute returned!",
1419 "argument and return types for 'returned' attribute",
1425 Assert(!SawSRet,
"Cannot have multiple 'sret' parameters!", V);
1426 Assert(Idx == 1 || Idx == 2,
1427 "Attribute 'sret' is not on first or second parameter!", V);
1445 "Attributes 'readnone and readonly' are incompatible!", V);
1451 "Attributes 'noinline and alwaysinline' are incompatible!", V);
1456 "Attribute 'optnone' requires 'noinline'!", V);
1460 "Attributes 'optsize and optnone' are incompatible!", V);
1463 "Attributes 'minsize and optnone' are incompatible!", V);
1470 "Attribute 'jumptable' requires 'unnamed_addr'", V);
1474 void Verifier::VerifyFunctionMetadata(
1475 const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs) {
1479 for (
unsigned i = 0; i < MDs.size(); i++) {
1481 MDNode *MD = MDs[i].second;
1483 "!prof annotations should have exactly 2 operands", MD);
1489 "expected string with name of the !prof annotation", MD);
1492 Assert(ProfName.equals(
"function_entry_count"),
1493 "first operand should be 'function_entry_count'", MD);
1499 "expected integer argument to function_entry_count", MD);
1504 void Verifier::VerifyConstantExprBitcastType(
const ConstantExpr *CE) {
1505 if (CE->
getOpcode() != Instruction::BitCast)
1510 "Invalid bitcast", CE);
1513 bool Verifier::VerifyAttributeCount(
AttributeSet Attrs,
unsigned Params) {
1519 if (LastIndex <= Params
1521 && (LastSlot == 0 || Attrs.
getSlotIndex(LastSlot - 1) <= Params)))
1531 Intrinsic::experimental_gc_statepoint);
1537 "gc.statepoint must read and write all memory to preserve "
1538 "reordering restrictions required by safepoint semantics",
1542 Assert(isa<ConstantInt>(IDV),
"gc.statepoint ID must be a constant integer",
1546 Assert(isa<ConstantInt>(NumPatchBytesV),
1547 "gc.statepoint number of patchable bytes must be a constant integer",
1549 const int64_t NumPatchBytes =
1550 cast<ConstantInt>(NumPatchBytesV)->getSExtValue();
1551 assert(
isInt<32>(NumPatchBytes) &&
"NumPatchBytesV is an i32!");
1552 Assert(NumPatchBytes >= 0,
"gc.statepoint number of patchable bytes must be "
1559 "gc.statepoint callee must be of function pointer type", &CI, Target);
1564 "gc.statepoint must have null as call target if number of patchable "
1565 "bytes is non zero",
1569 Assert(isa<ConstantInt>(NumCallArgsV),
1570 "gc.statepoint number of arguments to underlying call "
1571 "must be constant integer",
1573 const int NumCallArgs = cast<ConstantInt>(NumCallArgsV)->getZExtValue();
1575 "gc.statepoint number of arguments to underlying call "
1578 const int NumParams = (
int)TargetFuncType->getNumParams();
1579 if (TargetFuncType->isVarArg()) {
1580 Assert(NumCallArgs >= NumParams,
1581 "gc.statepoint mismatch in number of vararg call args", &CI);
1584 Assert(TargetFuncType->getReturnType()->isVoidTy(),
1585 "gc.statepoint doesn't support wrapping non-void "
1586 "vararg functions yet",
1589 Assert(NumCallArgs == NumParams,
1590 "gc.statepoint mismatch in number of call args", &CI);
1593 Assert(isa<ConstantInt>(FlagsV),
1594 "gc.statepoint flags must be constant integer", &CI);
1595 const uint64_t Flags = cast<ConstantInt>(FlagsV)->getZExtValue();
1597 "unknown flag used in gc.statepoint flags argument", &CI);
1601 for (
int i = 0; i < NumParams; i++) {
1602 Type *ParamType = TargetFuncType->getParamType(i);
1604 Assert(ArgType == ParamType,
1605 "gc.statepoint call argument does not match wrapped "
1610 const int EndCallArgsInx = 4 + NumCallArgs;
1612 const Value *NumTransitionArgsV = CS.
getArgument(EndCallArgsInx+1);
1613 Assert(isa<ConstantInt>(NumTransitionArgsV),
1614 "gc.statepoint number of transition arguments "
1615 "must be constant integer",
1617 const int NumTransitionArgs =
1618 cast<ConstantInt>(NumTransitionArgsV)->getZExtValue();
1619 Assert(NumTransitionArgs >= 0,
1620 "gc.statepoint number of transition arguments must be positive", &CI);
1621 const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs;
1623 const Value *NumDeoptArgsV = CS.
getArgument(EndTransitionArgsInx+1);
1624 Assert(isa<ConstantInt>(NumDeoptArgsV),
1625 "gc.statepoint number of deoptimization arguments "
1626 "must be constant integer",
1628 const int NumDeoptArgs = cast<ConstantInt>(NumDeoptArgsV)->getZExtValue();
1629 Assert(NumDeoptArgs >= 0,
"gc.statepoint number of deoptimization arguments "
1633 const int ExpectedNumArgs =
1634 7 + NumCallArgs + NumTransitionArgs + NumDeoptArgs;
1636 "gc.statepoint too few arguments according to length fields", &CI);
1643 Assert(Call,
"illegal use of statepoint token", &CI, U);
1644 if (!Call)
continue;
1646 "gc.result or gc.relocate are the only value uses"
1647 "of a gc.statepoint",
1651 "gc.result connected to wrong gc.statepoint", &CI,
Call);
1654 "gc.relocate connected to wrong gc.statepoint", &CI,
Call);
1668 void Verifier::verifyFrameRecoverIndices() {
1669 for (
auto &Counts : FrameEscapeInfo) {
1671 unsigned EscapedObjectCount = Counts.second.first;
1672 unsigned MaxRecoveredIndex = Counts.second.second;
1673 Assert(MaxRecoveredIndex <= EscapedObjectCount,
1674 "all indices passed to llvm.localrecover must be less than the "
1675 "number of arguments passed ot llvm.localescape in the parent "
1683 void Verifier::visitFunction(
const Function &F) {
1689 "Function context does not match Module context!", &
F);
1693 "# formal arguments must match # of arguments for function type!", &
F,
1695 Assert(F.getReturnType()->isFirstClassType() ||
1696 F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(),
1697 "Functions cannot return aggregate values!", &
F);
1699 Assert(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),
1700 "Invalid struct return type!", &
F);
1705 "Attribute after last parameter!", &F);
1708 VerifyFunctionAttrs(FT, Attrs, &F);
1714 "Attribute 'builtin' can only be applied to a callsite.", &
F);
1719 switch (F.getCallingConv()) {
1728 Assert(!F.isVarArg(),
"Calling convention does not support varargs or "
1729 "perfect forwarding!",
1734 bool isLLVMdotName = F.getName().size() >= 5 &&
1735 F.getName().substr(0, 5) ==
"llvm.";
1742 "Argument value does not match function argument type!",
I,
1744 Assert(
I->getType()->isFirstClassType(),
1745 "Function arguments must have first-class types!",
I);
1747 Assert(!
I->getType()->isMetadataTy(),
1748 "Function takes metadata but isn't an intrinsic",
I, &
F);
1753 F.getAllMetadata(MDs);
1754 assert(F.hasMetadata() != MDs.
empty() &&
"Bit out-of-sync");
1755 VerifyFunctionMetadata(MDs);
1757 if (F.isMaterializable()) {
1759 Assert(MDs.
empty(),
"unmaterialized function cannot have metadata", &
F,
1761 }
else if (F.isDeclaration()) {
1762 Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),
1763 "invalid linkage type for function declaration", &
F);
1764 Assert(MDs.
empty(),
"function without a body cannot have metadata", &
F,
1766 Assert(!F.hasPersonalityFn(),
1767 "Function declaration shouldn't have a personality routine", &
F);
1771 Assert(!isLLVMdotName,
"llvm intrinsics cannot be defined!", &F);
1774 const BasicBlock *Entry = &F.getEntryBlock();
1776 "Entry block to function must not have predecessors!", Entry);
1781 "blockaddress may not be used with the entry block!", Entry);
1785 for (
const auto &
I : MDs)
1786 visitMDNode(*
I.second);
1791 if (F.getIntrinsicID()) {
1793 if (F.hasAddressTaken(&U))
1794 Assert(0,
"Invalid user of intrinsic instruction!", U);
1797 Assert(!F.hasDLLImportStorageClass() ||
1798 (F.isDeclaration() && F.hasExternalLinkage()) ||
1799 F.hasAvailableExternallyLinkage(),
1800 "Function is marked as dllimport, but not external.", &
F);
1805 void Verifier::visitBasicBlock(
BasicBlock &BB) {
1806 InstsInThisBlock.clear();
1813 if (isa<PHINode>(BB.
front())) {
1816 std::sort(Preds.begin(), Preds.end());
1820 Assert(PN->getNumIncomingValues() != 0,
1821 "PHI nodes must have at least one entry. If the block is dead, "
1822 "the PHI should be removed!",
1824 Assert(PN->getNumIncomingValues() == Preds.size(),
1825 "PHINode should have one entry for each predecessor of its "
1826 "parent basic block!",
1831 Values.
reserve(PN->getNumIncomingValues());
1832 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
1833 Values.
push_back(std::make_pair(PN->getIncomingBlock(i),
1834 PN->getIncomingValue(i)));
1835 std::sort(Values.
begin(), Values.
end());
1837 for (
unsigned i = 0, e = Values.
size(); i != e; ++i) {
1842 Assert(i == 0 || Values[i].first != Values[i - 1].first ||
1843 Values[i].second == Values[i - 1].second,
1844 "PHI node has multiple entries for the same basic block with "
1845 "different incoming values!",
1846 PN, Values[i].first, Values[i].second, Values[i - 1].second);
1850 Assert(Values[i].first == Preds[i],
1851 "PHI node entries do not match predecessors!", PN,
1852 Values[i].first, Preds[i]);
1860 Assert(
I.getParent() == &BB,
"Instruction has bogus parent pointer!");
1867 "Terminator found in the middle of a basic block!", I.
getParent());
1868 visitInstruction(I);
1871 void Verifier::visitBranchInst(
BranchInst &BI) {
1874 "Branch condition is not 'i1' type!", &BI, BI.
getCondition());
1876 visitTerminatorInst(BI);
1879 void Verifier::visitReturnInst(
ReturnInst &RI) {
1884 "Found return instr that returns non-void in Function of void "
1889 "Function return type does not match operand "
1890 "type of return inst!",
1895 visitTerminatorInst(RI);
1904 Assert(i.getCaseValue()->getType() == SwitchTy,
1905 "Switch constants must all be same type as switch value!", &
SI);
1907 "Duplicate integer as switch case", &SI, i.getCaseValue());
1910 visitTerminatorInst(SI);
1915 "Indirectbr operand must have pointer type!", &BI);
1918 "Indirectbr destinations must all have pointer type!", &BI);
1920 visitTerminatorInst(BI);
1923 void Verifier::visitSelectInst(
SelectInst &SI) {
1926 "Invalid operands for select instruction!", &SI);
1929 "Select values must have same type as select instruction!", &
SI);
1930 visitInstruction(SI);
1937 Assert(0,
"User-defined operators should not live outside of a pass!", &I);
1940 void Verifier::visitTruncInst(
TruncInst &I) {
1952 "trunc source and destination must both be a vector or neither", &
I);
1953 Assert(SrcBitSize > DestBitSize,
"DestTy too big for Trunc", &I);
1955 visitInstruction(I);
1958 void Verifier::visitZExtInst(
ZExtInst &I) {
1967 "zext source and destination must both be a vector or neither", &
I);
1971 Assert(SrcBitSize < DestBitSize,
"Type too small for ZExt", &I);
1973 visitInstruction(I);
1976 void Verifier::visitSExtInst(
SExtInst &I) {
1988 "sext source and destination must both be a vector or neither", &
I);
1989 Assert(SrcBitSize < DestBitSize,
"Type too small for SExt", &I);
1991 visitInstruction(I);
2005 "fptrunc source and destination must both be a vector or neither", &
I);
2006 Assert(SrcBitSize > DestBitSize,
"DestTy too big for FPTrunc", &I);
2008 visitInstruction(I);
2011 void Verifier::visitFPExtInst(
FPExtInst &I) {
2023 "fpext source and destination must both be a vector or neither", &
I);
2024 Assert(SrcBitSize < DestBitSize,
"DestTy too small for FPExt", &I);
2026 visitInstruction(I);
2029 void Verifier::visitUIToFPInst(
UIToFPInst &I) {
2038 "UIToFP source and dest must both be vector or scalar", &I);
2040 "UIToFP source must be integer or integer vector", &
I);
2044 if (SrcVec && DstVec)
2045 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2046 cast<VectorType>(DestTy)->getNumElements(),
2047 "UIToFP source and dest vector length mismatch", &I);
2049 visitInstruction(I);
2052 void Verifier::visitSIToFPInst(
SIToFPInst &I) {
2061 "SIToFP source and dest must both be vector or scalar", &I);
2063 "SIToFP source must be integer or integer vector", &
I);
2067 if (SrcVec && DstVec)
2068 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2069 cast<VectorType>(DestTy)->getNumElements(),
2070 "SIToFP source and dest vector length mismatch", &I);
2072 visitInstruction(I);
2075 void Verifier::visitFPToUIInst(
FPToUIInst &I) {
2084 "FPToUI source and dest must both be vector or scalar", &I);
2088 "FPToUI result must be integer or integer vector", &
I);
2090 if (SrcVec && DstVec)
2091 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2092 cast<VectorType>(DestTy)->getNumElements(),
2093 "FPToUI source and dest vector length mismatch", &I);
2095 visitInstruction(I);
2098 void Verifier::visitFPToSIInst(
FPToSIInst &I) {
2107 "FPToSI source and dest must both be vector or scalar", &I);
2111 "FPToSI result must be integer or integer vector", &
I);
2113 if (SrcVec && DstVec)
2114 Assert(cast<VectorType>(SrcTy)->getNumElements() ==
2115 cast<VectorType>(DestTy)->getNumElements(),
2116 "FPToSI source and dest vector length mismatch", &I);
2118 visitInstruction(I);
2127 "PtrToInt source must be pointer", &
I);
2129 "PtrToInt result must be integral", &
I);
2137 "PtrToInt Vector width mismatch", &
I);
2140 visitInstruction(I);
2149 "IntToPtr source must be an integral", &
I);
2151 "IntToPtr result must be a pointer", &
I);
2158 "IntToPtr Vector width mismatch", &
I);
2160 visitInstruction(I);
2166 "Invalid bitcast", &I);
2167 visitInstruction(I);
2179 "AddrSpaceCast must be between different address spaces", &
I);
2182 "AddrSpaceCast vector pointer number of elements mismatch", &
I);
2183 visitInstruction(I);
2188 void Verifier::visitPHINode(
PHINode &PN) {
2195 "PHI nodes not grouped at top of basic block!", &PN, PN.
getParent());
2201 "PHI node operands are not the same type as the result!", &PN);
2206 visitInstruction(PN);
2209 void Verifier::VerifyCallSite(
CallSite CS) {
2213 "Called function must be a pointer!",
I);
2216 Assert(FPTy->getElementType()->isFunctionTy(),
2217 "Called function is not pointer to function type!",
I);
2220 "Called function is not the same type as the call!",
I);
2225 if (FTy->isVarArg())
2227 "Called function requires more parameters than were provided!",
I);
2230 "Incorrect number of arguments passed to called function!",
I);
2233 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
2235 "Call parameter type does not match function signature!",
2241 "Attribute after last parameter!", I);
2244 VerifyFunctionAttrs(FTy, Attrs, I);
2250 Value *InAllocaArg = CS.
getArgument(FTy->getNumParams() - 1);
2252 Assert(AI->isUsedWithInAlloca(),
2253 "inalloca argument for call has mismatched alloca", AI,
I);
2256 if (FTy->isVarArg()) {
2258 bool SawNest =
false;
2259 bool SawReturned =
false;
2261 for (
unsigned Idx = 1; Idx < 1 + FTy->getNumParams(); ++Idx) {
2269 for (
unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.
arg_size(); ++Idx) {
2271 VerifyParameterAttrs(Attrs, Idx, Ty,
false, I);
2274 Assert(!SawNest,
"More than one parameter has attribute nest!", I);
2279 Assert(!SawReturned,
"More than one parameter has attribute returned!",
2282 "Incompatible argument and return types for 'returned' "
2289 "Attribute 'sret' cannot be used for vararg call arguments!",
I);
2292 Assert(Idx == CS.
arg_size(),
"inalloca isn't on the last argument!",
I);
2300 PE = FTy->param_end(); PI != PE; ++PI)
2301 Assert(!(*PI)->isMetadataTy(),
2302 "Function has metadata parameter but isn't an intrinsic",
I);
2307 visitIntrinsicCallSite(ID, CS);
2309 visitInstruction(*I);
2329 for (
auto AK : ABIAttrs) {
2338 void Verifier::verifyMustTailCall(
CallInst &CI) {
2348 "cannot guarantee tail call due to mismatched parameter counts", &CI);
2350 "cannot guarantee tail call due to mismatched varargs", &CI);
2352 "cannot guarantee tail call due to mismatched return types", &CI);
2353 for (
int I = 0, E = CallerTy->
getNumParams(); I != E; ++
I) {
2356 "cannot guarantee tail call due to mismatched parameter types", &CI);
2361 "cannot guarantee tail call due to mismatched calling conv", &CI);
2367 for (
int I = 0, E = CallerTy->
getNumParams(); I != E; ++
I) {
2370 Assert(CallerABIAttrs == CalleeABIAttrs,
2371 "cannot guarantee tail call due to mismatched ABI impacting "
2372 "function attributes",
2380 Value *RetVal = &CI;
2384 if (
BitCastInst *BI = dyn_cast_or_null<BitCastInst>(Next)) {
2386 "bitcast following musttail call must use the call", BI);
2393 Assert(Ret,
"musttail call must be precede a ret with an optional bitcast",
2396 "musttail call result must be returned",
Ret);
2399 void Verifier::visitCallInst(
CallInst &CI) {
2400 VerifyCallSite(&CI);
2403 verifyMustTailCall(CI);
2406 void Verifier::visitInvokeInst(
InvokeInst &II) {
2407 VerifyCallSite(&II);
2412 "The unwind destination does not have a landingpad instruction!", &II);
2414 visitTerminatorInst(II);
2422 "Both operands to a binary operator are not of the same type!", &B);
2427 case Instruction::Add:
2428 case Instruction::Sub:
2429 case Instruction::Mul:
2430 case Instruction::SDiv:
2431 case Instruction::UDiv:
2432 case Instruction::SRem:
2433 case Instruction::URem:
2435 "Integer arithmetic operators only work with integral types!", &B);
2437 "Integer arithmetic operators must have same type "
2438 "for operands and result!",
2443 case Instruction::FAdd:
2444 case Instruction::FSub:
2445 case Instruction::FMul:
2446 case Instruction::FDiv:
2447 case Instruction::FRem:
2449 "Floating-point arithmetic operators only work with "
2450 "floating-point types!",
2453 "Floating-point arithmetic operators must have same type "
2454 "for operands and result!",
2462 "Logical operators only work with integral types!", &B);
2464 "Logical operators must have same type for operands and result!",
2467 case Instruction::Shl:
2468 case Instruction::LShr:
2469 case Instruction::AShr:
2471 "Shifts only work with integral types!", &B);
2473 "Shift return type must be same as operands!", &B);
2479 visitInstruction(B);
2482 void Verifier::visitICmpInst(
ICmpInst &IC) {
2487 "Both operands to ICmp instruction are not of the same type!", &IC);
2490 "Invalid operand types for ICmp instruction", &IC);
2494 "Invalid predicate in ICmp instruction!", &IC);
2496 visitInstruction(IC);
2504 "Both operands to FCmp instruction are not of the same type!", &FC);
2507 "Invalid operand types for FCmp instruction", &
FC);
2511 "Invalid predicate in FCmp instruction!", &
FC);
2513 visitInstruction(FC);
2519 "Invalid extractelement operands!", &EI);
2520 visitInstruction(EI);
2526 "Invalid insertelement operands!", &IE);
2527 visitInstruction(IE);
2533 "Invalid shufflevector operands!", &SV);
2534 visitInstruction(SV);
2540 Assert(isa<PointerType>(TargetTy),
2541 "GEP base pointer is not a vector or a vector of pointers", &GEP);
2546 Assert(ElTy,
"Invalid indices for GEP pointer type!", &GEP);
2550 "GEP is not of right type for indices!", &
GEP, ElTy);
2552 if (GEP.getType()->isVectorTy()) {
2554 unsigned GEPWidth = GEP.getType()->getVectorNumElements();
2555 if (GEP.getPointerOperandType()->isVectorTy())
2556 Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(),
2557 "Vector GEP result width doesn't match operand's", &
GEP);
2558 for (
unsigned i = 0, e = Idxs.size(); i != e; ++i) {
2559 Type *IndexTy = Idxs[i]->getType();
2562 Assert(IndexWidth == GEPWidth,
"Invalid GEP index vector width", &GEP);
2565 "All GEP indices should be of integer type");
2568 visitInstruction(GEP);
2579 "precondition violation");
2582 Assert(NumOperands % 2 == 0,
"Unfinished range!", Range);
2583 unsigned NumRanges = NumOperands / 2;
2584 Assert(NumRanges >= 1,
"It should have at least one range!", Range);
2587 for (
unsigned i = 0; i < NumRanges; ++i) {
2589 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i));
2590 Assert(Low,
"The lower limit must be an integer!", Low);
2592 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(2 * i + 1));
2593 Assert(High,
"The upper limit must be an integer!", High);
2595 "Range types must match instruction type!", &
I);
2600 Assert(!CurRange.isEmptySet() && !CurRange.isFullSet(),
2601 "Range must not be empty!", Range);
2603 Assert(CurRange.intersectWith(LastRange).isEmptySet(),
2604 "Intervals are overlapping", Range);
2605 Assert(LowV.
sgt(LastRange.getLower()),
"Intervals are not in order",
2612 if (NumRanges > 2) {
2614 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(0))->getValue();
2616 mdconst::dyn_extract<ConstantInt>(Range->
getOperand(1))->getValue();
2618 Assert(FirstRange.intersectWith(LastRange).isEmptySet(),
2619 "Intervals are overlapping", Range);
2625 void Verifier::visitLoadInst(
LoadInst &LI) {
2627 Assert(PTy,
"Load operand must be a pointer.", &LI);
2630 "huge alignment values are unsupported", &LI);
2633 "Load cannot have Release ordering", &LI);
2635 "Atomic load must specify explicit alignment", &LI);
2640 Assert(Size >= 8 && !(Size & (Size - 1)),
2641 "atomic load operand must be power-of-two byte-sized integer", &LI,
2646 "Non-atomic load cannot have SynchronizationScope specified", &LI);
2649 visitInstruction(LI);
2652 void Verifier::visitStoreInst(
StoreInst &SI) {
2654 Assert(PTy,
"Store operand must be a pointer.", &SI);
2657 "Stored value type does not match pointer operand type!", &
SI, ElTy);
2659 "huge alignment values are unsupported", &
SI);
2662 "Store cannot have Acquire ordering", &
SI);
2664 "Atomic store must specify explicit alignment", &
SI);
2667 "atomic store operand must have integer type!", &
SI, ElTy);
2669 Assert(Size >= 8 && !(Size & (Size - 1)),
2670 "atomic store operand must be power-of-two byte-sized integer",
2675 "Non-atomic store cannot have SynchronizationScope specified", &
SI);
2677 visitInstruction(SI);
2680 void Verifier::visitAllocaInst(
AllocaInst &AI) {
2684 "Allocation instruction pointer not in the generic address space!",
2687 "Cannot allocate unsized type", &AI);
2689 "Alloca array size must have integer type", &AI);
2691 "huge alignment values are unsupported", &AI);
2693 visitInstruction(AI);
2700 "cmpxchg instructions must be atomic.", &CXI);
2702 "cmpxchg instructions must be atomic.", &CXI);
2704 "cmpxchg instructions cannot be unordered.", &CXI);
2706 "cmpxchg instructions cannot be unordered.", &CXI);
2708 "cmpxchg instructions be at least as constrained on success as fail",
2712 "cmpxchg failure ordering cannot include release semantics", &CXI);
2715 Assert(PTy,
"First cmpxchg operand must be a pointer.", &CXI);
2716 Type *ElTy = PTy->getElementType();
2720 Assert(Size >= 8 && !(Size & (Size - 1)),
2721 "cmpxchg operand must be power-of-two byte-sized integer", &CXI, ElTy);
2723 "Expected value type does not match pointer operand type!", &CXI,
2726 "Stored value type does not match pointer operand type!", &CXI, ElTy);
2727 visitInstruction(CXI);
2732 "atomicrmw instructions must be atomic.", &RMWI);
2734 "atomicrmw instructions cannot be unordered.", &RMWI);
2736 Assert(PTy,
"First atomicrmw operand must be a pointer.", &RMWI);
2737 Type *ElTy = PTy->getElementType();
2741 Assert(Size >= 8 && !(Size & (Size - 1)),
2742 "atomicrmw operand must be power-of-two byte-sized integer", &RMWI,
2745 "Argument value type does not match pointer operand type!", &RMWI,
2749 "Invalid binary operation!", &RMWI);
2750 visitInstruction(RMWI);
2753 void Verifier::visitFenceInst(
FenceInst &FI) {
2757 "fence instructions may only have "
2758 "acquire, release, acq_rel, or seq_cst ordering.",
2760 visitInstruction(FI);
2766 "Invalid ExtractValueInst operands!", &EVI);
2768 visitInstruction(EVI);
2775 "Invalid InsertValueInst operands!", &IVI);
2777 visitInstruction(IVI);
2786 "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
2793 "Block containing LandingPadInst must be jumped to "
2794 "only by the unwind edge of an invoke.",
2800 "LandingPadInst needs to be in a function with a personality.", &LPI);
2805 "LandingPadInst not the first non-PHI instruction in the block.",
2812 "Catch operand does not have pointer type!", &LPI);
2814 Assert(LPI.
isFilter(i),
"Clause is neither catch nor filter!", &LPI);
2815 Assert(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),
2816 "Filter operand is not an array of constants!", &LPI);
2820 visitInstruction(LPI);
2823 void Verifier::verifyDominatesUse(
Instruction &I,
unsigned i) {
2828 if (
InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
2834 Assert(InstsInThisBlock.count(Op) || DT.dominates(Op, U),
2835 "Instruction does not dominate all uses!", Op, &
I);
2842 Assert(BB,
"Instruction not embedded in basic block!", &I);
2844 if (!isa<PHINode>(I)) {
2846 Assert(U != (
User *)&I || !DT.isReachableFromEntry(BB),
2847 "Only PHI nodes may reference their own value!", &
I);
2853 "Instruction has a name, but provides a void value!", &
I);
2858 "Instruction returns a non-scalar type!", &
I);
2863 "Invalid use of metadata!", &
I);
2870 Assert(Used->getParent() !=
nullptr,
2871 "Instruction referencing"
2872 " instruction not embedded in a basic block!",
2875 CheckFailed(
"Use of instruction is not an instruction!", U);
2886 Assert(0,
"Instruction operands must be first-class values!", &I);
2894 i == (isa<CallInst>(
I) ? e - 1 : isa<InvokeInst>(I) ? e - 3 : 0),
2895 "Cannot take the address of an intrinsic!", &I);
2899 F->
getIntrinsicID() == Intrinsic::experimental_patchpoint_void ||
2902 "Cannot invoke an intrinsinc other than"
2903 " donothing or patchpoint",
2905 Assert(F->
getParent() == M,
"Referencing function in another module!",
2909 "Referring to a basic block in another function!", &
I);
2912 "Referring to an argument in another function!", &
I);
2915 }
else if (isa<Instruction>(I.
getOperand(i))) {
2916 verifyDominatesUse(I, i);
2917 }
else if (isa<InlineAsm>(I.
getOperand(i))) {
2918 Assert((i + 1 == e && isa<CallInst>(I)) ||
2919 (i + 3 == e && isa<InvokeInst>(I)),
2920 "Cannot take the address of an inline asm!", &I);
2929 while (!Stack.
empty()) {
2931 if (!Visited.
insert(V).second)
2934 VerifyConstantExprBitcastType(V);
2947 "fpmath requires a floating point result!", &
I);
2950 mdconst::dyn_extract_or_null<ConstantFP>(MD->
getOperand(0))) {
2951 APFloat Accuracy = CFP0->getValueAPF();
2953 "fpmath accuracy not a positive number!", &
I);
2955 Assert(
false,
"invalid fpmath accuracy!", &I);
2960 Assert(isa<LoadInst>(I) || isa<CallInst>(I) || isa<InvokeInst>(I),
2961 "Ranges are only for loads, calls and invokes!", &I);
2962 visitRangeMetadata(I, Range, I.
getType());
2969 "nonnull applies only to load instructions, use attributes"
2970 " for calls or invokes",
2975 Assert(isa<DILocation>(N),
"invalid !dbg metadata attachment", &I, N);
2979 InstsInThisBlock.insert(&I);
2987 bool Verifier::VerifyIntrinsicType(
Type *Ty,
2990 using namespace Intrinsic;
2993 if (Infos.
empty())
return true;
2994 IITDescriptor D = Infos.
front();
2995 Infos = Infos.
slice(1);
3022 for (
unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
3031 if (D.getArgumentNumber() < ArgTys.
size())
3032 return Ty != ArgTys[D.getArgumentNumber()];
3036 assert(D.getArgumentNumber() == ArgTys.
size() &&
"Table consistency error");
3039 switch (D.getArgumentKind()) {
3050 if (D.getArgumentNumber() >= ArgTys.
size())
3053 Type *NewTy = ArgTys[D.getArgumentNumber()];
3054 if (
VectorType *VTy = dyn_cast<VectorType>(NewTy))
3056 else if (
IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
3065 if (D.getArgumentNumber() >= ArgTys.
size())
3068 Type *NewTy = ArgTys[D.getArgumentNumber()];
3069 if (
VectorType *VTy = dyn_cast<VectorType>(NewTy))
3071 else if (
IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
3080 return D.getArgumentNumber() >= ArgTys.
size() ||
3081 !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
3083 cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
3085 if (D.getArgumentNumber() >= ArgTys.
size())
3090 if (!ThisArgType || !ReferenceType ||
3092 ThisArgType->getVectorNumElements()))
3094 return VerifyIntrinsicType(ThisArgType->getVectorElementType(),
3098 if (D.getArgumentNumber() >= ArgTys.
size())
3100 Type * ReferenceType = ArgTys[D.getArgumentNumber()];
3102 return (!ThisArgType || ThisArgType->
getElementType() != ReferenceType);
3105 if (D.getArgumentNumber() >= ArgTys.
size())
3110 if (!ThisArgVecTy || !ReferenceType ||
3112 ThisArgVecTy->getVectorNumElements()))
3131 Verifier::VerifyIntrinsicIsVarArg(
bool isVarArg,
3133 using namespace Intrinsic;
3140 if (Infos.
size() != 1)
3144 IITDescriptor D = Infos.
front();
3145 Infos = Infos.
slice(1);
3168 Assert(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef, ArgTys),
3169 "Intrinsic has incorrect return type!", IF);
3170 for (
unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
3171 Assert(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef, ArgTys),
3172 "Intrinsic has incorrect argument type!", IF);
3176 Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),
3177 "Intrinsic was not defined with variable arguments!", IF);
3179 Assert(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),
3180 "Callsite was not defined with variable arguments!", IF);
3183 Assert(TableRef.
empty(),
"Intrinsic has too few arguments!", IF);
3191 "Intrinsic name not mangled correctly for type arguments! "
3198 for (Value *V : CS.
args())
3199 if (
auto *MD = dyn_cast<MetadataAsValue>(V))
3200 visitMetadataAsValue(*MD, CS.
getCaller());
3205 case Intrinsic::ctlz:
3206 case Intrinsic::cttz:
3208 "is_zero_undef argument of bit counting intrinsics must be a "
3212 case Intrinsic::dbg_declare:
3214 "invalid llvm.dbg.declare intrinsic call 1", CS);
3215 visitDbgIntrinsic(
"declare", cast<DbgDeclareInst>(*CS.
getInstruction()));
3217 case Intrinsic::dbg_value:
3218 visitDbgIntrinsic(
"value", cast<DbgValueInst>(*CS.
getInstruction()));
3220 case Intrinsic::memcpy:
3221 case Intrinsic::memmove:
3222 case Intrinsic::memset: {
3225 "alignment argument of memory intrinsics must be a constant int",
3229 "alignment argument of memory intrinsics must be a power of 2", CS);
3231 "isvolatile argument of memory intrinsics must be a constant int",
3235 case Intrinsic::gcroot:
3236 case Intrinsic::gcwrite:
3237 case Intrinsic::gcread:
3238 if (ID == Intrinsic::gcroot) {
3241 Assert(AI,
"llvm.gcroot parameter #1 must be an alloca.", CS);
3243 "llvm.gcroot parameter #2 must be a constant.", CS);
3246 "llvm.gcroot parameter #1 must either be a pointer alloca, "
3247 "or argument #2 must be a non-null constant.",
3253 "Enclosing function does not use GC.", CS);
3255 case Intrinsic::init_trampoline:
3257 "llvm.init_trampoline parameter #2 must resolve to a function.",
3263 cast<ConstantInt>(CS.
getArgOperand(1))->getZExtValue() < 2 &&
3265 "invalid arguments to llvm.prefetch", CS);
3267 case Intrinsic::stackprotector:
3269 "llvm.stackprotector parameter #2 must resolve to an alloca.", CS);
3271 case Intrinsic::lifetime_start:
3272 case Intrinsic::lifetime_end:
3273 case Intrinsic::invariant_start:
3275 "size argument of memory use markers must be a constant integer",
3278 case Intrinsic::invariant_end:
3280 "llvm.invariant.end parameter #2 must be a constant integer", CS);
3283 case Intrinsic::localescape: {
3286 "llvm.localescape used outside of entry block", CS);
3288 "multiple calls to llvm.localescape in one function", CS);
3289 for (Value *Arg : CS.
args()) {
3290 if (isa<ConstantPointerNull>(Arg))
3294 "llvm.localescape only accepts static allocas", CS);
3297 SawFrameEscape =
true;
3300 case Intrinsic::localrecover: {
3304 "llvm.localrecover first "
3305 "argument must be function defined in this module",
3308 Assert(IdxArg,
"idx argument of llvm.localrecover must be a constant int",
3310 auto &Entry = FrameEscapeInfo[Fn];
3312 std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1));
3316 case Intrinsic::experimental_gc_statepoint:
3318 "gc.statepoint support for inline assembly unimplemented", CS);
3320 "Enclosing function does not use GC.", CS);
3322 VerifyStatepoint(CS);
3324 case Intrinsic::experimental_gc_result_int:
3325 case Intrinsic::experimental_gc_result_float:
3326 case Intrinsic::experimental_gc_result_ptr:
3327 case Intrinsic::experimental_gc_result: {
3329 "Enclosing function does not use GC.", CS);
3333 StatepointCS.getInstruction() ? StatepointCS.getCalledFunction() :
nullptr;
3334 Assert(StatepointFn && StatepointFn->isDeclaration() &&
3335 StatepointFn->getIntrinsicID() ==
3336 Intrinsic::experimental_gc_statepoint,
3337 "gc.result operand #1 must be from a statepoint", CS,
3341 const Value *Target = StatepointCS.getArgument(2);
3342 const PointerType *PT = cast<PointerType>(Target->getType());
3345 Assert(CS.getType() == TargetFuncType->getReturnType(),
3346 "gc.result result type does not match wrapped callee", CS);
3349 case Intrinsic::experimental_gc_relocate: {
3350 Assert(CS.getNumArgOperands() == 3,
"wrong number of arguments", CS);
3356 dyn_cast<ExtractValueInst>(CS.getArgOperand(0))) {
3357 Assert(isa<LandingPadInst>(ExtractValue->getAggregateOperand()),
3358 "gc relocate on unwind path incorrectly linked to the statepoint",
3362 ExtractValue->
getParent()->getUniquePredecessor();
3366 Assert(InvokeBB,
"safepoints should have unique landingpads",
3371 "gc relocate should be linked to a statepoint", InvokeBB);
3377 auto Token = CS.getArgOperand(0);
3379 "gc relocate is incorrectly tied to the statepoint", CS, Token);
3388 Value* Base = CS.getArgOperand(1);
3389 Assert(isa<ConstantInt>(Base),
3390 "gc.relocate operand #2 must be integer offset", CS);
3392 Value* Derived = CS.getArgOperand(2);
3393 Assert(isa<ConstantInt>(Derived),
3394 "gc.relocate operand #3 must be integer offset", CS);
3396 const int BaseIndex = cast<ConstantInt>(Base)->getZExtValue();
3397 const int DerivedIndex = cast<ConstantInt>(Derived)->getZExtValue();
3399 Assert(0 <= BaseIndex && BaseIndex < (
int)StatepointCS.arg_size(),
3400 "gc.relocate: statepoint base index out of bounds", CS);
3401 Assert(0 <= DerivedIndex && DerivedIndex < (
int)StatepointCS.arg_size(),
3402 "gc.relocate: statepoint derived index out of bounds", CS);
3406 Assert(StatepointCS.arg_size() > 0,
3407 "gc.statepoint: insufficient arguments");
3408 Assert(isa<ConstantInt>(StatepointCS.getArgument(3)),
3409 "gc.statement: number of call arguments must be constant integer");
3410 const unsigned NumCallArgs =
3411 cast<ConstantInt>(StatepointCS.getArgument(3))->getZExtValue();
3412 Assert(StatepointCS.arg_size() > NumCallArgs + 5,
3413 "gc.statepoint: mismatch in number of call arguments");
3414 Assert(isa<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5)),
3415 "gc.statepoint: number of transition arguments must be "
3416 "a constant integer");
3417 const int NumTransitionArgs =
3418 cast<ConstantInt>(StatepointCS.getArgument(NumCallArgs + 5))
3420 const int DeoptArgsStart = 4 + NumCallArgs + 1 + NumTransitionArgs + 1;
3421 Assert(isa<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart)),
3422 "gc.statepoint: number of deoptimization arguments must be "
3423 "a constant integer");
3424 const int NumDeoptArgs =
3425 cast<ConstantInt>(StatepointCS.getArgument(DeoptArgsStart))->getZExtValue();
3426 const int GCParamArgsStart = DeoptArgsStart + 1 + NumDeoptArgs;
3427 const int GCParamArgsEnd = StatepointCS.arg_size();
3428 Assert(GCParamArgsStart <= BaseIndex && BaseIndex < GCParamArgsEnd,
3429 "gc.relocate: statepoint base index doesn't fall within the "
3430 "'gc parameters' section of the statepoint call",
3432 Assert(GCParamArgsStart <= DerivedIndex && DerivedIndex < GCParamArgsEnd,
3433 "gc.relocate: statepoint derived index doesn't fall within the "
3434 "'gc parameters' section of the statepoint call",
3442 "gc.relocate: relocated value must be a gc pointer", CS);
3446 Assert(cast<PointerType>(CS.getType())->getAddressSpace() ==
3447 cast<PointerType>(
Operands.getDerivedPtr()->getType())->getAddressSpace(),
3448 "gc.relocate: relocating a pointer shouldn't change its address space", CS);
3462 if (
auto *SP = dyn_cast<DISubprogram>(LocalScope))
3465 if (
auto *LB = dyn_cast<DILexicalBlockBase>(LocalScope))
3469 assert(!isa<DILocalScope>(LocalScope) &&
"Unknown type of local scope");
3473 template <
class DbgIntrinsicTy>
3474 void Verifier::visitDbgIntrinsic(
StringRef Kind, DbgIntrinsicTy &DII) {
3475 auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
3476 Assert(isa<ValueAsMetadata>(MD) ||
3477 (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
3478 "invalid llvm.dbg." + Kind +
" intrinsic address/value", &DII, MD);
3479 Assert(isa<DILocalVariable>(DII.getRawVariable()),
3480 "invalid llvm.dbg." + Kind +
" intrinsic variable", &DII,
3481 DII.getRawVariable());
3482 Assert(isa<DIExpression>(DII.getRawExpression()),
3483 "invalid llvm.dbg." + Kind +
" intrinsic expression", &DII,
3484 DII.getRawExpression());
3487 if (
MDNode *N = DII.getDebugLoc().getAsMDNode())
3488 if (!isa<DILocation>(N))
3497 Assert(Loc,
"llvm.dbg." + Kind +
" intrinsic requires a !dbg attachment",
3502 if (!VarSP || !LocSP)
3505 Assert(VarSP == LocSP,
"mismatched subprogram between llvm.dbg." + Kind +
3506 " variable and !dbg attachment",
3508 Loc->getScope()->getSubprogram());
3511 template <
class MapTy>
3517 if (
auto *T = dyn_cast<DIType>(RawType))
3518 if (uint64_t Size = T->getSizeInBits())
3521 if (
auto *DT = dyn_cast<DIDerivedType>(RawType)) {
3523 RawType = DT->getRawBaseType();
3527 if (
auto *S = dyn_cast<MDString>(RawType)) {
3529 RawType = Map.lookup(S);
3541 template <
class MapTy>
3543 const MapTy &TypeRefs) {
3546 if (
auto *DVI = dyn_cast<DbgValueInst>(&I)) {
3547 V = dyn_cast_or_null<DILocalVariable>(DVI->getRawVariable());
3548 E = dyn_cast_or_null<DIExpression>(DVI->getRawExpression());
3550 auto *DDI = cast<DbgDeclareInst>(&
I);
3551 V = dyn_cast_or_null<DILocalVariable>(DDI->getRawVariable());
3552 E = dyn_cast_or_null<DIExpression>(DDI->getRawExpression());
3556 if (!V || !E || !E->isValid())
3560 if (!E->isBitPiece())
3569 if (V->isArtificial())
3578 unsigned PieceSize = E->getBitPieceSize();
3579 unsigned PieceOffset = E->getBitPieceOffset();
3580 Assert(PieceSize + PieceOffset <= VarSize,
3581 "piece is larger than or outside of variable", &I, V, E);
3582 Assert(PieceSize != VarSize,
"piece covers entire variable", &I, V, E);
3585 void Verifier::visitUnresolvedTypeRef(
const MDString *S,
const MDNode *N) {
3588 Assert(
false,
"unresolved type ref", S, N);
3591 void Verifier::verifyTypeRefs() {
3598 for (
auto *CU : CUs->operands())
3599 if (
auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
3601 if (
auto *T = dyn_cast<DICompositeType>(Op))
3602 if (
auto *S = T->getRawIdentifier()) {
3603 UnresolvedTypeRefs.
erase(S);
3604 TypeRefs.
insert(std::make_pair(S, T));
3614 if (
auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
3615 verifyBitPieceExpression(*DII, TypeRefs);
3618 if (UnresolvedTypeRefs.empty())
3622 typedef std::pair<const MDString *, const MDNode *> TypeRef;
3624 UnresolvedTypeRefs.end());
3625 std::sort(Unresolved.begin(), Unresolved.end(),
3626 [](
const TypeRef &LHS,
const TypeRef &RHS) {
3627 return LHS.first->getString() < RHS.first->getString();
3631 for (
const TypeRef &TR : Unresolved)
3632 visitUnresolvedTypeRef(TR.first, TR.second);
3641 assert(!F.
isDeclaration() &&
"Cannot verify external functions");
3644 Verifier V(OS ? *OS : NullStr);
3648 return !V.verify(F);
3653 Verifier V(OS ? *OS : NullStr);
3655 bool Broken =
false;
3657 if (!I->isDeclaration() && !I->isMaterializable())
3658 Broken |= !V.verify(*I);
3662 return !V.verify(M) || Broken;
3675 explicit VerifierLegacyPass(
bool FatalErrors)
3680 bool runOnFunction(
Function &F)
override {
3681 if (!V.verify(F) && FatalErrors)
3687 bool doFinalization(
Module &M)
override {
3688 if (!V.verify(M) && FatalErrors)
3701 INITIALIZE_PASS(VerifierLegacyPass,
"verify",
"Module Verifier",
false,
false)
3704 return new VerifierLegacyPass(FatalErrors);
bool isInt< 32 >(int64_t x)
Metadata * getRawScope() const
DISubprogramArray getSubprograms() const
const Use & getOperandUse(unsigned i) const
ReturnInst - Return a value (possibly void), from a function.
bool describes(const Function *F) const
Check if this subprogram decribes the given function.
StringRef getName() const
void push_back(const T &Elt)
AtomicOrdering getFailureOrdering() const
Returns the ordering constraint on this cmpxchg.
LinkageTypes getLinkage() const
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
iterator_range< use_iterator > uses()
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
LLVM Argument representation.
Base class for instruction visitors.
Value * getAggregateOperand()
Alignment of stack for function (3 bits) stored as log2 of alignment with +1 bias 0 means unaligned (...
Type * getSourceElementType() const
SynchronizationScope getSynchScope() const
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
ArrayRef< unsigned > getIndices() const
Sign extended before/after call.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
ValTy * getArgument(unsigned ArgNo) const
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
isValidOperands - Return true if an insertelement instruction can be formed with the specified operan...
DITypeRef getType() const
Force argument to be passed in register.
A Module instance is used to store all the information related to an LLVM module. ...
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
Function is called early and/or often, so lazy binding isn't worthwhile.
AtomicOrdering getSuccessOrdering() const
Returns the ordering constraint on this cmpxchg.
FenceInst - an instruction for ordering other memory operations.
InstrTy * getInstruction() const
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
Metadata * getRawSubprograms() const
const T & front() const
front - Get the first element.
DILocalScope * getScope() const
Get the local scope for this variable.
This class represents zero extension of integer types.
unsigned getNumOperands() const
A raw_ostream that discards all output.
Nested function static chain.
unsigned getNumOperands() const
Return number of MDNode operands.
Type::subtype_iterator param_iterator
PTX_Device - Call to a PTX device function.
Metadata * getRawFile() const
Return the raw underlying file.
Type * getValueType() const
CallInst - This class represents a function call, abstracting a target machine's calling convention...
named_metadata_iterator named_metadata_end()
bool hasAppendingLinkage() const
Metadata * getRawType() const
FunctionPass * createVerifierPass(bool FatalErrors=true)
Create a verifier pass.
CaseIt case_begin()
Returns a read/write iterator that points to the first case in SwitchInst.
BBTy * getParent() const
Get the basic block containing the call site.
Source said inlining was desirable.
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
bool hasAvailableExternallyLinkage() const
iterator begin(unsigned Slot) const
bool isPtrOrPtrVectorTy() const
isPtrOrPtrVectorTy - Return true if this is a pointer type or a vector of pointer types...
Type * getReturnType() const
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
const Instruction & front() const
FunTy * getCaller() const
getCaller - Return the caller function for this call site
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
LoadInst - an instruction for reading from memory.
bool isValidMetadataNullArray(const MDTuple &N)
Typed, array-like tuple of metadata.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
VectorType::getTruncatedElementVectorType - This static method is like getInteger except that the ele...
void reserve(size_type N)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Metadata * getRawScope() const
const Constant * getAliasee() const
void print(raw_ostream &ROS) const
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
bool isFiniteNonZero() const
unsigned getColumn() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
Adds a requirement that another module flag be present and have a specified value after linking is pe...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Appends the two values, which are required to be metadata nodes.
Base class for DIDerivedType and DICompositeType.
This class represents a conversion between pointers from one address space to another.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
bool hasCommonLinkage() const
StringRef getName() const
SelectInst - This class represents the LLVM 'select' instruction.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const APInt & getValue() const
Return the constant as an APInt value reference.
NodeTy * getNextNode()
Get the next node, or 0 for the list tail.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool canLosslesslyBitCastTo(Type *Ty) const
canLosslesslyBitCastTo - Return true if this type could be converted with a lossless BitCast to type ...
Metadata * getRawRetainedTypes() const
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
DITypeArray getRetainedTypes() const
bool isMustTailCall() const
Function must be in a unwind table.
Type * getVectorElementType() const
StringRef getName() const
static const unsigned MaximumAlignment
Type * getPointerOperandType() const
getPointerOperandType - Method to return the pointer operand as a PointerType.
StringRef getName() const
Function does not access memory.
BasicBlock * getDestination(unsigned i)
getDestination - Return the specified destination.
Hidden pointer to structure to return.
DITypeRefArray getTypeArray() const
Function creates no aliases of pointer.
bool hasPrivateLinkage() const
SynchronizationScope getSynchScope() const
This class represents a cast from a pointer to an integer.
Metadata * getRawFile() const
global_iterator global_begin()
bool isStatepoint(const ImmutableCallSite &CS)
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
isValidOperands - Return true if a shufflevector instruction can be formed with the specified operand...
iterator_range< IterTy > args() const
void visit(Iterator Start, Iterator End)
Metadata * getRawStaticDataMemberDeclaration() const
ConstantExpr - a constant value that is initialized with an expression using other constant values...
FunctionType - Class to represent function types.
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
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...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
ArrayType - Class to represent array types.
unsigned getNumArgOperands() const
This instruction compares its operands according to the predicate given to the constructor.
PTX_Kernel - Call to a PTX kernel.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
bool isFirstClassType() const
isFirstClassType - Return true if the type is "first class", meaning it is a valid type for a Value...
This class represents a no-op cast from one type to another.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getNumClauses() const
getNumClauses - Get the number of clauses for this landing pad.
StoreInst - an instruction for storing to memory.
Metadata * getRawVTableHolder() const
This class represents a cast from floating point to signed integer.
bool isArrayTy() const
isArrayTy - True if this is an instance of ArrayType.
Metadata * getRawEnumTypes() const
unsigned getNumElements() const
Return the number of elements in the Vector type.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
DIScopeRef getScope() const
Type * getElementType() const
This class represents a truncation of integer types.
size_t size() const
size - Get the array size.
bool isAtomic() const
isAtomic - Return true if this instruction has an AtomicOrdering of unordered or higher.
BasicBlock * getNormalDest() const
PointerType - Class to represent pointers.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool isValidMetadataArray(const MDTuple &N)
Metadata * getRawScope() const
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool doesNotAccessMemory() const
Determine if the call does not access memory.
Value * stripPointerCastsNoFollowAliases()
Strip off pointer casts and all-zero GEPs.
bool isFilter(unsigned Idx) const
isFilter - Return 'true' if the clause and index Idx is a filter clause.
bool isX86_MMXTy() const
isX86_MMXTy - Return true if this is X86 MMX.
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
Metadata * getRawElements() const
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
Type * getParamType(unsigned i) const
Parameter type accessors.
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
static VectorType * getHalfElementsVectorType(VectorType *VTy)
VectorType::getHalfElementsVectorType - This static method returns a VectorType with half as many ele...
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Metadata * getRawFile() const
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
Subclasses of this class are all able to terminate a basic block.
An abstract set of preserved analyses following a transformation pass run.
alias_iterator alias_end()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
BranchInst - Conditional or Unconditional Branch instruction.
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
Type * getElementType(unsigned N) const
This is an important base class in LLVM.
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
Returns the module flags in the provided vector.
PointerType * getType() const
getType - Overload to return most specific pointer type
Metadata * getRawType() const
bool isGCRelocate(const Value *V)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IndirectBrInst - Indirect Branch Instruction.
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Base class for template parameters.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
unsigned getAlignment() const
getAlignment - Return the alignment of the memory that is being allocated by the instruction.
ConstantFP - Floating Point Values [float, double].
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Value * stripInBoundsOffsets()
Strip off pointer casts and inbounds GEPs.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool hasPersonalityFn() const
Get the personality function associated with this function.
Return value is always equal to this argument.
StringRef getFilename() const
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
static bool isValidLinkage(LinkageTypes L)
Metadata * getRawTemplateParams() const
Represent the analysis usage information of a pass.
Pass structure in an alloca.
static Type * getVoidTy(LLVMContext &C)
Type * getTypeAtIndex(const Value *V)
getTypeAtIndex - Given an index value into the type, return the type of the element.
This instruction compares its operands according to the predicate given to the constructor.
MDNode * getOperand(unsigned i) const
User * getUser() const
Returns the User that contains this Use.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Zero extended before/after call.
Interval::pred_iterator pred_end(Interval *I)
Base class for variables.
Function doesn't unwind stack.
Class to represent integer types.
Wraps a call to a gc.relocate and provides access to it's operands.
Predicate getPredicate() const
Return the predicate for this instruction.
DITypeRef getBaseType() const
bool pred_empty(const BasicBlock *BB)
bool empty() const
empty - Check if the array is empty.
Marks function as being in a cold path.
This class represents a cast from an integer to a pointer.
Mark the function as not returning.
static DISubprogram * getSubprogram(Metadata *LocalScope)
Carefully grab the subprogram from a local scope.
DINodeRef getEntity() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool isFPOrFPVectorTy() const
isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
PointerType * getPointerTo(unsigned AddrSpace=0)
getPointerTo - Return a pointer to the current type.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
ValTy * getArgOperand(unsigned i) const
Call cannot be duplicated.
FunctionType * getFunctionType() const
An imported module (C++ using directive or similar).
Base class for scope-like contexts.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool isConditional() const
global_iterator global_end()
bool verifyModule(const Module &M, raw_ostream *OS=nullptr)
Check a module for errors.
bool hasExternalWeakLinkage() const
DIImportedEntityArray getImportedEntities() const
BinaryOps getOpcode() const
StringRef getString() const
bool hasExternalLinkage() const
bool hasDLLImportStorageClass() const
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
const MDOperand & getOperand(unsigned I) const
BasicBlock * getUnwindDest() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
bool isFunctionTy() const
isFunctionTy - True if this is an instance of FunctionType.
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative. ...
unsigned getVectorNumElements() const
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Metadata * getRawInlinedAt() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isStaticAlloca() const
isStaticAlloca - Return true if this alloca is in the entry block of the function and is a constant s...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
MDNode * getMetadata(unsigned KindID) const
getMetadata - Get the metadata of given kind attached to this Instruction.
Callee is recognized as a builtin, despite nobuiltin attribute on its declaration.
iterator end(unsigned Slot) const
This class represents a range of values.
DbgInfoIntrinsic - This is the common base class for debug info intrinsics.
const APInt & getLower() const
Return the lower value for this range.
This class represents a cast from floating point to unsigned integer.
alias_iterator alias_begin()
unsigned arg_size() const
SequentialType * getType() const
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
BinOp getOperation() const
static VectorType * getExtendedElementVectorType(VectorType *VTy)
VectorType::getExtendedElementVectorType - This static method is like getInteger except that the elem...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Uses the specified value, regardless of the behavior or value of the other module.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias 0 means unaligned (different...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
VectorType - Class to represent vector types.
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
ConstantArray - Constant Array Declarations.
bool hasInitializer() const
Definitions have initializers, declarations don't.
A (clang) module that has been imported by the compile unit.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Function must not be optimized.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Emits a warning if two values disagree.
void setPreservesAll()
Set by analyses that do not transform their input at all.
PreservedAnalyses run(Module &M)
iterator_range< user_iterator > users()
Function only reads from memory.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Generic tagged DWARF-like metadata node.
Value * getCondition() const
bool isInlineAsm() const
isInlineAsm - Check if this call is an inline asm statement.
const AttributeSet & getAttributes() const
getAttributes - Return the parameter attributes for this call.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
MDNode * getAsMDNode() const
Return this as a bar MDNode.
Metadata * getRawVariable() const
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
static AttrBuilder getParameterABIAttributes(int I, AttributeSet Attrs)
Type array for a subprogram.
Metadata * getRawImportedEntities() const
Metadata * getRawScope() const
PointerType * getType() const
Global values are always pointers.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Value * getCondition() const
std::string getName(ID id, ArrayRef< Type * > Tys=None)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Appends the two values, which are required to be metadata nodes.
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
AttrBuilder typeIncompatible(const Type *Ty)
Which attributes cannot be applied to a type.
Callee isn't recognized as a builtin.
ImmutableCallSite - establish a view to a call site for examination.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
bool isCatch(unsigned Idx) const
isCatch - Return 'true' if the clause and index Idx is a catch clause.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool isLandingPad() const
Return true if this basic block is a landing pad.
FunctionType * getFunctionType() const
Fast - This calling convention attempts to make calls as fast as possible (e.g.
void initializeVerifierLegacyPassPass(PassRegistry &)
This class represents a cast unsigned integer to floating point.
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
const AttributeSet & getAttributes() const
getAttributes/setAttributes - get or set the parameter attributes of the call.
op_range operands() const
Funciton can access memory only using pointers based on its arguments.
FunctionType * getFunctionType() const
Metadata * getRawScope() const
SwitchInst - Multiway switch.
This class represents a cast from signed integer to floating point.
const APInt & getUpper() const
Return the upper value for this range.
Type * getReturnType() const
unsigned getAlignment() const
Function can return twice.
unsigned getFlags() const
const ARM::ArchExtKind Kind
const BasicBlock & front() const
This class represents a truncation of floating point types.
static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map)
DICompositeTypeArray getEnumTypes() const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
bool isLabelTy() const
isLabelTy - Return true if this is 'label'.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool hasUnnamedAddr() const
static bool hasConflictingReferenceFlags(unsigned Flags)
Disable implicit floating point insts.
const Value * getArraySize() const
getArraySize - Get the number of elements allocated.
unsigned getNumOperands() const
This class implements an extremely fast bulk output stream that can only output to a stream...
InvokeInst - Invoke instruction.
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
bool isCleanup() const
isCleanup - Return 'true' if this landingpad instruction is a cleanup.
C - The default llvm calling convention, compatible with C.
StringRef - Represent a constant reference to a string, i.e.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
This header defines various interfaces for pass management in LLVM.
bool isGCResult(const Value *V)
unsigned getNumElements() const
Random access to the elements.
DIGlobalVariableArray getGlobalVariables() const
Type * getAllocatedType() const
getAllocatedType - Return the type that is being allocated by the instruction.
op_range incoming_values()
This class represents an extension of floating point types.
bool isResolved() const
Check if node is fully resolved.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
Can only be moved to control-equivalent blocks.
A bitmask that includes all valid flags.
Stack protection required.
bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull)
bool isDeclarationForLinker() const
unsigned getNumDestinations() const
getNumDestinations - return the number of possible destinations in this indirectbr instruction...
bool isEmpty() const
Return true if there are no attributes.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
const BasicBlock * getParent() const
InstListType::iterator iterator
Instruction iterators...
Build jump-instruction tables and replace refs.
Type * getResultElementType() const
static cl::opt< bool > VerifyDebugInfo("verify-debug-info", cl::init(true))
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
named_metadata_iterator named_metadata_begin()
LLVMContext & getContext() const
Get the global data context.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
bool empty() const
empty - Check if the string is empty.
Metadata * getRawGlobalVariables() const
Basic type, like 'int' or 'float'.
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.
Metadata * getRawTypeArray() const
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
areInvalidOperands - Return a string if the specified operands are invalid for a select operation...
Function must be optimized for size first.