LLVM API Documentation
00001 //===- Verifier.h - LLVM IR Verifier ----------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the function verifier interface, that can be used for some 00011 // sanity checking of input to the system, and for checking that transformations 00012 // haven't done something bad. 00013 // 00014 // Note that this does not provide full 'java style' security and verifications, 00015 // instead it just tries to ensure that code is well formed. 00016 // 00017 // To see what specifically is checked, look at the top of Verifier.cpp 00018 // 00019 //===----------------------------------------------------------------------===// 00020 00021 #ifndef LLVM_IR_VERIFIER_H 00022 #define LLVM_IR_VERIFIER_H 00023 00024 #include "llvm/ADT/StringRef.h" 00025 #include <string> 00026 00027 namespace llvm { 00028 00029 class Function; 00030 class FunctionPass; 00031 class ModulePass; 00032 class Module; 00033 class PreservedAnalyses; 00034 class raw_ostream; 00035 00036 /// \brief Check a function for errors, useful for use when debugging a 00037 /// pass. 00038 /// 00039 /// If there are no errors, the function returns false. If an error is found, 00040 /// a message describing the error is written to OS (if non-null) and true is 00041 /// returned. 00042 bool verifyFunction(const Function &F, raw_ostream *OS = nullptr); 00043 00044 /// \brief Check a module for errors. 00045 /// 00046 /// If there are no errors, the function returns false. If an error is found, 00047 /// a message describing the error is written to OS (if non-null) and true is 00048 /// returned. 00049 bool verifyModule(const Module &M, raw_ostream *OS = nullptr); 00050 00051 /// \brief Create a verifier pass. 00052 /// 00053 /// Check a module or function for validity. This is essentially a pass wrapped 00054 /// around the above verifyFunction and verifyModule routines and 00055 /// functionality. When the pass detects a verification error it is always 00056 /// printed to stderr, and by default they are fatal. You can override that by 00057 /// passing \c false to \p FatalErrors. 00058 /// 00059 /// Note that this creates a pass suitable for the legacy pass manager. It has nothing to do with \c VerifierPass. 00060 FunctionPass *createVerifierPass(bool FatalErrors = true); 00061 00062 /// \brief Create a debug-info verifier pass. 00063 /// 00064 /// Check a module for validity of debug info. This is essentially a pass 00065 /// wrapped around the debug-info parts of \a verifyModule(). When the pass 00066 /// detects a verification error it is always printed to stderr, and by default 00067 /// they are fatal. You can override that by passing \c false to \p 00068 /// FatalErrors. 00069 /// 00070 /// Note that this creates a pass suitable for the legacy pass manager. It has 00071 /// nothing to do with \c VerifierPass. 00072 ModulePass *createDebugInfoVerifierPass(bool FatalErrors = true); 00073 00074 class VerifierPass { 00075 bool FatalErrors; 00076 00077 public: 00078 explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {} 00079 00080 PreservedAnalyses run(Module *M); 00081 PreservedAnalyses run(Function *F); 00082 00083 static StringRef name() { return "VerifierPass"; } 00084 }; 00085 00086 } // End llvm namespace 00087 00088 #endif