CheckerBase.td 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //===--- CheckerBase.td - Checker TableGen classes ------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the TableGen core definitions for checkers
  10. //
  11. //===----------------------------------------------------------------------===//
  12. /// Describes a checker or package option type. This is important for validating
  13. /// user supplied inputs.
  14. /// New option types can be added by modifying this enum. Note that this
  15. /// requires changes in the TableGen emitter file ClangSACheckersEmitter.cpp.
  16. class CmdLineOptionTypeEnum<bits<2> val> {
  17. bits<2> Type = val;
  18. }
  19. def Integer : CmdLineOptionTypeEnum<0>;
  20. def String : CmdLineOptionTypeEnum<1>;
  21. def Boolean : CmdLineOptionTypeEnum<2>;
  22. /// Describes the state of the entry. We wouldn't like to display, for example,
  23. /// developer only entries for a list meant for end users.
  24. class DevelopmentStageEnum<bits<1> val> {
  25. bits<1> Val = val;
  26. }
  27. /// Alpha entries are under development, might be incomplet, inkorrekt and
  28. /// unstable.
  29. def InAlpha : DevelopmentStageEnum<0>;
  30. /// Released entries are stable, produce minimal, if any false positives,
  31. /// and emits reports that explain the occurance of the bug understandably and
  32. /// thoroughly.
  33. def Released : DevelopmentStageEnum<1>;
  34. /// Marks the entry hidden. Hidden entries won't be displayed in
  35. /// -analyzer-checker-option-help.
  36. class HiddenEnum<bit val> {
  37. bit Val = val;
  38. }
  39. def DontHide : HiddenEnum<0>;
  40. def Hide : HiddenEnum<1>;
  41. /// Describes an option for a checker or a package.
  42. class CmdLineOption<CmdLineOptionTypeEnum type, string cmdFlag, string desc,
  43. string defaultVal, DevelopmentStageEnum stage,
  44. HiddenEnum isHidden = DontHide> {
  45. bits<2> Type = type.Type;
  46. string CmdFlag = cmdFlag;
  47. string Desc = desc;
  48. string DefaultVal = defaultVal;
  49. bits<1> DevelopmentStage = stage.Val;
  50. bit Hidden = isHidden.Val;
  51. }
  52. /// Describes a list of package options.
  53. class PackageOptions<list<CmdLineOption> opts> {
  54. list<CmdLineOption> PackageOptions = opts;
  55. }
  56. /// Describes a package. Every checker is a part of a package, for example,
  57. /// 'NullDereference' is part of the 'core' package, hence it's full name is
  58. /// 'core.NullDereference'.
  59. /// Example:
  60. /// def Core : Package<"core">;
  61. class Package<string name> {
  62. string PackageName = name;
  63. // This field is optional.
  64. list<CmdLineOption> PackageOptions;
  65. Package ParentPackage;
  66. bit Hidden = 0;
  67. }
  68. /// Describes a 'super' package that holds another package inside it. This is
  69. /// used to nest packages in one another. One may, for example, create the
  70. /// 'builtin' package inside 'core', thus creating the package 'core.builtin'.
  71. /// Example:
  72. /// def CoreBuiltin : Package<"builtin">, ParentPackage<Core>;
  73. class ParentPackage<Package P> { Package ParentPackage = P; }
  74. /// A description. May be displayed to the user when clang is invoked with
  75. /// a '-help'-like command line option.
  76. class HelpText<string text> { string HelpText = text; }
  77. /// Describes what kind of documentation exists for the checker.
  78. class DocumentationEnum<bits<2> val> {
  79. bits<2> Documentation = val;
  80. }
  81. def NotDocumented : DocumentationEnum<0>;
  82. def HasDocumentation : DocumentationEnum<1>;
  83. def HasAlphaDocumentation : DocumentationEnum<2>;
  84. class Documentation<DocumentationEnum val> {
  85. bits<2> Documentation = val.Documentation;
  86. }
  87. /// Describes a checker. Every builtin checker has to be registered with the use
  88. /// of this class (out-of-trunk checkers loaded from plugins obviously don't).
  89. /// Note that a checker has a name (e.g.: 'NullDereference'), and a fullname,
  90. /// that is autogenerated with the help of the ParentPackage field, that also
  91. /// includes package names (e.g.: 'core.NullDereference').
  92. /// Example:
  93. /// def DereferenceChecker : Checker<"NullDereference">,
  94. /// HelpText<"Check for dereferences of null pointers">;
  95. class Checker<string name = ""> {
  96. string CheckerName = name;
  97. string HelpText;
  98. // This field is optional.
  99. list<CmdLineOption> CheckerOptions;
  100. // This field is optional.
  101. list<Checker> Dependencies;
  102. // This field is optional.
  103. list<Checker> WeakDependencies;
  104. bits<2> Documentation;
  105. Package ParentPackage;
  106. bit Hidden = 0;
  107. }
  108. /// Describes a list of checker options.
  109. class CheckerOptions<list<CmdLineOption> opts> {
  110. list<CmdLineOption> CheckerOptions = opts;
  111. }
  112. /// Describes (strong) dependencies in between checkers. This is important for
  113. /// modeling checkers, for example, MallocBase depends on the proper modeling of
  114. /// string operations, so it depends on CStringBase. A checker may only be
  115. /// enabled if none of its dependencies (transitively) is disabled. Dependencies
  116. /// are always registered before the dependent checker, and its checker
  117. /// callbacks are also evaluated sooner.
  118. /// One may only depend on a purely modeling checker (that emits no diagnostis).
  119. /// Example:
  120. /// def InnerPointerChecker : Checker<"InnerPointer">,
  121. /// HelpText<"Check for inner pointers of C++ containers used after "
  122. /// "re/deallocation">,
  123. /// Dependencies<[MallocBase]>;
  124. class Dependencies<list<Checker> Deps = []> {
  125. list<Checker> Dependencies = Deps;
  126. }
  127. /// Describes preferred registration and evaluation order in between checkers.
  128. /// Unlike strong dependencies, this expresses dependencies in between
  129. /// diagnostics, and *not* modeling. In the case of an unsatisfied (disabled)
  130. /// weak dependency, the dependent checker might still be registered. If the
  131. /// weak dependency is satisfied, it'll be registered, and its checker
  132. /// callbacks will be evaluated before the dependent checker. This can be used
  133. /// to ensure that a more specific warning would be displayed in place of a
  134. /// generic one, should multiple checkers detect the same bug. For example,
  135. /// non-null parameter bugs are detected by NonNullParamChecker due to the
  136. /// nonnull attribute, and StdLibraryFunctionsChecker as it models standard
  137. /// functions, and the former is the more specific one. While freeing a
  138. /// dangling pointer is a bug, if it is also a double free, we would like to
  139. /// recognize it as such first and foremost. This works best for fatal error
  140. /// node generation, otherwise both warnings may be present and in any order.
  141. class WeakDependencies<list<Checker> Deps = []> {
  142. list<Checker> WeakDependencies = Deps;
  143. }
  144. /// Marks a checker or a package hidden. Hidden entries are meant for developers
  145. /// only, and aren't exposed to end users.
  146. class Hidden { bit Hidden = 1; }