IssueHash.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---------- IssueHash.h - Generate identification hashes ----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_ANALYSIS_ISSUEHASH_H
  14. #define LLVM_CLANG_ANALYSIS_ISSUEHASH_H
  15. #include "llvm/ADT/SmallString.h"
  16. namespace clang {
  17. class Decl;
  18. class FullSourceLoc;
  19. class LangOptions;
  20. /// Returns an opaque identifier for a diagnostic.
  21. ///
  22. /// This opaque identifier is intended to be stable even when the source code
  23. /// is changed. It allows to track diagnostics in the long term, for example,
  24. /// find which diagnostics are "new", maintain a database of suppressed
  25. /// diagnostics etc.
  26. ///
  27. /// We may introduce more variants of issue hashes in the future
  28. /// but older variants will still be available for compatibility.
  29. ///
  30. /// This hash is based on the following information:
  31. /// - Name of the checker that emitted the diagnostic.
  32. /// - Warning message.
  33. /// - Name of the enclosing declaration.
  34. /// - Contents of the line of code with the issue, excluding whitespace.
  35. /// - Column number (but not the line number! - which makes it stable).
  36. llvm::SmallString<32> getIssueHash(const FullSourceLoc &IssueLoc,
  37. llvm::StringRef CheckerName,
  38. llvm::StringRef WarningMessage,
  39. const Decl *IssueDecl,
  40. const LangOptions &LangOpts);
  41. /// Get the unhashed string representation of the V1 issue hash.
  42. /// When hashed, it becomes the actual issue hash. Useful for testing.
  43. /// See GetIssueHashV1() for more information.
  44. std::string getIssueString(const FullSourceLoc &IssueLoc,
  45. llvm::StringRef CheckerName,
  46. llvm::StringRef WarningMessage,
  47. const Decl *IssueDecl, const LangOptions &LangOpts);
  48. } // namespace clang
  49. #endif
  50. #ifdef __GNUC__
  51. #pragma GCC diagnostic pop
  52. #endif