1 //===- Verifier.h - LLVM IR Verifier ----------------------------*- C++ -*-===// 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, and for checking that transformations 12 // haven't done something bad. 13 // 14 // Note that this does not provide full 'java style' security and verifications, 15 // instead it just tries to ensure that code is well formed. 16 // 17 // To see what specifically is checked, look at the top of Verifier.cpp 18 // 19 //===----------------------------------------------------------------------===// 20 21 #ifndef LLVM_IR_VERIFIER_H 22 #define LLVM_IR_VERIFIER_H 23 24 #include "llvm/IR/PassManager.h" 25 26 namespace llvm { 27 28 class Function; 29 class FunctionPass; 30 class ModulePass; 31 class Module; 32 class raw_ostream; 33 34 /// \brief Check a function for errors, useful for use when debugging a 35 /// pass. 36 /// 37 /// If there are no errors, the function returns false. If an error is found, 38 /// a message describing the error is written to OS (if non-null) and true is 39 /// returned. 40 bool verifyFunction(const Function &F, raw_ostream *OS = nullptr); 41 42 /// \brief Check a module for errors. 43 /// 44 /// If there are no errors, the function returns false. If an error is 45 /// found, a message describing the error is written to OS (if 46 /// non-null) and true is returned. 47 /// 48 /// \return true if the module is broken. If BrokenDebugInfo is 49 /// supplied, DebugInfo verification failures won't be considered as 50 /// error and instead *BrokenDebugInfo will be set to true. Debug 51 /// info errors can be "recovered" from by stripping the debug info. 52 bool verifyModule(const Module &M, raw_ostream *OS = nullptr, 53 bool *BrokenDebugInfo = nullptr); 54 55 FunctionPass *createVerifierPass(bool FatalErrors = true); 56 57 /// Check a module for errors, and report separate error states for IR 58 /// and debug info errors. 59 class VerifierAnalysis : public AnalysisInfoMixin<VerifierAnalysis> { 60 friend AnalysisInfoMixin<VerifierAnalysis>; 61 static char PassID; 62 63 public: 64 struct Result { 65 bool IRBroken, DebugInfoBroken; 66 }; ID()67 static void *ID() { return (void *)&PassID; } 68 Result run(Module &M, ModuleAnalysisManager &); 69 Result run(Function &F, FunctionAnalysisManager &); 70 }; 71 72 /// Check a module for errors, but report debug info errors separately. 73 /// Otherwise behaves as the normal verifyModule. Debug info errors can be 74 /// "recovered" from by stripping the debug info. 75 bool verifyModule(bool &BrokenDebugInfo, const Module &M, raw_ostream *OS); 76 77 /// \brief Create a verifier pass. 78 /// 79 /// Check a module or function for validity. This is essentially a pass wrapped 80 /// around the above verifyFunction and verifyModule routines and 81 /// functionality. When the pass detects a verification error it is always 82 /// printed to stderr, and by default they are fatal. You can override that by 83 /// passing \c false to \p FatalErrors. 84 /// 85 /// Note that this creates a pass suitable for the legacy pass manager. It has 86 /// nothing to do with \c VerifierPass. 87 class VerifierPass : public PassInfoMixin<VerifierPass> { 88 bool FatalErrors; 89 90 public: FatalErrors(FatalErrors)91 explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {} 92 93 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 94 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 95 }; 96 97 98 } // End llvm namespace 99 100 #endif 101