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/ADT/StringRef.h"
25#include <string>
26
27namespace llvm {
28
29class Function;
30class FunctionPass;
31class ModulePass;
32class Module;
33class PreservedAnalyses;
34class raw_ostream;
35
36/// \brief Check a function for errors, useful for use when debugging a
37/// pass.
38///
39/// If there are no errors, the function returns false. If an error is found,
40/// a message describing the error is written to OS (if non-null) and true is
41/// returned.
42bool verifyFunction(const Function &F, raw_ostream *OS = nullptr);
43
44/// \brief Check a module for errors.
45///
46/// If there are no errors, the function returns false. If an error is found,
47/// a message describing the error is written to OS (if non-null) and true is
48/// returned.
49bool verifyModule(const Module &M, raw_ostream *OS = nullptr);
50
51/// \brief Create a verifier pass.
52///
53/// Check a module or function for validity. This is essentially a pass wrapped
54/// around the above verifyFunction and verifyModule routines and
55/// functionality. When the pass detects a verification error it is always
56/// printed to stderr, and by default they are fatal. You can override that by
57/// passing \c false to \p FatalErrors.
58///
59/// Note that this creates a pass suitable for the legacy pass manager. It has nothing to do with \c VerifierPass.
60FunctionPass *createVerifierPass(bool FatalErrors = true);
61
62/// \brief Create a debug-info verifier pass.
63///
64/// Check a module for validity of debug info. This is essentially a pass
65/// wrapped around the debug-info parts of \a verifyModule().  When the pass
66/// detects a verification error it is always printed to stderr, and by default
67/// they are fatal. You can override that by passing \c false to \p
68/// FatalErrors.
69///
70/// Note that this creates a pass suitable for the legacy pass manager. It has
71/// nothing to do with \c VerifierPass.
72ModulePass *createDebugInfoVerifierPass(bool FatalErrors = true);
73
74class VerifierPass {
75  bool FatalErrors;
76
77public:
78  explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {}
79
80  PreservedAnalyses run(Module *M);
81  PreservedAnalyses run(Function *F);
82
83  static StringRef name() { return "VerifierPass"; }
84};
85
86} // End llvm namespace
87
88#endif
89