xref: /openbsd-src/gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_suppressions.h (revision 3cab2bb3f667058bece8e38b12449a63a9d73c4b)
1*3cab2bb3Spatrick //===-- sanitizer_suppressions.h --------------------------------*- C++ -*-===//
2*3cab2bb3Spatrick //
3*3cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*3cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
5*3cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*3cab2bb3Spatrick //
7*3cab2bb3Spatrick //===----------------------------------------------------------------------===//
8*3cab2bb3Spatrick //
9*3cab2bb3Spatrick // Suppression parsing/matching code.
10*3cab2bb3Spatrick //
11*3cab2bb3Spatrick //===----------------------------------------------------------------------===//
12*3cab2bb3Spatrick #ifndef SANITIZER_SUPPRESSIONS_H
13*3cab2bb3Spatrick #define SANITIZER_SUPPRESSIONS_H
14*3cab2bb3Spatrick 
15*3cab2bb3Spatrick #include "sanitizer_common.h"
16*3cab2bb3Spatrick #include "sanitizer_atomic.h"
17*3cab2bb3Spatrick #include "sanitizer_internal_defs.h"
18*3cab2bb3Spatrick 
19*3cab2bb3Spatrick namespace __sanitizer {
20*3cab2bb3Spatrick 
21*3cab2bb3Spatrick struct Suppression {
SuppressionSuppression22*3cab2bb3Spatrick   Suppression() { internal_memset(this, 0, sizeof(*this)); }
23*3cab2bb3Spatrick   const char *type;
24*3cab2bb3Spatrick   char *templ;
25*3cab2bb3Spatrick   atomic_uint32_t hit_count;
26*3cab2bb3Spatrick   uptr weight;
27*3cab2bb3Spatrick };
28*3cab2bb3Spatrick 
29*3cab2bb3Spatrick class SuppressionContext {
30*3cab2bb3Spatrick  public:
31*3cab2bb3Spatrick   // Create new SuppressionContext capable of parsing given suppression types.
32*3cab2bb3Spatrick   SuppressionContext(const char *supprression_types[],
33*3cab2bb3Spatrick                      int suppression_types_num);
34*3cab2bb3Spatrick 
35*3cab2bb3Spatrick   void ParseFromFile(const char *filename);
36*3cab2bb3Spatrick   void Parse(const char *str);
37*3cab2bb3Spatrick 
38*3cab2bb3Spatrick   bool Match(const char *str, const char *type, Suppression **s);
39*3cab2bb3Spatrick   uptr SuppressionCount() const;
40*3cab2bb3Spatrick   bool HasSuppressionType(const char *type) const;
41*3cab2bb3Spatrick   const Suppression *SuppressionAt(uptr i) const;
42*3cab2bb3Spatrick   void GetMatched(InternalMmapVector<Suppression *> *matched);
43*3cab2bb3Spatrick 
44*3cab2bb3Spatrick  private:
45*3cab2bb3Spatrick   static const int kMaxSuppressionTypes = 64;
46*3cab2bb3Spatrick   const char **const suppression_types_;
47*3cab2bb3Spatrick   const int suppression_types_num_;
48*3cab2bb3Spatrick 
49*3cab2bb3Spatrick   InternalMmapVector<Suppression> suppressions_;
50*3cab2bb3Spatrick   bool has_suppression_type_[kMaxSuppressionTypes];
51*3cab2bb3Spatrick   bool can_parse_;
52*3cab2bb3Spatrick };
53*3cab2bb3Spatrick 
54*3cab2bb3Spatrick }  // namespace __sanitizer
55*3cab2bb3Spatrick 
56*3cab2bb3Spatrick #endif  // SANITIZER_SUPPRESSIONS_H
57