LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Verifier.cpp
Go to the documentation of this file.
1 //===-- Verifier.cpp - Implement the Module Verifier -----------------------==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the function verifier interface, that can be used for some
11 // sanity checking of input to the system.
12 //
13 // Note that this does not provide full `Java style' security and verifications,
14 // instead it just tries to ensure that code is well-formed.
15 //
16 // * Both of a binary operator's parameters are of the same type
17 // * Verify that the indices of mem access instructions match other operands
18 // * Verify that arithmetic and other things are only performed on first-class
19 // types. Verify that shifts & logicals only happen on integrals f.e.
20 // * All of the constants in a switch statement are of the correct type
21 // * The code is in valid SSA form
22 // * It should be illegal to put a label into any other type (like a structure)
23 // or to return one. [except constant arrays!]
24 // * Only phi nodes can be self referential: 'add i32 %0, %0 ; <int>:0' is bad
25 // * PHI nodes must have an entry for each predecessor, with no extras.
26 // * PHI nodes must be the first thing in a basic block, all grouped together
27 // * PHI nodes must have at least one entry
28 // * All basic blocks should only end with terminator insts, not contain them
29 // * The entry node to a function must not have predecessors
30 // * All Instructions must be embedded into a basic block
31 // * Functions cannot take a void-typed parameter
32 // * Verify that a function's argument list agrees with it's declared type.
33 // * It is illegal to specify a name for a void value.
34 // * It is illegal to have a internal global value with no initializer
35 // * It is illegal to have a ret instruction that returns a value that does not
36 // agree with the function return value type.
37 // * Function call argument types match the function prototype
38 // * A landing pad is defined by a landingpad instruction, and can be jumped to
39 // only by the unwind edge of an invoke instruction.
40 // * A landingpad instruction must be the first non-PHI instruction in the
41 // block.
42 // * All landingpad instructions must use the same personality function with
43 // the same function.
44 // * All other things that are tested by asserts spread about the code...
45 //
46 //===----------------------------------------------------------------------===//
47 
48 #include "llvm/Analysis/Verifier.h"
49 #include "llvm/ADT/STLExtras.h"
50 #include "llvm/ADT/SetVector.h"
51 #include "llvm/ADT/SmallPtrSet.h"
52 #include "llvm/ADT/SmallVector.h"
53 #include "llvm/ADT/StringExtras.h"
55 #include "llvm/Assembly/Writer.h"
56 #include "llvm/DebugInfo.h"
57 #include "llvm/IR/CallingConv.h"
58 #include "llvm/IR/Constants.h"
59 #include "llvm/IR/DataLayout.h"
60 #include "llvm/IR/DerivedTypes.h"
61 #include "llvm/IR/InlineAsm.h"
62 #include "llvm/IR/IntrinsicInst.h"
63 #include "llvm/IR/LLVMContext.h"
64 #include "llvm/IR/Metadata.h"
65 #include "llvm/IR/Module.h"
66 #include "llvm/InstVisitor.h"
67 #include "llvm/Pass.h"
68 #include "llvm/PassManager.h"
69 #include "llvm/Support/CFG.h"
70 #include "llvm/Support/CallSite.h"
73 #include "llvm/Support/Debug.h"
76 #include <algorithm>
77 #include <cstdarg>
78 using namespace llvm;
79 
80 static cl::opt<bool> DisableDebugInfoVerifier("disable-debug-info-verifier",
81  cl::init(true));
82 
83 namespace { // Anonymous namespace for class
84  struct PreVerifier : public FunctionPass {
85  static char ID; // Pass ID, replacement for typeid
86 
87  PreVerifier() : FunctionPass(ID) {
89  }
90 
91  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
92  AU.setPreservesAll();
93  }
94 
95  // Check that the prerequisites for successful DominatorTree construction
96  // are satisfied.
97  bool runOnFunction(Function &F) {
98  bool Broken = false;
99 
100  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
101  if (I->empty() || !I->back().isTerminator()) {
102  dbgs() << "Basic Block in function '" << F.getName()
103  << "' does not have terminator!\n";
104  WriteAsOperand(dbgs(), I, true);
105  dbgs() << "\n";
106  Broken = true;
107  }
108  }
109 
110  if (Broken)
111  report_fatal_error("Broken module, no Basic Block terminator!");
112 
113  return false;
114  }
115  };
116 }
117 
118 char PreVerifier::ID = 0;
119 INITIALIZE_PASS(PreVerifier, "preverify", "Preliminary module verification",
120  false, false)
121 static char &PreVerifyID = PreVerifier::ID;
122 
123 namespace {
124  struct Verifier : public FunctionPass, public InstVisitor<Verifier> {
125  static char ID; // Pass ID, replacement for typeid
126  bool Broken; // Is this module found to be broken?
127  VerifierFailureAction action;
128  // What to do if verification fails.
129  Module *Mod; // Module we are verifying right now
130  LLVMContext *Context; // Context within which we are verifying
131  DominatorTree *DT; // Dominator Tree, caution can be null!
132  const DataLayout *DL;
133 
134  std::string Messages;
135  raw_string_ostream MessagesStr;
136 
137  /// InstInThisBlock - when verifying a basic block, keep track of all of the
138  /// instructions we have seen so far. This allows us to do efficient
139  /// dominance checks for the case when an instruction has an operand that is
140  /// an instruction in the same block.
141  SmallPtrSet<Instruction*, 16> InstsInThisBlock;
142 
143  /// MDNodes - keep track of the metadata nodes that have been checked
144  /// already.
146 
147  /// PersonalityFn - The personality function referenced by the
148  /// LandingPadInsts. All LandingPadInsts within the same function must use
149  /// the same personality function.
150  const Value *PersonalityFn;
151 
152  /// Finder keeps track of all debug info MDNodes in a Module.
153  DebugInfoFinder Finder;
154 
155  Verifier()
156  : FunctionPass(ID), Broken(false),
157  action(AbortProcessAction), Mod(0), Context(0), DT(0), DL(0),
158  MessagesStr(Messages), PersonalityFn(0) {
160  }
161  explicit Verifier(VerifierFailureAction ctn)
162  : FunctionPass(ID), Broken(false), action(ctn), Mod(0),
163  Context(0), DT(0), DL(0), MessagesStr(Messages), PersonalityFn(0) {
165  }
166 
167  bool doInitialization(Module &M) {
168  Mod = &M;
169  Context = &M.getContext();
170 
171  DL = getAnalysisIfAvailable<DataLayout>();
172 
173  // We must abort before returning back to the pass manager, or else the
174  // pass manager may try to run other passes on the broken module.
175  return abortIfBroken();
176  }
177 
178  bool runOnFunction(Function &F) {
179  // Get dominator information if we are being run by PassManager
180  DT = &getAnalysis<DominatorTree>();
181 
182  Mod = F.getParent();
183  if (!Context) Context = &F.getContext();
184 
185  Finder.reset();
186  visit(F);
187  InstsInThisBlock.clear();
188  PersonalityFn = 0;
189 
191  // Verify Debug Info.
192  verifyDebugInfo();
193 
194  // We must abort before returning back to the pass manager, or else the
195  // pass manager may try to run other passes on the broken module.
196  return abortIfBroken();
197  }
198 
199  bool doFinalization(Module &M) {
200  // Scan through, checking all of the external function's linkage now...
201  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
202  visitGlobalValue(*I);
203 
204  // Check to make sure function prototypes are okay.
205  if (I->isDeclaration()) visitFunction(*I);
206  }
207 
208  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
209  I != E; ++I)
210  visitGlobalVariable(*I);
211 
212  for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
213  I != E; ++I)
214  visitGlobalAlias(*I);
215 
217  E = M.named_metadata_end(); I != E; ++I)
218  visitNamedMDNode(*I);
219 
220  visitModuleFlags(M);
221  visitModuleIdents(M);
222 
224  Finder.reset();
225  Finder.processModule(M);
226  // Verify Debug Info.
227  verifyDebugInfo();
228  }
229 
230  // If the module is broken, abort at this time.
231  return abortIfBroken();
232  }
233 
234  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
235  AU.setPreservesAll();
236  AU.addRequiredID(PreVerifyID);
238  }
239 
240  /// abortIfBroken - If the module is broken and we are supposed to abort on
241  /// this condition, do so.
242  ///
243  bool abortIfBroken() {
244  if (!Broken) return false;
245  MessagesStr << "Broken module found, ";
246  switch (action) {
247  case AbortProcessAction:
248  MessagesStr << "compilation aborted!\n";
249  dbgs() << MessagesStr.str();
250  // Client should choose different reaction if abort is not desired
251  abort();
252  case PrintMessageAction:
253  MessagesStr << "verification continues.\n";
254  dbgs() << MessagesStr.str();
255  return false;
256  case ReturnStatusAction:
257  MessagesStr << "compilation terminated.\n";
258  return true;
259  }
260  llvm_unreachable("Invalid action");
261  }
262 
263 
264  // Verification methods...
265  void visitGlobalValue(GlobalValue &GV);
266  void visitGlobalVariable(GlobalVariable &GV);
267  void visitGlobalAlias(GlobalAlias &GA);
268  void visitNamedMDNode(NamedMDNode &NMD);
269  void visitMDNode(MDNode &MD, Function *F);
270  void visitModuleIdents(Module &M);
271  void visitModuleFlags(Module &M);
272  void visitModuleFlag(MDNode *Op, DenseMap<MDString*, MDNode*> &SeenIDs,
273  SmallVectorImpl<MDNode*> &Requirements);
274  void visitFunction(Function &F);
275  void visitBasicBlock(BasicBlock &BB);
277 
278  void visit(Instruction &I);
279 
280  void visitTruncInst(TruncInst &I);
281  void visitZExtInst(ZExtInst &I);
282  void visitSExtInst(SExtInst &I);
283  void visitFPTruncInst(FPTruncInst &I);
284  void visitFPExtInst(FPExtInst &I);
285  void visitFPToUIInst(FPToUIInst &I);
286  void visitFPToSIInst(FPToSIInst &I);
287  void visitUIToFPInst(UIToFPInst &I);
288  void visitSIToFPInst(SIToFPInst &I);
289  void visitIntToPtrInst(IntToPtrInst &I);
290  void visitPtrToIntInst(PtrToIntInst &I);
291  void visitBitCastInst(BitCastInst &I);
292  void visitAddrSpaceCastInst(AddrSpaceCastInst &I);
293  void visitPHINode(PHINode &PN);
294  void visitBinaryOperator(BinaryOperator &B);
295  void visitICmpInst(ICmpInst &IC);
296  void visitFCmpInst(FCmpInst &FC);
297  void visitExtractElementInst(ExtractElementInst &EI);
298  void visitInsertElementInst(InsertElementInst &EI);
299  void visitShuffleVectorInst(ShuffleVectorInst &EI);
300  void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); }
301  void visitCallInst(CallInst &CI);
302  void visitInvokeInst(InvokeInst &II);
303  void visitGetElementPtrInst(GetElementPtrInst &GEP);
304  void visitLoadInst(LoadInst &LI);
305  void visitStoreInst(StoreInst &SI);
306  void verifyDominatesUse(Instruction &I, unsigned i);
307  void visitInstruction(Instruction &I);
308  void visitTerminatorInst(TerminatorInst &I);
309  void visitBranchInst(BranchInst &BI);
310  void visitReturnInst(ReturnInst &RI);
311  void visitSwitchInst(SwitchInst &SI);
312  void visitIndirectBrInst(IndirectBrInst &BI);
313  void visitSelectInst(SelectInst &SI);
314  void visitUserOp1(Instruction &I);
315  void visitUserOp2(Instruction &I) { visitUserOp1(I); }
316  void visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI);
317  void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
318  void visitAtomicRMWInst(AtomicRMWInst &RMWI);
319  void visitFenceInst(FenceInst &FI);
320  void visitAllocaInst(AllocaInst &AI);
321  void visitExtractValueInst(ExtractValueInst &EVI);
322  void visitInsertValueInst(InsertValueInst &IVI);
323  void visitLandingPadInst(LandingPadInst &LPI);
324 
325  void VerifyCallSite(CallSite CS);
326  bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty,
327  int VT, unsigned ArgNo, std::string &Suffix);
328  bool VerifyIntrinsicType(Type *Ty,
330  SmallVectorImpl<Type*> &ArgTys);
331  bool VerifyIntrinsicIsVarArg(bool isVarArg,
333  bool VerifyAttributeCount(AttributeSet Attrs, unsigned Params);
334  void VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
335  bool isFunction, const Value *V);
336  void VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
337  bool isReturnValue, const Value *V);
338  void VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs,
339  const Value *V);
340 
341  void VerifyBitcastType(const Value *V, Type *DestTy, Type *SrcTy);
342  void VerifyConstantExprBitcastType(const ConstantExpr *CE);
343 
344  void verifyDebugInfo();
345 
346  void WriteValue(const Value *V) {
347  if (!V) return;
348  if (isa<Instruction>(V)) {
349  MessagesStr << *V << '\n';
350  } else {
351  WriteAsOperand(MessagesStr, V, true, Mod);
352  MessagesStr << '\n';
353  }
354  }
355 
356  void WriteType(Type *T) {
357  if (!T) return;
358  MessagesStr << ' ' << *T;
359  }
360 
361 
362  // CheckFailed - A check failed, so print out the condition and the message
363  // that failed. This provides a nice place to put a breakpoint if you want
364  // to see why something is not correct.
365  void CheckFailed(const Twine &Message,
366  const Value *V1 = 0, const Value *V2 = 0,
367  const Value *V3 = 0, const Value *V4 = 0) {
368  MessagesStr << Message.str() << "\n";
369  WriteValue(V1);
370  WriteValue(V2);
371  WriteValue(V3);
372  WriteValue(V4);
373  Broken = true;
374  }
375 
376  void CheckFailed(const Twine &Message, const Value *V1,
377  Type *T2, const Value *V3 = 0) {
378  MessagesStr << Message.str() << "\n";
379  WriteValue(V1);
380  WriteType(T2);
381  WriteValue(V3);
382  Broken = true;
383  }
384 
385  void CheckFailed(const Twine &Message, Type *T1,
386  Type *T2 = 0, Type *T3 = 0) {
387  MessagesStr << Message.str() << "\n";
388  WriteType(T1);
389  WriteType(T2);
390  WriteType(T3);
391  Broken = true;
392  }
393  };
394 } // End anonymous namespace
395 
396 char Verifier::ID = 0;
397 INITIALIZE_PASS_BEGIN(Verifier, "verify", "Module Verifier", false, false)
398 INITIALIZE_PASS_DEPENDENCY(PreVerifier)
400 INITIALIZE_PASS_END(Verifier, "verify", "Module Verifier", false, false)
401 
402 // Assert - We know that cond should be true, if not print an error message.
403 #define Assert(C, M) \
404  do { if (!(C)) { CheckFailed(M); return; } } while (0)
405 #define Assert1(C, M, V1) \
406  do { if (!(C)) { CheckFailed(M, V1); return; } } while (0)
407 #define Assert2(C, M, V1, V2) \
408  do { if (!(C)) { CheckFailed(M, V1, V2); return; } } while (0)
409 #define Assert3(C, M, V1, V2, V3) \
410  do { if (!(C)) { CheckFailed(M, V1, V2, V3); return; } } while (0)
411 #define Assert4(C, M, V1, V2, V3, V4) \
412  do { if (!(C)) { CheckFailed(M, V1, V2, V3, V4); return; } } while (0)
413 
414 void Verifier::visit(Instruction &I) {
415  for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
416  Assert1(I.getOperand(i) != 0, "Operand is null", &I);
418 }
419 
420 
421 void Verifier::visitGlobalValue(GlobalValue &GV) {
422  Assert1(!GV.isDeclaration() ||
423  GV.isMaterializable() ||
424  GV.hasExternalLinkage() ||
425  GV.hasDLLImportLinkage() ||
426  GV.hasExternalWeakLinkage() ||
427  (isa<GlobalAlias>(GV) &&
428  (GV.hasLocalLinkage() || GV.hasWeakLinkage())),
429  "Global is external, but doesn't have external or dllimport or weak linkage!",
430  &GV);
431 
433  "Global is marked as dllimport, but not external", &GV);
434 
435  Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
436  "Only global variables can have appending linkage!", &GV);
437 
438  if (GV.hasAppendingLinkage()) {
439  GlobalVariable *GVar = dyn_cast<GlobalVariable>(&GV);
440  Assert1(GVar && GVar->getType()->getElementType()->isArrayTy(),
441  "Only global arrays can have appending linkage!", GVar);
442  }
443 }
444 
445 void Verifier::visitGlobalVariable(GlobalVariable &GV) {
446  if (GV.hasInitializer()) {
448  "Global variable initializer type does not match global "
449  "variable type!", &GV);
450 
451  // If the global has common linkage, it must have a zero initializer and
452  // cannot be constant.
453  if (GV.hasCommonLinkage()) {
455  "'common' global must have a zero initializer!", &GV);
456  Assert1(!GV.isConstant(), "'common' global may not be marked constant!",
457  &GV);
458  }
459  } else {
462  "invalid linkage type for global declaration", &GV);
463  }
464 
465  if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
466  GV.getName() == "llvm.global_dtors")) {
468  "invalid linkage for intrinsic global variable", &GV);
469  // Don't worry about emitting an error for it not being an array,
470  // visitGlobalValue will complain on appending non-array.
471  if (ArrayType *ATy = dyn_cast<ArrayType>(GV.getType())) {
472  StructType *STy = dyn_cast<StructType>(ATy->getElementType());
473  PointerType *FuncPtrTy =
474  FunctionType::get(Type::getVoidTy(*Context), false)->getPointerTo();
475  Assert1(STy && STy->getNumElements() == 2 &&
476  STy->getTypeAtIndex(0u)->isIntegerTy(32) &&
477  STy->getTypeAtIndex(1) == FuncPtrTy,
478  "wrong type for intrinsic global variable", &GV);
479  }
480  }
481 
482  if (GV.hasName() && (GV.getName() == "llvm.used" ||
483  GV.getName() == "llvm.compiler.used")) {
485  "invalid linkage for intrinsic global variable", &GV);
486  Type *GVType = GV.getType()->getElementType();
487  if (ArrayType *ATy = dyn_cast<ArrayType>(GVType)) {
488  PointerType *PTy = dyn_cast<PointerType>(ATy->getElementType());
489  Assert1(PTy, "wrong type for intrinsic global variable", &GV);
490  if (GV.hasInitializer()) {
491  Constant *Init = GV.getInitializer();
492  ConstantArray *InitArray = dyn_cast<ConstantArray>(Init);
493  Assert1(InitArray, "wrong initalizer for intrinsic global variable",
494  Init);
495  for (unsigned i = 0, e = InitArray->getNumOperands(); i != e; ++i) {
497  Assert1(
498  isa<GlobalVariable>(V) || isa<Function>(V) || isa<GlobalAlias>(V),
499  "invalid llvm.used member", V);
500  Assert1(V->hasName(), "members of llvm.used must be named", V);
501  }
502  }
503  }
504  }
505 
506  if (!GV.hasInitializer()) {
507  visitGlobalValue(GV);
508  return;
509  }
510 
511  // Walk any aggregate initializers looking for bitcasts between address spaces
514  WorkStack.push_back(cast<Value>(GV.getInitializer()));
515 
516  while (!WorkStack.empty()) {
517  const Value *V = WorkStack.pop_back_val();
518  if (!Visited.insert(V))
519  continue;
520 
521  if (const User *U = dyn_cast<User>(V)) {
522  for (unsigned I = 0, N = U->getNumOperands(); I != N; ++I)
523  WorkStack.push_back(U->getOperand(I));
524  }
525 
526  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
527  VerifyConstantExprBitcastType(CE);
528  if (Broken)
529  return;
530  }
531  }
532 
533  visitGlobalValue(GV);
534 }
535 
536 void Verifier::visitGlobalAlias(GlobalAlias &GA) {
537  Assert1(!GA.getName().empty(),
538  "Alias name cannot be empty!", &GA);
540  "Alias should have external or external weak linkage!", &GA);
541  Assert1(GA.getAliasee(),
542  "Aliasee cannot be NULL!", &GA);
543  Assert1(GA.getType() == GA.getAliasee()->getType(),
544  "Alias and aliasee types should match!", &GA);
545  Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA);
546 
547  Constant *Aliasee = GA.getAliasee();
548 
549  if (!isa<GlobalValue>(Aliasee)) {
550  ConstantExpr *CE = dyn_cast<ConstantExpr>(Aliasee);
551  Assert1(CE &&
552  (CE->getOpcode() == Instruction::BitCast ||
553  CE->getOpcode() == Instruction::GetElementPtr) &&
554  isa<GlobalValue>(CE->getOperand(0)),
555  "Aliasee should be either GlobalValue or bitcast of GlobalValue",
556  &GA);
557 
558  if (CE->getOpcode() == Instruction::BitCast) {
559  unsigned SrcAS = CE->getOperand(0)->getType()->getPointerAddressSpace();
560  unsigned DstAS = CE->getType()->getPointerAddressSpace();
561 
562  Assert1(SrcAS == DstAS,
563  "Alias bitcasts cannot be between different address spaces",
564  &GA);
565  }
566  }
567 
568  const GlobalValue* Resolved = GA.resolveAliasedGlobal(/*stopOnWeak*/ false);
569  Assert1(Resolved,
570  "Aliasing chain should end with function or global variable", &GA);
571 
572  visitGlobalValue(GA);
573 }
574 
575 void Verifier::visitNamedMDNode(NamedMDNode &NMD) {
576  for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) {
577  MDNode *MD = NMD.getOperand(i);
578  if (!MD)
579  continue;
580 
581  Assert1(!MD->isFunctionLocal(),
582  "Named metadata operand cannot be function local!", MD);
583  visitMDNode(*MD, 0);
584  }
585 }
586 
587 void Verifier::visitMDNode(MDNode &MD, Function *F) {
588  // Only visit each node once. Metadata can be mutually recursive, so this
589  // avoids infinite recursion here, as well as being an optimization.
590  if (!MDNodes.insert(&MD))
591  return;
592 
593  for (unsigned i = 0, e = MD.getNumOperands(); i != e; ++i) {
594  Value *Op = MD.getOperand(i);
595  if (!Op)
596  continue;
597  if (isa<Constant>(Op) || isa<MDString>(Op))
598  continue;
599  if (MDNode *N = dyn_cast<MDNode>(Op)) {
600  Assert2(MD.isFunctionLocal() || !N->isFunctionLocal(),
601  "Global metadata operand cannot be function local!", &MD, N);
602  visitMDNode(*N, F);
603  continue;
604  }
605  Assert2(MD.isFunctionLocal(), "Invalid operand for global metadata!", &MD, Op);
606 
607  // If this was an instruction, bb, or argument, verify that it is in the
608  // function that we expect.
609  Function *ActualF = 0;
610  if (Instruction *I = dyn_cast<Instruction>(Op))
611  ActualF = I->getParent()->getParent();
612  else if (BasicBlock *BB = dyn_cast<BasicBlock>(Op))
613  ActualF = BB->getParent();
614  else if (Argument *A = dyn_cast<Argument>(Op))
615  ActualF = A->getParent();
616  assert(ActualF && "Unimplemented function local metadata case!");
617 
618  Assert2(ActualF == F, "function-local metadata used in wrong function",
619  &MD, Op);
620  }
621 }
622 
623 void Verifier::visitModuleIdents(Module &M) {
624  const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident");
625  if (!Idents)
626  return;
627 
628  // llvm.ident takes a list of metadata entry. Each entry has only one string.
629  // Scan each llvm.ident entry and make sure that this requirement is met.
630  for (unsigned i = 0, e = Idents->getNumOperands(); i != e; ++i) {
631  const MDNode *N = Idents->getOperand(i);
632  Assert1(N->getNumOperands() == 1,
633  "incorrect number of operands in llvm.ident metadata", N);
634  Assert1(isa<MDString>(N->getOperand(0)),
635  ("invalid value for llvm.ident metadata entry operand"
636  "(the operand should be a string)"),
637  N->getOperand(0));
638  }
639 }
640 
641 void Verifier::visitModuleFlags(Module &M) {
643  if (!Flags) return;
644 
645  // Scan each flag, and track the flags and requirements.
647  SmallVector<MDNode*, 16> Requirements;
648  for (unsigned I = 0, E = Flags->getNumOperands(); I != E; ++I) {
649  visitModuleFlag(Flags->getOperand(I), SeenIDs, Requirements);
650  }
651 
652  // Validate that the requirements in the module are valid.
653  for (unsigned I = 0, E = Requirements.size(); I != E; ++I) {
654  MDNode *Requirement = Requirements[I];
655  MDString *Flag = cast<MDString>(Requirement->getOperand(0));
656  Value *ReqValue = Requirement->getOperand(1);
657 
658  MDNode *Op = SeenIDs.lookup(Flag);
659  if (!Op) {
660  CheckFailed("invalid requirement on flag, flag is not present in module",
661  Flag);
662  continue;
663  }
664 
665  if (Op->getOperand(2) != ReqValue) {
666  CheckFailed(("invalid requirement on flag, "
667  "flag does not have the required value"),
668  Flag);
669  continue;
670  }
671  }
672 }
673 
674 void Verifier::visitModuleFlag(MDNode *Op, DenseMap<MDString*, MDNode*>&SeenIDs,
675  SmallVectorImpl<MDNode*> &Requirements) {
676  // Each module flag should have three arguments, the merge behavior (a
677  // constant int), the flag ID (an MDString), and the value.
678  Assert1(Op->getNumOperands() == 3,
679  "incorrect number of operands in module flag", Op);
680  ConstantInt *Behavior = dyn_cast<ConstantInt>(Op->getOperand(0));
681  MDString *ID = dyn_cast<MDString>(Op->getOperand(1));
682  Assert1(Behavior,
683  "invalid behavior operand in module flag (expected constant integer)",
684  Op->getOperand(0));
685  unsigned BehaviorValue = Behavior->getZExtValue();
686  Assert1(ID,
687  "invalid ID operand in module flag (expected metadata string)",
688  Op->getOperand(1));
689 
690  // Sanity check the values for behaviors with additional requirements.
691  switch (BehaviorValue) {
692  default:
693  Assert1(false,
694  "invalid behavior operand in module flag (unexpected constant)",
695  Op->getOperand(0));
696  break;
697 
698  case Module::Error:
699  case Module::Warning:
700  case Module::Override:
701  // These behavior types accept any value.
702  break;
703 
704  case Module::Require: {
705  // The value should itself be an MDNode with two operands, a flag ID (an
706  // MDString), and a value.
707  MDNode *Value = dyn_cast<MDNode>(Op->getOperand(2));
708  Assert1(Value && Value->getNumOperands() == 2,
709  "invalid value for 'require' module flag (expected metadata pair)",
710  Op->getOperand(2));
711  Assert1(isa<MDString>(Value->getOperand(0)),
712  ("invalid value for 'require' module flag "
713  "(first value operand should be a string)"),
714  Value->getOperand(0));
715 
716  // Append it to the list of requirements, to check once all module flags are
717  // scanned.
718  Requirements.push_back(Value);
719  break;
720  }
721 
722  case Module::Append:
723  case Module::AppendUnique: {
724  // These behavior types require the operand be an MDNode.
725  Assert1(isa<MDNode>(Op->getOperand(2)),
726  "invalid value for 'append'-type module flag "
727  "(expected a metadata node)", Op->getOperand(2));
728  break;
729  }
730  }
731 
732  // Unless this is a "requires" flag, check the ID is unique.
733  if (BehaviorValue != Module::Require) {
734  bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second;
735  Assert1(Inserted,
736  "module flag identifiers must be unique (or of 'require' type)",
737  ID);
738  }
739 }
740 
741 void Verifier::VerifyAttributeTypes(AttributeSet Attrs, unsigned Idx,
742  bool isFunction, const Value *V) {
743  unsigned Slot = ~0U;
744  for (unsigned I = 0, E = Attrs.getNumSlots(); I != E; ++I)
745  if (Attrs.getSlotIndex(I) == Idx) {
746  Slot = I;
747  break;
748  }
749 
750  assert(Slot != ~0U && "Attribute set inconsistency!");
751 
752  for (AttributeSet::iterator I = Attrs.begin(Slot), E = Attrs.end(Slot);
753  I != E; ++I) {
754  if (I->isStringAttribute())
755  continue;
756 
757  if (I->getKindAsEnum() == Attribute::NoReturn ||
758  I->getKindAsEnum() == Attribute::NoUnwind ||
759  I->getKindAsEnum() == Attribute::NoInline ||
760  I->getKindAsEnum() == Attribute::AlwaysInline ||
761  I->getKindAsEnum() == Attribute::OptimizeForSize ||
762  I->getKindAsEnum() == Attribute::StackProtect ||
763  I->getKindAsEnum() == Attribute::StackProtectReq ||
764  I->getKindAsEnum() == Attribute::StackProtectStrong ||
765  I->getKindAsEnum() == Attribute::NoRedZone ||
766  I->getKindAsEnum() == Attribute::NoImplicitFloat ||
767  I->getKindAsEnum() == Attribute::Naked ||
768  I->getKindAsEnum() == Attribute::InlineHint ||
769  I->getKindAsEnum() == Attribute::StackAlignment ||
770  I->getKindAsEnum() == Attribute::UWTable ||
771  I->getKindAsEnum() == Attribute::NonLazyBind ||
772  I->getKindAsEnum() == Attribute::ReturnsTwice ||
773  I->getKindAsEnum() == Attribute::SanitizeAddress ||
774  I->getKindAsEnum() == Attribute::SanitizeThread ||
775  I->getKindAsEnum() == Attribute::SanitizeMemory ||
776  I->getKindAsEnum() == Attribute::MinSize ||
777  I->getKindAsEnum() == Attribute::NoDuplicate ||
778  I->getKindAsEnum() == Attribute::Builtin ||
779  I->getKindAsEnum() == Attribute::NoBuiltin ||
780  I->getKindAsEnum() == Attribute::Cold ||
781  I->getKindAsEnum() == Attribute::OptimizeNone) {
782  if (!isFunction) {
783  CheckFailed("Attribute '" + I->getAsString() +
784  "' only applies to functions!", V);
785  return;
786  }
787  } else if (I->getKindAsEnum() == Attribute::ReadOnly ||
788  I->getKindAsEnum() == Attribute::ReadNone) {
789  if (Idx == 0) {
790  CheckFailed("Attribute '" + I->getAsString() +
791  "' does not apply to function returns");
792  return;
793  }
794  } else if (isFunction) {
795  CheckFailed("Attribute '" + I->getAsString() +
796  "' does not apply to functions!", V);
797  return;
798  }
799  }
800 }
801 
802 // VerifyParameterAttrs - Check the given attributes for an argument or return
803 // value of the specified type. The value V is printed in error messages.
804 void Verifier::VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
805  bool isReturnValue, const Value *V) {
806  if (!Attrs.hasAttributes(Idx))
807  return;
808 
809  VerifyAttributeTypes(Attrs, Idx, false, V);
810 
811  if (isReturnValue)
812  Assert1(!Attrs.hasAttribute(Idx, Attribute::ByVal) &&
813  !Attrs.hasAttribute(Idx, Attribute::Nest) &&
814  !Attrs.hasAttribute(Idx, Attribute::StructRet) &&
815  !Attrs.hasAttribute(Idx, Attribute::NoCapture) &&
816  !Attrs.hasAttribute(Idx, Attribute::Returned),
817  "Attribute 'byval', 'nest', 'sret', 'nocapture', and 'returned' "
818  "do not apply to return values!", V);
819 
820  // Check for mutually incompatible attributes.
821  Assert1(!((Attrs.hasAttribute(Idx, Attribute::ByVal) &&
822  Attrs.hasAttribute(Idx, Attribute::Nest)) ||
823  (Attrs.hasAttribute(Idx, Attribute::ByVal) &&
824  Attrs.hasAttribute(Idx, Attribute::StructRet)) ||
825  (Attrs.hasAttribute(Idx, Attribute::Nest) &&
826  Attrs.hasAttribute(Idx, Attribute::StructRet))), "Attributes "
827  "'byval, nest, and sret' are incompatible!", V);
828 
829  Assert1(!((Attrs.hasAttribute(Idx, Attribute::ByVal) &&
830  Attrs.hasAttribute(Idx, Attribute::Nest)) ||
831  (Attrs.hasAttribute(Idx, Attribute::ByVal) &&
832  Attrs.hasAttribute(Idx, Attribute::InReg)) ||
833  (Attrs.hasAttribute(Idx, Attribute::Nest) &&
834  Attrs.hasAttribute(Idx, Attribute::InReg))), "Attributes "
835  "'byval, nest, and inreg' are incompatible!", V);
836 
837  Assert1(!(Attrs.hasAttribute(Idx, Attribute::StructRet) &&
838  Attrs.hasAttribute(Idx, Attribute::Returned)), "Attributes "
839  "'sret and returned' are incompatible!", V);
840 
841  Assert1(!(Attrs.hasAttribute(Idx, Attribute::ZExt) &&
842  Attrs.hasAttribute(Idx, Attribute::SExt)), "Attributes "
843  "'zeroext and signext' are incompatible!", V);
844 
845  Assert1(!(Attrs.hasAttribute(Idx, Attribute::ReadNone) &&
846  Attrs.hasAttribute(Idx, Attribute::ReadOnly)), "Attributes "
847  "'readnone and readonly' are incompatible!", V);
848 
849  Assert1(!(Attrs.hasAttribute(Idx, Attribute::NoInline) &&
850  Attrs.hasAttribute(Idx, Attribute::AlwaysInline)), "Attributes "
851  "'noinline and alwaysinline' are incompatible!", V);
852 
853  Assert1(!AttrBuilder(Attrs, Idx).
854  hasAttributes(AttributeFuncs::typeIncompatible(Ty, Idx), Idx),
855  "Wrong types for attribute: " +
856  AttributeFuncs::typeIncompatible(Ty, Idx).getAsString(Idx), V);
857 
858  if (PointerType *PTy = dyn_cast<PointerType>(Ty))
859  Assert1(!Attrs.hasAttribute(Idx, Attribute::ByVal) ||
860  PTy->getElementType()->isSized(),
861  "Attribute 'byval' does not support unsized types!", V);
862  else
864  "Attribute 'byval' only applies to parameters with pointer type!",
865  V);
866 }
867 
868 // VerifyFunctionAttrs - Check parameter attributes against a function type.
869 // The value V is printed in error messages.
870 void Verifier::VerifyFunctionAttrs(FunctionType *FT, AttributeSet Attrs,
871  const Value *V) {
872  if (Attrs.isEmpty())
873  return;
874 
875  bool SawNest = false;
876  bool SawReturned = false;
877 
878  for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
879  unsigned Idx = Attrs.getSlotIndex(i);
880 
881  Type *Ty;
882  if (Idx == 0)
883  Ty = FT->getReturnType();
884  else if (Idx-1 < FT->getNumParams())
885  Ty = FT->getParamType(Idx-1);
886  else
887  break; // VarArgs attributes, verified elsewhere.
888 
889  VerifyParameterAttrs(Attrs, Idx, Ty, Idx == 0, V);
890 
891  if (Idx == 0)
892  continue;
893 
894  if (Attrs.hasAttribute(Idx, Attribute::Nest)) {
895  Assert1(!SawNest, "More than one parameter has attribute nest!", V);
896  SawNest = true;
897  }
898 
899  if (Attrs.hasAttribute(Idx, Attribute::Returned)) {
900  Assert1(!SawReturned, "More than one parameter has attribute returned!",
901  V);
902  Assert1(Ty->canLosslesslyBitCastTo(FT->getReturnType()), "Incompatible "
903  "argument and return types for 'returned' attribute", V);
904  SawReturned = true;
905  }
906 
907  if (Attrs.hasAttribute(Idx, Attribute::StructRet))
908  Assert1(Idx == 1, "Attribute sret is not on first parameter!", V);
909  }
910 
911  if (!Attrs.hasAttributes(AttributeSet::FunctionIndex))
912  return;
913 
914  VerifyAttributeTypes(Attrs, AttributeSet::FunctionIndex, true, V);
915 
916  Assert1(!(Attrs.hasAttribute(AttributeSet::FunctionIndex,
918  Attrs.hasAttribute(AttributeSet::FunctionIndex,
920  "Attributes 'readnone and readonly' are incompatible!", V);
921 
922  Assert1(!(Attrs.hasAttribute(AttributeSet::FunctionIndex,
924  Attrs.hasAttribute(AttributeSet::FunctionIndex,
926  "Attributes 'noinline and alwaysinline' are incompatible!", V);
927 
928  if (Attrs.hasAttribute(AttributeSet::FunctionIndex,
930  Assert1(Attrs.hasAttribute(AttributeSet::FunctionIndex,
932  "Attribute 'optnone' requires 'noinline'!", V);
933 
934  Assert1(!Attrs.hasAttribute(AttributeSet::FunctionIndex,
936  "Attributes 'optsize and optnone' are incompatible!", V);
937 
938  Assert1(!Attrs.hasAttribute(AttributeSet::FunctionIndex,
940  "Attributes 'minsize and optnone' are incompatible!", V);
941  }
942 }
943 
944 void Verifier::VerifyBitcastType(const Value *V, Type *DestTy, Type *SrcTy) {
945  // Get the size of the types in bits, we'll need this later
946  unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits();
947  unsigned DestBitSize = DestTy->getPrimitiveSizeInBits();
948 
949  // BitCast implies a no-op cast of type only. No bits change.
950  // However, you can't cast pointers to anything but pointers.
951  Assert1(SrcTy->isPointerTy() == DestTy->isPointerTy(),
952  "Bitcast requires both operands to be pointer or neither", V);
953  Assert1(SrcBitSize == DestBitSize,
954  "Bitcast requires types of same width", V);
955 
956  // Disallow aggregates.
957  Assert1(!SrcTy->isAggregateType(),
958  "Bitcast operand must not be aggregate", V);
959  Assert1(!DestTy->isAggregateType(),
960  "Bitcast type must not be aggregate", V);
961 
962  // Without datalayout, assume all address spaces are the same size.
963  // Don't check if both types are not pointers.
964  // Skip casts between scalars and vectors.
965  if (!DL ||
966  !SrcTy->isPtrOrPtrVectorTy() ||
967  !DestTy->isPtrOrPtrVectorTy() ||
968  SrcTy->isVectorTy() != DestTy->isVectorTy()) {
969  return;
970  }
971 
972  unsigned SrcAS = SrcTy->getPointerAddressSpace();
973  unsigned DstAS = DestTy->getPointerAddressSpace();
974 
975  Assert1(SrcAS == DstAS,
976  "Bitcasts between pointers of different address spaces is not legal."
977  "Use AddrSpaceCast instead.", V);
978 }
979 
980 void Verifier::VerifyConstantExprBitcastType(const ConstantExpr *CE) {
981  if (CE->getOpcode() == Instruction::BitCast) {
982  Type *SrcTy = CE->getOperand(0)->getType();
983  Type *DstTy = CE->getType();
984  VerifyBitcastType(CE, DstTy, SrcTy);
985  }
986 }
987 
988 bool Verifier::VerifyAttributeCount(AttributeSet Attrs, unsigned Params) {
989  if (Attrs.getNumSlots() == 0)
990  return true;
991 
992  unsigned LastSlot = Attrs.getNumSlots() - 1;
993  unsigned LastIndex = Attrs.getSlotIndex(LastSlot);
994  if (LastIndex <= Params
995  || (LastIndex == AttributeSet::FunctionIndex
996  && (LastSlot == 0 || Attrs.getSlotIndex(LastSlot - 1) <= Params)))
997  return true;
998 
999  return false;
1000 }
1001 
1002 // visitFunction - Verify that a function is ok.
1003 //
1004 void Verifier::visitFunction(Function &F) {
1005  // Check function arguments.
1006  FunctionType *FT = F.getFunctionType();
1007  unsigned NumArgs = F.arg_size();
1008 
1009  Assert1(Context == &F.getContext(),
1010  "Function context does not match Module context!", &F);
1011 
1012  Assert1(!F.hasCommonLinkage(), "Functions may not have common linkage", &F);
1013  Assert2(FT->getNumParams() == NumArgs,
1014  "# formal arguments must match # of arguments for function type!",
1015  &F, FT);
1016  Assert1(F.getReturnType()->isFirstClassType() ||
1017  F.getReturnType()->isVoidTy() ||
1018  F.getReturnType()->isStructTy(),
1019  "Functions cannot return aggregate values!", &F);
1020 
1021  Assert1(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(),
1022  "Invalid struct return type!", &F);
1023 
1024  AttributeSet Attrs = F.getAttributes();
1025 
1026  Assert1(VerifyAttributeCount(Attrs, FT->getNumParams()),
1027  "Attribute after last parameter!", &F);
1028 
1029  // Check function attributes.
1030  VerifyFunctionAttrs(FT, Attrs, &F);
1031 
1032  // On function declarations/definitions, we do not support the builtin
1033  // attribute. We do not check this in VerifyFunctionAttrs since that is
1034  // checking for Attributes that can/can not ever be on functions.
1035  Assert1(!Attrs.hasAttribute(AttributeSet::FunctionIndex,
1037  "Attribute 'builtin' can only be applied to a callsite.", &F);
1038 
1039  // Check that this function meets the restrictions on this calling convention.
1040  switch (F.getCallingConv()) {
1041  default:
1042  break;
1043  case CallingConv::C:
1044  break;
1045  case CallingConv::Fast:
1046  case CallingConv::Cold:
1052  Assert1(!F.isVarArg(),
1053  "Varargs functions must have C calling conventions!", &F);
1054  break;
1055  }
1056 
1057  bool isLLVMdotName = F.getName().size() >= 5 &&
1058  F.getName().substr(0, 5) == "llvm.";
1059 
1060  // Check that the argument values match the function type for this function...
1061  unsigned i = 0;
1062  for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end();
1063  I != E; ++I, ++i) {
1064  Assert2(I->getType() == FT->getParamType(i),
1065  "Argument value does not match function argument type!",
1066  I, FT->getParamType(i));
1067  Assert1(I->getType()->isFirstClassType(),
1068  "Function arguments must have first-class types!", I);
1069  if (!isLLVMdotName)
1070  Assert2(!I->getType()->isMetadataTy(),
1071  "Function takes metadata but isn't an intrinsic", I, &F);
1072  }
1073 
1074  if (F.isMaterializable()) {
1075  // Function has a body somewhere we can't see.
1076  } else if (F.isDeclaration()) {
1077  Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
1078  F.hasExternalWeakLinkage(),
1079  "invalid linkage type for function declaration", &F);
1080  } else {
1081  // Verify that this function (which has a body) is not named "llvm.*". It
1082  // is not legal to define intrinsics.
1083  Assert1(!isLLVMdotName, "llvm intrinsics cannot be defined!", &F);
1084 
1085  // Check the entry node
1086  BasicBlock *Entry = &F.getEntryBlock();
1087  Assert1(pred_begin(Entry) == pred_end(Entry),
1088  "Entry block to function must not have predecessors!", Entry);
1089 
1090  // The address of the entry block cannot be taken, unless it is dead.
1091  if (Entry->hasAddressTaken()) {
1092  Assert1(!BlockAddress::get(Entry)->isConstantUsed(),
1093  "blockaddress may not be used with the entry block!", Entry);
1094  }
1095  }
1096 
1097  // If this function is actually an intrinsic, verify that it is only used in
1098  // direct call/invokes, never having its "address taken".
1099  if (F.getIntrinsicID()) {
1100  const User *U;
1101  if (F.hasAddressTaken(&U))
1102  Assert1(0, "Invalid user of intrinsic instruction!", U);
1103  }
1104 }
1105 
1106 // verifyBasicBlock - Verify that a basic block is well formed...
1107 //
1108 void Verifier::visitBasicBlock(BasicBlock &BB) {
1109  InstsInThisBlock.clear();
1110 
1111  // Ensure that basic blocks have terminators!
1112  Assert1(BB.getTerminator(), "Basic Block does not have terminator!", &BB);
1113 
1114  // Check constraints that this basic block imposes on all of the PHI nodes in
1115  // it.
1116  if (isa<PHINode>(BB.front())) {
1119  std::sort(Preds.begin(), Preds.end());
1120  PHINode *PN;
1121  for (BasicBlock::iterator I = BB.begin(); (PN = dyn_cast<PHINode>(I));++I) {
1122  // Ensure that PHI nodes have at least one entry!
1123  Assert1(PN->getNumIncomingValues() != 0,
1124  "PHI nodes must have at least one entry. If the block is dead, "
1125  "the PHI should be removed!", PN);
1126  Assert1(PN->getNumIncomingValues() == Preds.size(),
1127  "PHINode should have one entry for each predecessor of its "
1128  "parent basic block!", PN);
1129 
1130  // Get and sort all incoming values in the PHI node...
1131  Values.clear();
1132  Values.reserve(PN->getNumIncomingValues());
1133  for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
1134  Values.push_back(std::make_pair(PN->getIncomingBlock(i),
1135  PN->getIncomingValue(i)));
1136  std::sort(Values.begin(), Values.end());
1137 
1138  for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1139  // Check to make sure that if there is more than one entry for a
1140  // particular basic block in this PHI node, that the incoming values are
1141  // all identical.
1142  //
1143  Assert4(i == 0 || Values[i].first != Values[i-1].first ||
1144  Values[i].second == Values[i-1].second,
1145  "PHI node has multiple entries for the same basic block with "
1146  "different incoming values!", PN, Values[i].first,
1147  Values[i].second, Values[i-1].second);
1148 
1149  // Check to make sure that the predecessors and PHI node entries are
1150  // matched up.
1151  Assert3(Values[i].first == Preds[i],
1152  "PHI node entries do not match predecessors!", PN,
1153  Values[i].first, Preds[i]);
1154  }
1155  }
1156  }
1157 }
1158 
1159 void Verifier::visitTerminatorInst(TerminatorInst &I) {
1160  // Ensure that terminators only exist at the end of the basic block.
1161  Assert1(&I == I.getParent()->getTerminator(),
1162  "Terminator found in the middle of a basic block!", I.getParent());
1163  visitInstruction(I);
1164 }
1165 
1166 void Verifier::visitBranchInst(BranchInst &BI) {
1167  if (BI.isConditional()) {
1169  "Branch condition is not 'i1' type!", &BI, BI.getCondition());
1170  }
1171  visitTerminatorInst(BI);
1172 }
1173 
1174 void Verifier::visitReturnInst(ReturnInst &RI) {
1175  Function *F = RI.getParent()->getParent();
1176  unsigned N = RI.getNumOperands();
1177  if (F->getReturnType()->isVoidTy())
1178  Assert2(N == 0,
1179  "Found return instr that returns non-void in Function of void "
1180  "return type!", &RI, F->getReturnType());
1181  else
1182  Assert2(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(),
1183  "Function return type does not match operand "
1184  "type of return inst!", &RI, F->getReturnType());
1185 
1186  // Check to make sure that the return value has necessary properties for
1187  // terminators...
1188  visitTerminatorInst(RI);
1189 }
1190 
1191 void Verifier::visitSwitchInst(SwitchInst &SI) {
1192  // Check to make sure that all of the constants in the switch instruction
1193  // have the same type as the switched-on value.
1194  Type *SwitchTy = SI.getCondition()->getType();
1196  for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; ++i) {
1197  Assert1(i.getCaseValue()->getType() == SwitchTy,
1198  "Switch constants must all be same type as switch value!", &SI);
1199  Assert2(Constants.insert(i.getCaseValue()),
1200  "Duplicate integer as switch case", &SI, i.getCaseValue());
1201  }
1202 
1203  visitTerminatorInst(SI);
1204 }
1205 
1206 void Verifier::visitIndirectBrInst(IndirectBrInst &BI) {
1208  "Indirectbr operand must have pointer type!", &BI);
1209  for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i)
1211  "Indirectbr destinations must all have pointer type!", &BI);
1212 
1213  visitTerminatorInst(BI);
1214 }
1215 
1216 void Verifier::visitSelectInst(SelectInst &SI) {
1218  SI.getOperand(2)),
1219  "Invalid operands for select instruction!", &SI);
1220 
1221  Assert1(SI.getTrueValue()->getType() == SI.getType(),
1222  "Select values must have same type as select instruction!", &SI);
1223  visitInstruction(SI);
1224 }
1225 
1226 /// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of
1227 /// a pass, if any exist, it's an error.
1228 ///
1229 void Verifier::visitUserOp1(Instruction &I) {
1230  Assert1(0, "User-defined operators should not live outside of a pass!", &I);
1231 }
1232 
1233 void Verifier::visitTruncInst(TruncInst &I) {
1234  // Get the source and destination types
1235  Type *SrcTy = I.getOperand(0)->getType();
1236  Type *DestTy = I.getType();
1237 
1238  // Get the size of the types in bits, we'll need this later
1239  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
1240  unsigned DestBitSize = DestTy->getScalarSizeInBits();
1241 
1242  Assert1(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I);
1243  Assert1(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I);
1244  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1245  "trunc source and destination must both be a vector or neither", &I);
1246  Assert1(SrcBitSize > DestBitSize,"DestTy too big for Trunc", &I);
1247 
1248  visitInstruction(I);
1249 }
1250 
1251 void Verifier::visitZExtInst(ZExtInst &I) {
1252  // Get the source and destination types
1253  Type *SrcTy = I.getOperand(0)->getType();
1254  Type *DestTy = I.getType();
1255 
1256  // Get the size of the types in bits, we'll need this later
1257  Assert1(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I);
1258  Assert1(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I);
1259  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1260  "zext source and destination must both be a vector or neither", &I);
1261  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
1262  unsigned DestBitSize = DestTy->getScalarSizeInBits();
1263 
1264  Assert1(SrcBitSize < DestBitSize,"Type too small for ZExt", &I);
1265 
1266  visitInstruction(I);
1267 }
1268 
1269 void Verifier::visitSExtInst(SExtInst &I) {
1270  // Get the source and destination types
1271  Type *SrcTy = I.getOperand(0)->getType();
1272  Type *DestTy = I.getType();
1273 
1274  // Get the size of the types in bits, we'll need this later
1275  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
1276  unsigned DestBitSize = DestTy->getScalarSizeInBits();
1277 
1278  Assert1(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I);
1279  Assert1(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I);
1280  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1281  "sext source and destination must both be a vector or neither", &I);
1282  Assert1(SrcBitSize < DestBitSize,"Type too small for SExt", &I);
1283 
1284  visitInstruction(I);
1285 }
1286 
1287 void Verifier::visitFPTruncInst(FPTruncInst &I) {
1288  // Get the source and destination types
1289  Type *SrcTy = I.getOperand(0)->getType();
1290  Type *DestTy = I.getType();
1291  // Get the size of the types in bits, we'll need this later
1292  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
1293  unsigned DestBitSize = DestTy->getScalarSizeInBits();
1294 
1295  Assert1(SrcTy->isFPOrFPVectorTy(),"FPTrunc only operates on FP", &I);
1296  Assert1(DestTy->isFPOrFPVectorTy(),"FPTrunc only produces an FP", &I);
1297  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1298  "fptrunc source and destination must both be a vector or neither",&I);
1299  Assert1(SrcBitSize > DestBitSize,"DestTy too big for FPTrunc", &I);
1300 
1301  visitInstruction(I);
1302 }
1303 
1304 void Verifier::visitFPExtInst(FPExtInst &I) {
1305  // Get the source and destination types
1306  Type *SrcTy = I.getOperand(0)->getType();
1307  Type *DestTy = I.getType();
1308 
1309  // Get the size of the types in bits, we'll need this later
1310  unsigned SrcBitSize = SrcTy->getScalarSizeInBits();
1311  unsigned DestBitSize = DestTy->getScalarSizeInBits();
1312 
1313  Assert1(SrcTy->isFPOrFPVectorTy(),"FPExt only operates on FP", &I);
1314  Assert1(DestTy->isFPOrFPVectorTy(),"FPExt only produces an FP", &I);
1315  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1316  "fpext source and destination must both be a vector or neither", &I);
1317  Assert1(SrcBitSize < DestBitSize,"DestTy too small for FPExt", &I);
1318 
1319  visitInstruction(I);
1320 }
1321 
1322 void Verifier::visitUIToFPInst(UIToFPInst &I) {
1323  // Get the source and destination types
1324  Type *SrcTy = I.getOperand(0)->getType();
1325  Type *DestTy = I.getType();
1326 
1327  bool SrcVec = SrcTy->isVectorTy();
1328  bool DstVec = DestTy->isVectorTy();
1329 
1330  Assert1(SrcVec == DstVec,
1331  "UIToFP source and dest must both be vector or scalar", &I);
1332  Assert1(SrcTy->isIntOrIntVectorTy(),
1333  "UIToFP source must be integer or integer vector", &I);
1334  Assert1(DestTy->isFPOrFPVectorTy(),
1335  "UIToFP result must be FP or FP vector", &I);
1336 
1337  if (SrcVec && DstVec)
1338  Assert1(cast<VectorType>(SrcTy)->getNumElements() ==
1339  cast<VectorType>(DestTy)->getNumElements(),
1340  "UIToFP source and dest vector length mismatch", &I);
1341 
1342  visitInstruction(I);
1343 }
1344 
1345 void Verifier::visitSIToFPInst(SIToFPInst &I) {
1346  // Get the source and destination types
1347  Type *SrcTy = I.getOperand(0)->getType();
1348  Type *DestTy = I.getType();
1349 
1350  bool SrcVec = SrcTy->isVectorTy();
1351  bool DstVec = DestTy->isVectorTy();
1352 
1353  Assert1(SrcVec == DstVec,
1354  "SIToFP source and dest must both be vector or scalar", &I);
1355  Assert1(SrcTy->isIntOrIntVectorTy(),
1356  "SIToFP source must be integer or integer vector", &I);
1357  Assert1(DestTy->isFPOrFPVectorTy(),
1358  "SIToFP result must be FP or FP vector", &I);
1359 
1360  if (SrcVec && DstVec)
1361  Assert1(cast<VectorType>(SrcTy)->getNumElements() ==
1362  cast<VectorType>(DestTy)->getNumElements(),
1363  "SIToFP source and dest vector length mismatch", &I);
1364 
1365  visitInstruction(I);
1366 }
1367 
1368 void Verifier::visitFPToUIInst(FPToUIInst &I) {
1369  // Get the source and destination types
1370  Type *SrcTy = I.getOperand(0)->getType();
1371  Type *DestTy = I.getType();
1372 
1373  bool SrcVec = SrcTy->isVectorTy();
1374  bool DstVec = DestTy->isVectorTy();
1375 
1376  Assert1(SrcVec == DstVec,
1377  "FPToUI source and dest must both be vector or scalar", &I);
1378  Assert1(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector",
1379  &I);
1380  Assert1(DestTy->isIntOrIntVectorTy(),
1381  "FPToUI result must be integer or integer vector", &I);
1382 
1383  if (SrcVec && DstVec)
1384  Assert1(cast<VectorType>(SrcTy)->getNumElements() ==
1385  cast<VectorType>(DestTy)->getNumElements(),
1386  "FPToUI source and dest vector length mismatch", &I);
1387 
1388  visitInstruction(I);
1389 }
1390 
1391 void Verifier::visitFPToSIInst(FPToSIInst &I) {
1392  // Get the source and destination types
1393  Type *SrcTy = I.getOperand(0)->getType();
1394  Type *DestTy = I.getType();
1395 
1396  bool SrcVec = SrcTy->isVectorTy();
1397  bool DstVec = DestTy->isVectorTy();
1398 
1399  Assert1(SrcVec == DstVec,
1400  "FPToSI source and dest must both be vector or scalar", &I);
1401  Assert1(SrcTy->isFPOrFPVectorTy(),
1402  "FPToSI source must be FP or FP vector", &I);
1403  Assert1(DestTy->isIntOrIntVectorTy(),
1404  "FPToSI result must be integer or integer vector", &I);
1405 
1406  if (SrcVec && DstVec)
1407  Assert1(cast<VectorType>(SrcTy)->getNumElements() ==
1408  cast<VectorType>(DestTy)->getNumElements(),
1409  "FPToSI source and dest vector length mismatch", &I);
1410 
1411  visitInstruction(I);
1412 }
1413 
1414 void Verifier::visitPtrToIntInst(PtrToIntInst &I) {
1415  // Get the source and destination types
1416  Type *SrcTy = I.getOperand(0)->getType();
1417  Type *DestTy = I.getType();
1418 
1419  Assert1(SrcTy->getScalarType()->isPointerTy(),
1420  "PtrToInt source must be pointer", &I);
1421  Assert1(DestTy->getScalarType()->isIntegerTy(),
1422  "PtrToInt result must be integral", &I);
1423  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1424  "PtrToInt type mismatch", &I);
1425 
1426  if (SrcTy->isVectorTy()) {
1427  VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
1428  VectorType *VDest = dyn_cast<VectorType>(DestTy);
1429  Assert1(VSrc->getNumElements() == VDest->getNumElements(),
1430  "PtrToInt Vector width mismatch", &I);
1431  }
1432 
1433  visitInstruction(I);
1434 }
1435 
1436 void Verifier::visitIntToPtrInst(IntToPtrInst &I) {
1437  // Get the source and destination types
1438  Type *SrcTy = I.getOperand(0)->getType();
1439  Type *DestTy = I.getType();
1440 
1441  Assert1(SrcTy->getScalarType()->isIntegerTy(),
1442  "IntToPtr source must be an integral", &I);
1443  Assert1(DestTy->getScalarType()->isPointerTy(),
1444  "IntToPtr result must be a pointer",&I);
1445  Assert1(SrcTy->isVectorTy() == DestTy->isVectorTy(),
1446  "IntToPtr type mismatch", &I);
1447  if (SrcTy->isVectorTy()) {
1448  VectorType *VSrc = dyn_cast<VectorType>(SrcTy);
1449  VectorType *VDest = dyn_cast<VectorType>(DestTy);
1450  Assert1(VSrc->getNumElements() == VDest->getNumElements(),
1451  "IntToPtr Vector width mismatch", &I);
1452  }
1453  visitInstruction(I);
1454 }
1455 
1456 void Verifier::visitBitCastInst(BitCastInst &I) {
1457  Type *SrcTy = I.getOperand(0)->getType();
1458  Type *DestTy = I.getType();
1459  VerifyBitcastType(&I, DestTy, SrcTy);
1460  visitInstruction(I);
1461 }
1462 
1463 void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
1464  Type *SrcTy = I.getOperand(0)->getType();
1465  Type *DestTy = I.getType();
1466 
1467  Assert1(SrcTy->isPtrOrPtrVectorTy(),
1468  "AddrSpaceCast source must be a pointer", &I);
1469  Assert1(DestTy->isPtrOrPtrVectorTy(),
1470  "AddrSpaceCast result must be a pointer", &I);
1472  "AddrSpaceCast must be between different address spaces", &I);
1473  if (SrcTy->isVectorTy())
1474  Assert1(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),
1475  "AddrSpaceCast vector pointer number of elements mismatch", &I);
1476  visitInstruction(I);
1477 }
1478 
1479 /// visitPHINode - Ensure that a PHI node is well formed.
1480 ///
1481 void Verifier::visitPHINode(PHINode &PN) {
1482  // Ensure that the PHI nodes are all grouped together at the top of the block.
1483  // This can be tested by checking whether the instruction before this is
1484  // either nonexistent (because this is begin()) or is a PHI node. If not,
1485  // then there is some other instruction before a PHI.
1486  Assert2(&PN == &PN.getParent()->front() ||
1487  isa<PHINode>(--BasicBlock::iterator(&PN)),
1488  "PHI nodes not grouped at top of basic block!",
1489  &PN, PN.getParent());
1490 
1491  // Check that all of the values of the PHI node have the same type as the
1492  // result, and that the incoming blocks are really basic blocks.
1493  for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
1494  Assert1(PN.getType() == PN.getIncomingValue(i)->getType(),
1495  "PHI node operands are not the same type as the result!", &PN);
1496  }
1497 
1498  // All other PHI node constraints are checked in the visitBasicBlock method.
1499 
1500  visitInstruction(PN);
1501 }
1502 
1503 void Verifier::VerifyCallSite(CallSite CS) {
1504  Instruction *I = CS.getInstruction();
1505 
1507  "Called function must be a pointer!", I);
1508  PointerType *FPTy = cast<PointerType>(CS.getCalledValue()->getType());
1509 
1510  Assert1(FPTy->getElementType()->isFunctionTy(),
1511  "Called function is not pointer to function type!", I);
1512  FunctionType *FTy = cast<FunctionType>(FPTy->getElementType());
1513 
1514  // Verify that the correct number of arguments are being passed
1515  if (FTy->isVarArg())
1516  Assert1(CS.arg_size() >= FTy->getNumParams(),
1517  "Called function requires more parameters than were provided!",I);
1518  else
1519  Assert1(CS.arg_size() == FTy->getNumParams(),
1520  "Incorrect number of arguments passed to called function!", I);
1521 
1522  // Verify that all arguments to the call match the function type.
1523  for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
1524  Assert3(CS.getArgument(i)->getType() == FTy->getParamType(i),
1525  "Call parameter type does not match function signature!",
1526  CS.getArgument(i), FTy->getParamType(i), I);
1527 
1528  AttributeSet Attrs = CS.getAttributes();
1529 
1530  Assert1(VerifyAttributeCount(Attrs, CS.arg_size()),
1531  "Attribute after last parameter!", I);
1532 
1533  // Verify call attributes.
1534  VerifyFunctionAttrs(FTy, Attrs, I);
1535 
1536  if (FTy->isVarArg()) {
1537  // FIXME? is 'nest' even legal here?
1538  bool SawNest = false;
1539  bool SawReturned = false;
1540 
1541  for (unsigned Idx = 1; Idx < 1 + FTy->getNumParams(); ++Idx) {
1542  if (Attrs.hasAttribute(Idx, Attribute::Nest))
1543  SawNest = true;
1544  if (Attrs.hasAttribute(Idx, Attribute::Returned))
1545  SawReturned = true;
1546  }
1547 
1548  // Check attributes on the varargs part.
1549  for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
1550  Type *Ty = CS.getArgument(Idx-1)->getType();
1551  VerifyParameterAttrs(Attrs, Idx, Ty, false, I);
1552 
1553  if (Attrs.hasAttribute(Idx, Attribute::Nest)) {
1554  Assert1(!SawNest, "More than one parameter has attribute nest!", I);
1555  SawNest = true;
1556  }
1557 
1558  if (Attrs.hasAttribute(Idx, Attribute::Returned)) {
1559  Assert1(!SawReturned, "More than one parameter has attribute returned!",
1560  I);
1561  Assert1(Ty->canLosslesslyBitCastTo(FTy->getReturnType()),
1562  "Incompatible argument and return types for 'returned' "
1563  "attribute", I);
1564  SawReturned = true;
1565  }
1566 
1568  "Attribute 'sret' cannot be used for vararg call arguments!", I);
1569  }
1570  }
1571 
1572  // Verify that there's no metadata unless it's a direct call to an intrinsic.
1573  if (CS.getCalledFunction() == 0 ||
1574  !CS.getCalledFunction()->getName().startswith("llvm.")) {
1575  for (FunctionType::param_iterator PI = FTy->param_begin(),
1576  PE = FTy->param_end(); PI != PE; ++PI)
1577  Assert1(!(*PI)->isMetadataTy(),
1578  "Function has metadata parameter but isn't an intrinsic", I);
1579  }
1580 
1581  visitInstruction(*I);
1582 }
1583 
1584 void Verifier::visitCallInst(CallInst &CI) {
1585  VerifyCallSite(&CI);
1586 
1587  if (Function *F = CI.getCalledFunction())
1589  visitIntrinsicFunctionCall(ID, CI);
1590 }
1591 
1592 void Verifier::visitInvokeInst(InvokeInst &II) {
1593  VerifyCallSite(&II);
1594 
1595  // Verify that there is a landingpad instruction as the first non-PHI
1596  // instruction of the 'unwind' destination.
1598  "The unwind destination does not have a landingpad instruction!",&II);
1599 
1600  visitTerminatorInst(II);
1601 }
1602 
1603 /// visitBinaryOperator - Check that both arguments to the binary operator are
1604 /// of the same type!
1605 ///
1606 void Verifier::visitBinaryOperator(BinaryOperator &B) {
1607  Assert1(B.getOperand(0)->getType() == B.getOperand(1)->getType(),
1608  "Both operands to a binary operator are not of the same type!", &B);
1609 
1610  switch (B.getOpcode()) {
1611  // Check that integer arithmetic operators are only used with
1612  // integral operands.
1613  case Instruction::Add:
1614  case Instruction::Sub:
1615  case Instruction::Mul:
1616  case Instruction::SDiv:
1617  case Instruction::UDiv:
1618  case Instruction::SRem:
1619  case Instruction::URem:
1621  "Integer arithmetic operators only work with integral types!", &B);
1622  Assert1(B.getType() == B.getOperand(0)->getType(),
1623  "Integer arithmetic operators must have same type "
1624  "for operands and result!", &B);
1625  break;
1626  // Check that floating-point arithmetic operators are only used with
1627  // floating-point operands.
1628  case Instruction::FAdd:
1629  case Instruction::FSub:
1630  case Instruction::FMul:
1631  case Instruction::FDiv:
1632  case Instruction::FRem:
1634  "Floating-point arithmetic operators only work with "
1635  "floating-point types!", &B);
1636  Assert1(B.getType() == B.getOperand(0)->getType(),
1637  "Floating-point arithmetic operators must have same type "
1638  "for operands and result!", &B);
1639  break;
1640  // Check that logical operators are only used with integral operands.
1641  case Instruction::And:
1642  case Instruction::Or:
1643  case Instruction::Xor:
1645  "Logical operators only work with integral types!", &B);
1646  Assert1(B.getType() == B.getOperand(0)->getType(),
1647  "Logical operators must have same type for operands and result!",
1648  &B);
1649  break;
1650  case Instruction::Shl:
1651  case Instruction::LShr:
1652  case Instruction::AShr:
1654  "Shifts only work with integral types!", &B);
1655  Assert1(B.getType() == B.getOperand(0)->getType(),
1656  "Shift return type must be same as operands!", &B);
1657  break;
1658  default:
1659  llvm_unreachable("Unknown BinaryOperator opcode!");
1660  }
1661 
1662  visitInstruction(B);
1663 }
1664 
1665 void Verifier::visitICmpInst(ICmpInst &IC) {
1666  // Check that the operands are the same type
1667  Type *Op0Ty = IC.getOperand(0)->getType();
1668  Type *Op1Ty = IC.getOperand(1)->getType();
1669  Assert1(Op0Ty == Op1Ty,
1670  "Both operands to ICmp instruction are not of the same type!", &IC);
1671  // Check that the operands are the right type
1672  Assert1(Op0Ty->isIntOrIntVectorTy() || Op0Ty->getScalarType()->isPointerTy(),
1673  "Invalid operand types for ICmp instruction", &IC);
1674  // Check that the predicate is valid.
1677  "Invalid predicate in ICmp instruction!", &IC);
1678 
1679  visitInstruction(IC);
1680 }
1681 
1682 void Verifier::visitFCmpInst(FCmpInst &FC) {
1683  // Check that the operands are the same type
1684  Type *Op0Ty = FC.getOperand(0)->getType();
1685  Type *Op1Ty = FC.getOperand(1)->getType();
1686  Assert1(Op0Ty == Op1Ty,
1687  "Both operands to FCmp instruction are not of the same type!", &FC);
1688  // Check that the operands are the right type
1689  Assert1(Op0Ty->isFPOrFPVectorTy(),
1690  "Invalid operand types for FCmp instruction", &FC);
1691  // Check that the predicate is valid.
1694  "Invalid predicate in FCmp instruction!", &FC);
1695 
1696  visitInstruction(FC);
1697 }
1698 
1699 void Verifier::visitExtractElementInst(ExtractElementInst &EI) {
1701  EI.getOperand(1)),
1702  "Invalid extractelement operands!", &EI);
1703  visitInstruction(EI);
1704 }
1705 
1706 void Verifier::visitInsertElementInst(InsertElementInst &IE) {
1708  IE.getOperand(1),
1709  IE.getOperand(2)),
1710  "Invalid insertelement operands!", &IE);
1711  visitInstruction(IE);
1712 }
1713 
1714 void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
1716  SV.getOperand(2)),
1717  "Invalid shufflevector operands!", &SV);
1718  visitInstruction(SV);
1719 }
1720 
1721 void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
1722  Type *TargetTy = GEP.getPointerOperandType()->getScalarType();
1723 
1724  Assert1(isa<PointerType>(TargetTy),
1725  "GEP base pointer is not a vector or a vector of pointers", &GEP);
1726  Assert1(cast<PointerType>(TargetTy)->getElementType()->isSized(),
1727  "GEP into unsized type!", &GEP);
1729  GEP.getType()->isVectorTy(), "Vector GEP must return a vector value",
1730  &GEP);
1731 
1732  SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
1733  Type *ElTy =
1735  Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
1736 
1737  Assert2(GEP.getType()->getScalarType()->isPointerTy() &&
1738  cast<PointerType>(GEP.getType()->getScalarType())->getElementType()
1739  == ElTy, "GEP is not of right type for indices!", &GEP, ElTy);
1740 
1741  if (GEP.getPointerOperandType()->isVectorTy()) {
1742  // Additional checks for vector GEPs.
1743  unsigned GepWidth = GEP.getPointerOperandType()->getVectorNumElements();
1744  Assert1(GepWidth == GEP.getType()->getVectorNumElements(),
1745  "Vector GEP result width doesn't match operand's", &GEP);
1746  for (unsigned i = 0, e = Idxs.size(); i != e; ++i) {
1747  Type *IndexTy = Idxs[i]->getType();
1748  Assert1(IndexTy->isVectorTy(),
1749  "Vector GEP must have vector indices!", &GEP);
1750  unsigned IndexWidth = IndexTy->getVectorNumElements();
1751  Assert1(IndexWidth == GepWidth, "Invalid GEP index vector width", &GEP);
1752  }
1753  }
1754  visitInstruction(GEP);
1755 }
1756 
1757 static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
1758  return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
1759 }
1760 
1761 void Verifier::visitLoadInst(LoadInst &LI) {
1763  Assert1(PTy, "Load operand must be a pointer.", &LI);
1764  Type *ElTy = PTy->getElementType();
1765  Assert2(ElTy == LI.getType(),
1766  "Load result type does not match pointer operand type!", &LI, ElTy);
1767  if (LI.isAtomic()) {
1769  "Load cannot have Release ordering", &LI);
1770  Assert1(LI.getAlignment() != 0,
1771  "Atomic load must specify explicit alignment", &LI);
1772  if (!ElTy->isPointerTy()) {
1773  Assert2(ElTy->isIntegerTy(),
1774  "atomic store operand must have integer type!",
1775  &LI, ElTy);
1776  unsigned Size = ElTy->getPrimitiveSizeInBits();
1777  Assert2(Size >= 8 && !(Size & (Size - 1)),
1778  "atomic store operand must be power-of-two byte-sized integer",
1779  &LI, ElTy);
1780  }
1781  } else {
1783  "Non-atomic load cannot have SynchronizationScope specified", &LI);
1784  }
1785 
1786  if (MDNode *Range = LI.getMetadata(LLVMContext::MD_range)) {
1787  unsigned NumOperands = Range->getNumOperands();
1788  Assert1(NumOperands % 2 == 0, "Unfinished range!", Range);
1789  unsigned NumRanges = NumOperands / 2;
1790  Assert1(NumRanges >= 1, "It should have at least one range!", Range);
1791 
1792  ConstantRange LastRange(1); // Dummy initial value
1793  for (unsigned i = 0; i < NumRanges; ++i) {
1794  ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i));
1795  Assert1(Low, "The lower limit must be an integer!", Low);
1796  ConstantInt *High = dyn_cast<ConstantInt>(Range->getOperand(2*i + 1));
1797  Assert1(High, "The upper limit must be an integer!", High);
1798  Assert1(High->getType() == Low->getType() &&
1799  High->getType() == ElTy, "Range types must match load type!",
1800  &LI);
1801 
1802  APInt HighV = High->getValue();
1803  APInt LowV = Low->getValue();
1804  ConstantRange CurRange(LowV, HighV);
1805  Assert1(!CurRange.isEmptySet() && !CurRange.isFullSet(),
1806  "Range must not be empty!", Range);
1807  if (i != 0) {
1808  Assert1(CurRange.intersectWith(LastRange).isEmptySet(),
1809  "Intervals are overlapping", Range);
1810  Assert1(LowV.sgt(LastRange.getLower()), "Intervals are not in order",
1811  Range);
1812  Assert1(!isContiguous(CurRange, LastRange), "Intervals are contiguous",
1813  Range);
1814  }
1815  LastRange = ConstantRange(LowV, HighV);
1816  }
1817  if (NumRanges > 2) {
1818  APInt FirstLow =
1819  dyn_cast<ConstantInt>(Range->getOperand(0))->getValue();
1820  APInt FirstHigh =
1821  dyn_cast<ConstantInt>(Range->getOperand(1))->getValue();
1822  ConstantRange FirstRange(FirstLow, FirstHigh);
1823  Assert1(FirstRange.intersectWith(LastRange).isEmptySet(),
1824  "Intervals are overlapping", Range);
1825  Assert1(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",
1826  Range);
1827  }
1828 
1829 
1830  }
1831 
1832  visitInstruction(LI);
1833 }
1834 
1835 void Verifier::visitStoreInst(StoreInst &SI) {
1837  Assert1(PTy, "Store operand must be a pointer.", &SI);
1838  Type *ElTy = PTy->getElementType();
1839  Assert2(ElTy == SI.getOperand(0)->getType(),
1840  "Stored value type does not match pointer operand type!",
1841  &SI, ElTy);
1842  if (SI.isAtomic()) {
1844  "Store cannot have Acquire ordering", &SI);
1845  Assert1(SI.getAlignment() != 0,
1846  "Atomic store must specify explicit alignment", &SI);
1847  if (!ElTy->isPointerTy()) {
1848  Assert2(ElTy->isIntegerTy(),
1849  "atomic store operand must have integer type!",
1850  &SI, ElTy);
1851  unsigned Size = ElTy->getPrimitiveSizeInBits();
1852  Assert2(Size >= 8 && !(Size & (Size - 1)),
1853  "atomic store operand must be power-of-two byte-sized integer",
1854  &SI, ElTy);
1855  }
1856  } else {
1858  "Non-atomic store cannot have SynchronizationScope specified", &SI);
1859  }
1860  visitInstruction(SI);
1861 }
1862 
1863 void Verifier::visitAllocaInst(AllocaInst &AI) {
1864  PointerType *PTy = AI.getType();
1865  Assert1(PTy->getAddressSpace() == 0,
1866  "Allocation instruction pointer not in the generic address space!",
1867  &AI);
1868  Assert1(PTy->getElementType()->isSized(), "Cannot allocate unsized type",
1869  &AI);
1871  "Alloca array size must have integer type", &AI);
1872  visitInstruction(AI);
1873 }
1874 
1875 void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) {
1876  Assert1(CXI.getOrdering() != NotAtomic,
1877  "cmpxchg instructions must be atomic.", &CXI);
1878  Assert1(CXI.getOrdering() != Unordered,
1879  "cmpxchg instructions cannot be unordered.", &CXI);
1880  PointerType *PTy = dyn_cast<PointerType>(CXI.getOperand(0)->getType());
1881  Assert1(PTy, "First cmpxchg operand must be a pointer.", &CXI);
1882  Type *ElTy = PTy->getElementType();
1883  Assert2(ElTy->isIntegerTy(),
1884  "cmpxchg operand must have integer type!",
1885  &CXI, ElTy);
1886  unsigned Size = ElTy->getPrimitiveSizeInBits();
1887  Assert2(Size >= 8 && !(Size & (Size - 1)),
1888  "cmpxchg operand must be power-of-two byte-sized integer",
1889  &CXI, ElTy);
1890  Assert2(ElTy == CXI.getOperand(1)->getType(),
1891  "Expected value type does not match pointer operand type!",
1892  &CXI, ElTy);
1893  Assert2(ElTy == CXI.getOperand(2)->getType(),
1894  "Stored value type does not match pointer operand type!",
1895  &CXI, ElTy);
1896  visitInstruction(CXI);
1897 }
1898 
1899 void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
1900  Assert1(RMWI.getOrdering() != NotAtomic,
1901  "atomicrmw instructions must be atomic.", &RMWI);
1902  Assert1(RMWI.getOrdering() != Unordered,
1903  "atomicrmw instructions cannot be unordered.", &RMWI);
1904  PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
1905  Assert1(PTy, "First atomicrmw operand must be a pointer.", &RMWI);
1906  Type *ElTy = PTy->getElementType();
1907  Assert2(ElTy->isIntegerTy(),
1908  "atomicrmw operand must have integer type!",
1909  &RMWI, ElTy);
1910  unsigned Size = ElTy->getPrimitiveSizeInBits();
1911  Assert2(Size >= 8 && !(Size & (Size - 1)),
1912  "atomicrmw operand must be power-of-two byte-sized integer",
1913  &RMWI, ElTy);
1914  Assert2(ElTy == RMWI.getOperand(1)->getType(),
1915  "Argument value type does not match pointer operand type!",
1916  &RMWI, ElTy);
1919  "Invalid binary operation!", &RMWI);
1920  visitInstruction(RMWI);
1921 }
1922 
1923 void Verifier::visitFenceInst(FenceInst &FI) {
1924  const AtomicOrdering Ordering = FI.getOrdering();
1925  Assert1(Ordering == Acquire || Ordering == Release ||
1926  Ordering == AcquireRelease || Ordering == SequentiallyConsistent,
1927  "fence instructions may only have "
1928  "acquire, release, acq_rel, or seq_cst ordering.", &FI);
1929  visitInstruction(FI);
1930 }
1931 
1932 void Verifier::visitExtractValueInst(ExtractValueInst &EVI) {
1934  EVI.getIndices()) ==
1935  EVI.getType(),
1936  "Invalid ExtractValueInst operands!", &EVI);
1937 
1938  visitInstruction(EVI);
1939 }
1940 
1941 void Verifier::visitInsertValueInst(InsertValueInst &IVI) {
1943  IVI.getIndices()) ==
1944  IVI.getOperand(1)->getType(),
1945  "Invalid InsertValueInst operands!", &IVI);
1946 
1947  visitInstruction(IVI);
1948 }
1949 
1950 void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
1951  BasicBlock *BB = LPI.getParent();
1952 
1953  // The landingpad instruction is ill-formed if it doesn't have any clauses and
1954  // isn't a cleanup.
1955  Assert1(LPI.getNumClauses() > 0 || LPI.isCleanup(),
1956  "LandingPadInst needs at least one clause or to be a cleanup.", &LPI);
1957 
1958  // The landingpad instruction defines its parent as a landing pad block. The
1959  // landing pad block may be branched to only by the unwind edge of an invoke.
1960  for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
1961  const InvokeInst *II = dyn_cast<InvokeInst>((*I)->getTerminator());
1962  Assert1(II && II->getUnwindDest() == BB && II->getNormalDest() != BB,
1963  "Block containing LandingPadInst must be jumped to "
1964  "only by the unwind edge of an invoke.", &LPI);
1965  }
1966 
1967  // The landingpad instruction must be the first non-PHI instruction in the
1968  // block.
1969  Assert1(LPI.getParent()->getLandingPadInst() == &LPI,
1970  "LandingPadInst not the first non-PHI instruction in the block.",
1971  &LPI);
1972 
1973  // The personality functions for all landingpad instructions within the same
1974  // function should match.
1975  if (PersonalityFn)
1976  Assert1(LPI.getPersonalityFn() == PersonalityFn,
1977  "Personality function doesn't match others in function", &LPI);
1978  PersonalityFn = LPI.getPersonalityFn();
1979 
1980  // All operands must be constants.
1981  Assert1(isa<Constant>(PersonalityFn), "Personality function is not constant!",
1982  &LPI);
1983  for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) {
1984  Value *Clause = LPI.getClause(i);
1985  Assert1(isa<Constant>(Clause), "Clause is not constant!", &LPI);
1986  if (LPI.isCatch(i)) {
1987  Assert1(isa<PointerType>(Clause->getType()),
1988  "Catch operand does not have pointer type!", &LPI);
1989  } else {
1990  Assert1(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI);
1991  Assert1(isa<ConstantArray>(Clause) || isa<ConstantAggregateZero>(Clause),
1992  "Filter operand is not an array of constants!", &LPI);
1993  }
1994  }
1995 
1996  visitInstruction(LPI);
1997 }
1998 
1999 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
2000  Instruction *Op = cast<Instruction>(I.getOperand(i));
2001  // If the we have an invalid invoke, don't try to compute the dominance.
2002  // We already reject it in the invoke specific checks and the dominance
2003  // computation doesn't handle multiple edges.
2004  if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
2005  if (II->getNormalDest() == II->getUnwindDest())
2006  return;
2007  }
2008 
2009  const Use &U = I.getOperandUse(i);
2010  Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, U),
2011  "Instruction does not dominate all uses!", Op, &I);
2012 }
2013 
2014 /// verifyInstruction - Verify that an instruction is well formed.
2015 ///
2016 void Verifier::visitInstruction(Instruction &I) {
2017  BasicBlock *BB = I.getParent();
2018  Assert1(BB, "Instruction not embedded in basic block!", &I);
2019 
2020  if (!isa<PHINode>(I)) { // Check that non-phi nodes are not self referential
2021  for (Value::use_iterator UI = I.use_begin(), UE = I.use_end();
2022  UI != UE; ++UI)
2023  Assert1(*UI != (User*)&I || !DT->isReachableFromEntry(BB),
2024  "Only PHI nodes may reference their own value!", &I);
2025  }
2026 
2027  // Check that void typed values don't have names
2028  Assert1(!I.getType()->isVoidTy() || !I.hasName(),
2029  "Instruction has a name, but provides a void value!", &I);
2030 
2031  // Check that the return value of the instruction is either void or a legal
2032  // value type.
2033  Assert1(I.getType()->isVoidTy() ||
2034  I.getType()->isFirstClassType(),
2035  "Instruction returns a non-scalar type!", &I);
2036 
2037  // Check that the instruction doesn't produce metadata. Calls are already
2038  // checked against the callee type.
2039  Assert1(!I.getType()->isMetadataTy() ||
2040  isa<CallInst>(I) || isa<InvokeInst>(I),
2041  "Invalid use of metadata!", &I);
2042 
2043  // Check that all uses of the instruction, if they are instructions
2044  // themselves, actually have parent basic blocks. If the use is not an
2045  // instruction, it is an error!
2046  for (User::use_iterator UI = I.use_begin(), UE = I.use_end();
2047  UI != UE; ++UI) {
2048  if (Instruction *Used = dyn_cast<Instruction>(*UI))
2049  Assert2(Used->getParent() != 0, "Instruction referencing instruction not"
2050  " embedded in a basic block!", &I, Used);
2051  else {
2052  CheckFailed("Use of instruction is not an instruction!", *UI);
2053  return;
2054  }
2055  }
2056 
2057  for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
2058  Assert1(I.getOperand(i) != 0, "Instruction has null operand!", &I);
2059 
2060  // Check to make sure that only first-class-values are operands to
2061  // instructions.
2062  if (!I.getOperand(i)->getType()->isFirstClassType()) {
2063  Assert1(0, "Instruction operands must be first-class values!", &I);
2064  }
2065 
2066  if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
2067  // Check to make sure that the "address of" an intrinsic function is never
2068  // taken.
2069  Assert1(!F->isIntrinsic() || i == (isa<CallInst>(I) ? e-1 : 0),
2070  "Cannot take the address of an intrinsic!", &I);
2071  Assert1(!F->isIntrinsic() || isa<CallInst>(I) ||
2073  "Cannot invoke an intrinsinc other than donothing", &I);
2074  Assert1(F->getParent() == Mod, "Referencing function in another module!",
2075  &I);
2076  } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {
2077  Assert1(OpBB->getParent() == BB->getParent(),
2078  "Referring to a basic block in another function!", &I);
2079  } else if (Argument *OpArg = dyn_cast<Argument>(I.getOperand(i))) {
2080  Assert1(OpArg->getParent() == BB->getParent(),
2081  "Referring to an argument in another function!", &I);
2082  } else if (GlobalValue *GV = dyn_cast<GlobalValue>(I.getOperand(i))) {
2083  Assert1(GV->getParent() == Mod, "Referencing global in another module!",
2084  &I);
2085  } else if (isa<Instruction>(I.getOperand(i))) {
2086  verifyDominatesUse(I, i);
2087  } else if (isa<InlineAsm>(I.getOperand(i))) {
2088  Assert1((i + 1 == e && isa<CallInst>(I)) ||
2089  (i + 3 == e && isa<InvokeInst>(I)),
2090  "Cannot take the address of an inline asm!", &I);
2091  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(i))) {
2092  if (CE->getType()->isPtrOrPtrVectorTy()) {
2093  // If we have a ConstantExpr pointer, we need to see if it came from an
2094  // illegal bitcast (inttoptr <constant int> )
2097  Stack.push_back(CE);
2098 
2099  while (!Stack.empty()) {
2100  const ConstantExpr *V = Stack.pop_back_val();
2101  if (!Visited.insert(V))
2102  continue;
2103 
2104  VerifyConstantExprBitcastType(V);
2105 
2106  for (unsigned I = 0, N = V->getNumOperands(); I != N; ++I) {
2107  if (ConstantExpr *Op = dyn_cast<ConstantExpr>(V->getOperand(I)))
2108  Stack.push_back(Op);
2109  }
2110  }
2111  }
2112  }
2113  }
2114 
2115  if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) {
2117  "fpmath requires a floating point result!", &I);
2118  Assert1(MD->getNumOperands() == 1, "fpmath takes one operand!", &I);
2119  Value *Op0 = MD->getOperand(0);
2120  if (ConstantFP *CFP0 = dyn_cast_or_null<ConstantFP>(Op0)) {
2121  APFloat Accuracy = CFP0->getValueAPF();
2122  Assert1(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),
2123  "fpmath accuracy not a positive number!", &I);
2124  } else {
2125  Assert1(false, "invalid fpmath accuracy!", &I);
2126  }
2127  }
2128 
2130  Assert1(!MD || isa<LoadInst>(I), "Ranges are only for loads!", &I);
2131 
2132  if (!DisableDebugInfoVerifier) {
2134  Finder.processLocation(*Mod, DILocation(MD));
2135  }
2136 
2137  InstsInThisBlock.insert(&I);
2138 }
2139 
2140 /// VerifyIntrinsicType - Verify that the specified type (which comes from an
2141 /// intrinsic argument or return value) matches the type constraints specified
2142 /// by the .td file (e.g. an "any integer" argument really is an integer).
2143 ///
2144 /// This return true on error but does not print a message.
2145 bool Verifier::VerifyIntrinsicType(Type *Ty,
2147  SmallVectorImpl<Type*> &ArgTys) {
2148  using namespace Intrinsic;
2149 
2150  // If we ran out of descriptors, there are too many arguments.
2151  if (Infos.empty()) return true;
2152  IITDescriptor D = Infos.front();
2153  Infos = Infos.slice(1);
2154 
2155  switch (D.Kind) {
2156  case IITDescriptor::Void: return !Ty->isVoidTy();
2157  case IITDescriptor::VarArg: return true;
2158  case IITDescriptor::MMX: return !Ty->isX86_MMXTy();
2159  case IITDescriptor::Metadata: return !Ty->isMetadataTy();
2160  case IITDescriptor::Half: return !Ty->isHalfTy();
2161  case IITDescriptor::Float: return !Ty->isFloatTy();
2162  case IITDescriptor::Double: return !Ty->isDoubleTy();
2163  case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
2164  case IITDescriptor::Vector: {
2165  VectorType *VT = dyn_cast<VectorType>(Ty);
2166  return VT == 0 || VT->getNumElements() != D.Vector_Width ||
2167  VerifyIntrinsicType(VT->getElementType(), Infos, ArgTys);
2168  }
2169  case IITDescriptor::Pointer: {
2170  PointerType *PT = dyn_cast<PointerType>(Ty);
2171  return PT == 0 || PT->getAddressSpace() != D.Pointer_AddressSpace ||
2172  VerifyIntrinsicType(PT->getElementType(), Infos, ArgTys);
2173  }
2174 
2175  case IITDescriptor::Struct: {
2176  StructType *ST = dyn_cast<StructType>(Ty);
2177  if (ST == 0 || ST->getNumElements() != D.Struct_NumElements)
2178  return true;
2179 
2180  for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
2181  if (VerifyIntrinsicType(ST->getElementType(i), Infos, ArgTys))
2182  return true;
2183  return false;
2184  }
2185 
2187  // Two cases here - If this is the second occurrence of an argument, verify
2188  // that the later instance matches the previous instance.
2189  if (D.getArgumentNumber() < ArgTys.size())
2190  return Ty != ArgTys[D.getArgumentNumber()];
2191 
2192  // Otherwise, if this is the first instance of an argument, record it and
2193  // verify the "Any" kind.
2194  assert(D.getArgumentNumber() == ArgTys.size() && "Table consistency error");
2195  ArgTys.push_back(Ty);
2196 
2197  switch (D.getArgumentKind()) {
2199  case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy();
2200  case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty);
2201  case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty);
2202  }
2203  llvm_unreachable("all argument kinds not covered");
2204 
2206  // This may only be used when referring to a previous vector argument.
2207  return D.getArgumentNumber() >= ArgTys.size() ||
2208  !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
2210  cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
2211 
2213  // This may only be used when referring to a previous vector argument.
2214  return D.getArgumentNumber() >= ArgTys.size() ||
2215  !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
2217  cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
2218  }
2219  llvm_unreachable("unhandled");
2220 }
2221 
2222 /// \brief Verify if the intrinsic has variable arguments.
2223 /// This method is intended to be called after all the fixed arguments have been
2224 /// verified first.
2225 ///
2226 /// This method returns true on error and does not print an error message.
2227 bool
2228 Verifier::VerifyIntrinsicIsVarArg(bool isVarArg,
2230  using namespace Intrinsic;
2231 
2232  // If there are no descriptors left, then it can't be a vararg.
2233  if (Infos.empty())
2234  return isVarArg ? true : false;
2235 
2236  // There should be only one descriptor remaining at this point.
2237  if (Infos.size() != 1)
2238  return true;
2239 
2240  // Check and verify the descriptor.
2241  IITDescriptor D = Infos.front();
2242  Infos = Infos.slice(1);
2243  if (D.Kind == IITDescriptor::VarArg)
2244  return isVarArg ? false : true;
2245 
2246  return true;
2247 }
2248 
2249 /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways.
2250 ///
2251 void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
2252  Function *IF = CI.getCalledFunction();
2253  Assert1(IF->isDeclaration(), "Intrinsic functions should never be defined!",
2254  IF);
2255 
2256  // Verify that the intrinsic prototype lines up with what the .td files
2257  // describe.
2258  FunctionType *IFTy = IF->getFunctionType();
2259  bool IsVarArg = IFTy->isVarArg();
2260 
2262  getIntrinsicInfoTableEntries(ID, Table);
2263  ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
2264 
2265  SmallVector<Type *, 4> ArgTys;
2266  Assert1(!VerifyIntrinsicType(IFTy->getReturnType(), TableRef, ArgTys),
2267  "Intrinsic has incorrect return type!", IF);
2268  for (unsigned i = 0, e = IFTy->getNumParams(); i != e; ++i)
2269  Assert1(!VerifyIntrinsicType(IFTy->getParamType(i), TableRef, ArgTys),
2270  "Intrinsic has incorrect argument type!", IF);
2271 
2272  // Verify if the intrinsic call matches the vararg property.
2273  if (IsVarArg)
2274  Assert1(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),
2275  "Intrinsic was not defined with variable arguments!", IF);
2276  else
2277  Assert1(!VerifyIntrinsicIsVarArg(IsVarArg, TableRef),
2278  "Callsite was not defined with variable arguments!", IF);
2279 
2280  // All descriptors should be absorbed by now.
2281  Assert1(TableRef.empty(), "Intrinsic has too few arguments!", IF);
2282 
2283  // Now that we have the intrinsic ID and the actual argument types (and we
2284  // know they are legal for the intrinsic!) get the intrinsic name through the
2285  // usual means. This allows us to verify the mangling of argument types into
2286  // the name.
2287  Assert1(Intrinsic::getName(ID, ArgTys) == IF->getName(),
2288  "Intrinsic name not mangled correctly for type arguments!", IF);
2289 
2290  // If the intrinsic takes MDNode arguments, verify that they are either global
2291  // or are local to *this* function.
2292  for (unsigned i = 0, e = CI.getNumArgOperands(); i != e; ++i)
2293  if (MDNode *MD = dyn_cast<MDNode>(CI.getArgOperand(i)))
2294  visitMDNode(*MD, CI.getParent()->getParent());
2295 
2296  switch (ID) {
2297  default:
2298  break;
2299  case Intrinsic::ctlz: // llvm.ctlz
2300  case Intrinsic::cttz: // llvm.cttz
2301  Assert1(isa<ConstantInt>(CI.getArgOperand(1)),
2302  "is_zero_undef argument of bit counting intrinsics must be a "
2303  "constant int", &CI);
2304  break;
2305  case Intrinsic::dbg_declare: { // llvm.dbg.declare
2306  Assert1(CI.getArgOperand(0) && isa<MDNode>(CI.getArgOperand(0)),
2307  "invalid llvm.dbg.declare intrinsic call 1", &CI);
2308  MDNode *MD = cast<MDNode>(CI.getArgOperand(0));
2309  Assert1(MD->getNumOperands() == 1,
2310  "invalid llvm.dbg.declare intrinsic call 2", &CI);
2312  Finder.processDeclare(*Mod, cast<DbgDeclareInst>(&CI));
2313  } break;
2314  case Intrinsic::dbg_value: { //llvm.dbg.value
2315  if (!DisableDebugInfoVerifier) {
2316  Assert1(CI.getArgOperand(0) && isa<MDNode>(CI.getArgOperand(0)),
2317  "invalid llvm.dbg.value intrinsic call 1", &CI);
2318  Finder.processValue(*Mod, cast<DbgValueInst>(&CI));
2319  }
2320  break;
2321  }
2322  case Intrinsic::memcpy:
2323  case Intrinsic::memmove:
2324  case Intrinsic::memset:
2325  Assert1(isa<ConstantInt>(CI.getArgOperand(3)),
2326  "alignment argument of memory intrinsics must be a constant int",
2327  &CI);
2328  Assert1(isa<ConstantInt>(CI.getArgOperand(4)),
2329  "isvolatile argument of memory intrinsics must be a constant int",
2330  &CI);
2331  break;
2332  case Intrinsic::gcroot:
2333  case Intrinsic::gcwrite:
2334  case Intrinsic::gcread:
2335  if (ID == Intrinsic::gcroot) {
2336  AllocaInst *AI =
2338  Assert1(AI, "llvm.gcroot parameter #1 must be an alloca.", &CI);
2339  Assert1(isa<Constant>(CI.getArgOperand(1)),
2340  "llvm.gcroot parameter #2 must be a constant.", &CI);
2341  if (!AI->getType()->getElementType()->isPointerTy()) {
2342  Assert1(!isa<ConstantPointerNull>(CI.getArgOperand(1)),
2343  "llvm.gcroot parameter #1 must either be a pointer alloca, "
2344  "or argument #2 must be a non-null constant.", &CI);
2345  }
2346  }
2347 
2348  Assert1(CI.getParent()->getParent()->hasGC(),
2349  "Enclosing function does not use GC.", &CI);
2350  break;
2352  Assert1(isa<Function>(CI.getArgOperand(1)->stripPointerCasts()),
2353  "llvm.init_trampoline parameter #2 must resolve to a function.",
2354  &CI);
2355  break;
2356  case Intrinsic::prefetch:
2357  Assert1(isa<ConstantInt>(CI.getArgOperand(1)) &&
2358  isa<ConstantInt>(CI.getArgOperand(2)) &&
2359  cast<ConstantInt>(CI.getArgOperand(1))->getZExtValue() < 2 &&
2360  cast<ConstantInt>(CI.getArgOperand(2))->getZExtValue() < 4,
2361  "invalid arguments to llvm.prefetch",
2362  &CI);
2363  break;
2365  Assert1(isa<AllocaInst>(CI.getArgOperand(1)->stripPointerCasts()),
2366  "llvm.stackprotector parameter #2 must resolve to an alloca.",
2367  &CI);
2368  break;
2372  Assert1(isa<ConstantInt>(CI.getArgOperand(0)),
2373  "size argument of memory use markers must be a constant integer",
2374  &CI);
2375  break;
2377  Assert1(isa<ConstantInt>(CI.getArgOperand(1)),
2378  "llvm.invariant.end parameter #2 must be a constant integer", &CI);
2379  break;
2380  }
2381 }
2382 
2383 void Verifier::verifyDebugInfo() {
2384  // Verify Debug Info.
2385  if (!DisableDebugInfoVerifier) {
2386  for (DebugInfoFinder::iterator I = Finder.compile_unit_begin(),
2387  E = Finder.compile_unit_end(); I != E; ++I)
2388  Assert1(DICompileUnit(*I).Verify(), "DICompileUnit does not Verify!", *I);
2389  for (DebugInfoFinder::iterator I = Finder.subprogram_begin(),
2390  E = Finder.subprogram_end(); I != E; ++I)
2391  Assert1(DISubprogram(*I).Verify(), "DISubprogram does not Verify!", *I);
2392  for (DebugInfoFinder::iterator I = Finder.global_variable_begin(),
2393  E = Finder.global_variable_end(); I != E; ++I)
2395  "DIGlobalVariable does not Verify!", *I);
2396  for (DebugInfoFinder::iterator I = Finder.type_begin(),
2397  E = Finder.type_end(); I != E; ++I)
2398  Assert1(DIType(*I).Verify(), "DIType does not Verify!", *I);
2399  for (DebugInfoFinder::iterator I = Finder.scope_begin(),
2400  E = Finder.scope_end(); I != E; ++I)
2401  Assert1(DIScope(*I).Verify(), "DIScope does not Verify!", *I);
2402  }
2403 }
2404 
2405 //===----------------------------------------------------------------------===//
2406 // Implement the public interfaces to this file...
2407 //===----------------------------------------------------------------------===//
2408 
2410  return new Verifier(action);
2411 }
2412 
2413 
2414 /// verifyFunction - Check a function for errors, printing messages on stderr.
2415 /// Return true if the function is corrupt.
2416 ///
2418  Function &F = const_cast<Function&>(f);
2419  assert(!F.isDeclaration() && "Cannot verify external functions");
2420 
2421  FunctionPassManager FPM(F.getParent());
2422  Verifier *V = new Verifier(action);
2423  FPM.add(V);
2424  FPM.doInitialization();
2425  FPM.run(F);
2426  return V->Broken;
2427 }
2428 
2429 /// verifyModule - Check a module for errors, printing messages on stderr.
2430 /// Return true if the module is corrupt.
2431 ///
2433  std::string *ErrorInfo) {
2434  PassManager PM;
2435  Verifier *V = new Verifier(action);
2436  PM.add(V);
2437  PM.run(const_cast<Module&>(M));
2438 
2439  if (ErrorInfo && V->Broken)
2440  *ErrorInfo = V->MessagesStr.str();
2441  return V->Broken;
2442 }
bool verifyModule(const Module &M, VerifierFailureAction action=AbortProcessAction, std::string *ErrorInfo=0)
Check a module for errors.
Definition: Verifier.cpp:2432
const Use & getOperandUse(unsigned i) const
Definition: User.h:99
use_iterator use_end()
Definition: Value.h:152
LinkageTypes getLinkage() const
Definition: GlobalValue.h:218
IntegerType * getType() const
Definition: Constants.h:139
AtomicOrdering getOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:501
void reserve(unsigned N)
Definition: SmallVector.h:425
static PassRegistry * getPassRegistry()
LLVMContext & getContext() const
Definition: Function.cpp:167
const AttributeSet & getAttributes() const
Definition: CallSite.h:179
LLVM Argument representation.
Definition: Argument.h:35
#define Assert4(C, M, V1, V2, V3, V4)
Definition: Verifier.cpp:411
Base class for instruction visitors.
Definition: InstVisitor.h:81
Value * getAggregateOperand()
void initializeVerifierPass(PassRegistry &)
bool hasName() const
Definition: Value.h:117
SynchronizationScope getSynchScope() const
Definition: Instructions.h:319
ArrayRef< unsigned > getIndices() const
Sign extended before/after call.
Definition: Attributes.h:97
unsigned getScalarSizeInBits()
Definition: Type.cpp:135
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
VerifierFailureAction
An enumeration to specify the action to be taken if errors found.
Definition: Verifier.h:38
Force argument to be passed in register.
Definition: Attributes.h:76
The main container class for the LLVM Intermediate Representation.
Definition: Module.h:112
unsigned getNumParams() const
Definition: DerivedTypes.h:133
iterator end()
Definition: Function.h:397
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:112
static cl::opt< bool > DisableDebugInfoVerifier("disable-debug-info-verifier", cl::init(true))
unsigned arg_size() const
Definition: CallSite.h:145
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
This class represents zero extension of integer types.
unsigned getNumOperands() const
Definition: User.h:108
Nested function static chain.
Definition: Attributes.h:79
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
Definition: Metadata.h:142
Type::subtype_iterator param_iterator
Definition: DerivedTypes.h:123
bool isIntrinsic() const
Definition: Function.h:156
named_metadata_iterator named_metadata_end()
Definition: Module.h:559
bool hasAppendingLinkage() const
Definition: GlobalValue.h:204
bool insert(PtrType Ptr)
Definition: SmallPtrSet.h:253
Source said inlining was desirable.
Definition: Attributes.h:75
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:149
iterator begin(unsigned Slot) const
Definition: Attributes.cpp:887
bool isPtrOrPtrVectorTy() const
Definition: Type.h:225
Type * getReturnType() const
Definition: Function.cpp:179
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:116
const Instruction & front() const
Definition: BasicBlock.h:205
MDNode - a tuple of other values.
Definition: Metadata.h:69
F(f)
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:445
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: Type.cpp:218
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
Definition: DerivedTypes.h:395
const Constant * getInitializer() const
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:818
Value * getPersonalityFn() const
const Constant * getAliasee() const
Definition: GlobalAlias.h:61
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
Definition: Constants.h:1049
bool isFiniteNonZero() const
Definition: APFloat.h:399
Naked function.
Definition: Attributes.h:78
LoopInfoBase< BlockT, LoopT > * LI
Definition: LoopInfoImpl.h:411
ValTy * getArgument(unsigned ArgNo) const
Definition: CallSite.h:111
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
size_t arg_size() const
Definition: Function.cpp:248
StringRef getName() const
Definition: Value.cpp:167
iterator begin()
Definition: BasicBlock.h:193
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
Definition: Metadata.cpp:307
ArrayRef< unsigned > getIndices() const
bool Verify() const
Verify - Verify that a compile unit is well formed.
Definition: DebugInfo.cpp:375
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
Definition: AsmWriter.cpp:1179
Appends the two values, which are required to be metadata nodes.
Definition: Module.h:176
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:167
This class represents a conversion between pointers from one address space to another.
std::string str() const
str - Return the twine contents as a std::string.
Definition: Twine.cpp:16
bool hasCommonLinkage() const
Definition: GlobalValue.h:215
static Type * getIndexedType(Type *Agg, ArrayRef< unsigned > Idxs)
const APInt & getValue() const
Return the constant's value.
Definition: Constants.h:105
bool Verify() const
Definition: DebugInfo.cpp:37
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
Definition: SmallVector.h:430
#define llvm_unreachable(msg)
Definition: Use.h:60
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:172
unsigned getNumArgOperands() const
bool canLosslesslyBitCastTo(Type *Ty) const
Determine if this type could be losslessly bitcast to Ty.
Definition: Type.cpp:65
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc. to it.
Definition: BasicBlock.h:268
bool Verify() const
Verify - Verify that a global variable descriptor is well formed.
Definition: DebugInfo.cpp:528
Function must be in a unwind table.
Definition: Attributes.h:109
#define Assert2(C, M, V1, V2)
Definition: Verifier.cpp:407
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
AttributeSet typeIncompatible(Type *Ty, uint64_t Index)
Which attributes cannot be applied to a type.
Type * getPointerOperandType() const
Definition: Instructions.h:802
#define false
Definition: ConvertUTF.c:64
Function does not access memory.
Definition: Attributes.h:93
BasicBlock * getDestination(unsigned i)
getDestination - Return the specified destination.
Hidden pointer to structure to return.
Definition: Attributes.h:105
Function creates no aliases of pointer.
Definition: Attributes.h:82
SynchronizationScope getSynchScope() const
Definition: Instructions.h:199
This class represents a cast from a pointer to an integer.
AtomicOrdering
Definition: Instructions.h:36
global_iterator global_begin()
Definition: Module.h:521
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
void visit(Iterator Start, Iterator End)
Definition: InstVisitor.h:90
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Definition: DebugInfo.h:429
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
Definition: Instructions.h:648
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: SmallVector.h:56
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:143
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
Definition: ArrayRef.h:134
#define T
Represents a floating point comparison operator.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
Definition: APInt.h:1100
bool isMaterializable() const
Definition: Globals.cpp:30
bool isFirstClassType() const
Definition: Type.h:251
This class represents a no-op cast from one type to another.
op_iterator idx_begin()
Definition: Instructions.h:785
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
Definition: Type.cpp:361
GlobalValue * resolveAliasedGlobal(bool stopOnWeak=true)
Definition: Globals.cpp:247
Pass structure by value.
Definition: Attributes.h:73
unsigned getNumClauses() const
getNumClauses - Get the number of clauses for this landing pad.
ValTy * getCalledValue() const
Definition: CallSite.h:85
This class represents a cast from floating point to signed integer.
bool isArrayTy() const
Definition: Type.h:216
unsigned getNumElements() const
Return the number of elements in the Vector type.
Definition: DerivedTypes.h:408
iterator begin()
Definition: Function.h:395
Stack protection.
Definition: Attributes.h:102
Type * getElementType() const
Definition: DerivedTypes.h:319
This class represents a truncation of integer types.
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:109
BasicBlock * getNormalDest() const
unsigned getNumIncomingValues() const
Value * getClause(unsigned Idx) const
#define Assert3(C, M, V1, V2, V3)
Definition: Verifier.cpp:409
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
Value * stripPointerCastsNoFollowAliases()
Strips off any unneeded pointer casts and all-zero GEPs from the specified value, returning the origi...
Definition: Value.cpp:389
verifyModule will print to stderr and return true
Definition: Verifier.h:40
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.
Definition: Type.h:182
bool isIntOrIntVectorTy() const
Definition: Type.h:204
unsigned getNumSlots() const
Return the number of slots used in this attribute list. This is the number of arguments that have an ...
Definition: Attributes.cpp:906
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:128
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:314
unsigned getAlignment() const
Definition: Instructions.h:301
alias_iterator alias_end()
Definition: Module.h:544
value_use_iterator< User > use_iterator
Definition: Value.h:146
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
InstrTy * getInstruction() const
Definition: CallSite.h:79
void initializePreVerifierPass(PassRegistry &)
bool isVectorTy() const
Definition: Type.h:229
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1358
unsigned getIntrinsicID() const LLVM_READONLY
Definition: Function.cpp:371
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:287
LLVM Constant Representation.
Definition: Constant.h:41
void getModuleFlagsMetadata(SmallVectorImpl< ModuleFlagEntry > &Flags) const
getModuleFlagsMetadata - Returns the module flags in the provided vector.
Definition: Module.cpp:315
PointerType * getType() const
Definition: Instructions.h:91
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:146
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Definition: APInt.h:1845
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:366
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Definition: APInt.h:1850
Interval::pred_iterator pred_begin(Interval *I)
Definition: Interval.h:117
Return value is always equal to this argument.
Definition: Attributes.h:95
static bool isValidLinkage(LinkageTypes L)
Definition: GlobalAlias.h:84
bool verifyFunction(const Function &F, VerifierFailureAction action=AbortProcessAction)
Definition: Verifier.cpp:2417
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:227
DIGlobalVariable - This is a wrapper for a global variable.
Definition: DebugInfo.h:572
INITIALIZE_PASS(PreVerifier,"preverify","Preliminary module verification", false, false) static char &PreVerifyID
Type * getTypeAtIndex(const Value *V)
Definition: Type.cpp:627
verifyModule will print to stderr and abort()
Definition: Verifier.h:39
Represent an integer comparison operator.
Definition: Instructions.h:911
MDNode * getOperand(unsigned i) const
getOperand - Return specified operand.
Definition: Metadata.cpp:545
Value * getOperand(unsigned i) const
Definition: User.h:88
Zero extended before/after call.
Definition: Attributes.h:110
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:120
Function doesn't unwind stack.
Definition: Attributes.h:90
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:714
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:104
Marks function as being in a cold path.
Definition: Attributes.h:74
This class represents a cast from an integer to a pointer.
Mark the function as not returning.
Definition: Attributes.h:89
bool isPointerTy() const
Definition: Type.h:220
bool hasWeakLinkage() const
Definition: GlobalValue.h:201
bool isFPOrFPVectorTy() const
Definition: Type.h:186
PointerType * getPointerTo(unsigned AddrSpace=0)
Definition: Type.cpp:756
static bool isValidOperands(const Value *Vec, const Value *Idx)
const Value * getTrueValue() const
bool isAtomic() const
Definition: Instructions.h:211
Call cannot be duplicated.
Definition: Attributes.h:83
DIScope - A base class for various scopes.
Definition: DebugInfo.h:197
bool isConditional() const
global_iterator global_end()
Definition: Module.h:523
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:153
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:214
BinaryOps getOpcode() const
Definition: InstrTypes.h:326
bool hasExternalLinkage() const
Definition: GlobalValue.h:194
BasicBlock * getUnwindDest() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
Definition: Instructions.h:308
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:208
Class for constant integers.
Definition: Constants.h:51
bool isNegative() const
Definition: APFloat.h:361
Value * getIncomingValue(unsigned i) const
unsigned getVectorNumElements() const
Definition: Type.cpp:214
AnalysisUsage & addRequiredID(const void *ID)
Definition: Pass.cpp:262
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Definition: Function.cpp:578
Type * getType() const
Definition: Value.h:111
MDNode * getMetadata(unsigned KindID) const
Definition: Instruction.h:140
iterator end(unsigned Slot) const
Definition: Attributes.cpp:893
const APInt & getLower() const
Definition: ConstantRange.h:79
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:164
This class represents a cast from floating point to unsigned integer.
alias_iterator alias_begin()
Definition: Module.h:542
SequentialType * getType() const
Definition: Instructions.h:764
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
Definition: Value.cpp:385
Function * getCalledFunction() const
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
Definition: Instructions.h:188
bool isNullValue() const
Definition: Constants.cpp:75
BinOp getOperation() const
Definition: Instructions.h:605
static VectorType * getExtendedElementVectorType(VectorType *VTy)
Definition: DerivedTypes.h:385
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
Value * getArgOperand(unsigned i) const
Class for arbitrary precision integers.
Definition: APInt.h:75
bool hasInitializer() const
bool isAtomic() const
Definition: Instructions.h:331
bool isConstant() const
Function must not be optimized.
Definition: Attributes.h:92
bool isIntegerTy() const
Definition: Type.h:196
Function only reads from memory.
Definition: Attributes.h:94
bool hasGC() const
Definition: Function.cpp:310
Value * getCondition() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Definition: APInt.h:1840
Disable redzone.
Definition: Attributes.h:88
ThreadSanitizer is on.
Definition: Attributes.h:107
use_iterator use_begin()
Definition: Value.h:150
PointerType * getType() const
getType - Global values are always pointers.
Definition: GlobalValue.h:107
bool isFunctionLocal() const
isFunctionLocal - Return whether MDNode is local to a function.
Definition: Metadata.h:145
NamedMDNode * getNamedMetadata(const Twine &Name) const
Definition: Module.cpp:286
Value * getCondition() const
iterator end()
Definition: Module.h:533
std::string getName(ID id, ArrayRef< Type * > Tys=None)
Definition: Function.cpp:400
bool isAggregateType() const
Definition: Type.h:270
bool Verify() const
Verify - Verify that a type descriptor is well formed.
Definition: DebugInfo.cpp:441
verifyModule will just return true
Definition: Verifier.h:41
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
Definition: Instructions.h:403
bool isDeclaration() const
Definition: Globals.cpp:66
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
Definition: Attributes.cpp:910
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
Definition: Attributes.cpp:828
unsigned getAlignment() const
Definition: Instructions.h:181
Callee isn't recognized as a builtin.
Definition: Attributes.h:81
bool isCatch(unsigned Idx) const
isCatch - Return 'true' if the clause and index Idx is a catch clause.
AddressSanitizer is on.
Definition: Attributes.h:106
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
Strong Stack protection.
Definition: Attributes.h:104
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
bool Verify() const
Verify - Verify that a subprogram descriptor is well formed.
Definition: DebugInfo.cpp:512
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:360
FunctionType * getFunctionType() const
Definition: Function.cpp:171
This class represents a cast unsigned integer to floating point.
iterator begin()
Definition: Module.h:531
const Type * getScalarType() const
Definition: Type.cpp:51
unsigned getPrimitiveSizeInBits() const
Definition: Type.cpp:117
bool hasLocalLinkage() const
Definition: GlobalValue.h:211
bool isVarArg() const
Definition: DerivedTypes.h:120
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
Definition: Module.h:141
This class represents a cast from signed integer to floating point.
const APInt & getUpper() const
Definition: ConstantRange.h:83
Type * getReturnType() const
Definition: DerivedTypes.h:121
Function can return twice.
Definition: Attributes.h:96
static Type * getIndexedType(Type *Ptr, ArrayRef< Value * > IdxList)
This class represents a truncation of floating point types.
bool isLabelTy() const
isLabelTy - Return true if this is 'label'.
Definition: Type.h:189
Module * getParent()
Definition: GlobalValue.h:286
LLVM Value Representation.
Definition: Value.h:66
bool hasUnnamedAddr() const
Definition: GlobalValue.h:84
Disable implicit floating point insts.
Definition: Attributes.h:84
const Value * getArraySize() const
Definition: Instructions.h:86
bool hasDLLImportLinkage() const
Definition: GlobalValue.h:212
bool isSized() const
Definition: Type.h:278
unsigned getNumOperands() const
getNumOperands - Return the number of NamedMDNode operands.
Definition: Metadata.cpp:540
#define Assert1(C, M, V1)
Definition: Verifier.cpp:405
static bool isContiguous(const ConstantRange &A, const ConstantRange &B)
Definition: Verifier.cpp:1757
bool isCleanup() const
ppc ctr loops verify
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:286
This class represents an extension of floating point types.
DICompileUnit - A wrapper for a compile unit.
Definition: DebugInfo.h:402
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
Definition: CallingConv.h:122
Stack protection required.
Definition: Attributes.h:103
MemorySanitizer is on.
Definition: Attributes.h:108
unsigned getNumDestinations() const
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:345
const BasicBlock * getParent() const
Definition: Instruction.h:52
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:99
#define T1
named_metadata_iterator named_metadata_begin()
Definition: Module.h:554
LLVMContext & getContext() const
Definition: Module.h:249
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
Definition: Type.h:140
FunTy * getCalledFunction() const
Definition: CallSite.h:93
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
FunctionPass * createVerifierPass(VerifierFailureAction action=AbortProcessAction)
Create a verifier pass.
Definition: Verifier.cpp:2409
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.
Definition: Type.h:192
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Function must be optimized for size first.
Definition: Attributes.h:77