Verifier.h 2.5 KB

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