Add a HasSuppressionType method into SuppressionContext

Extending SuppressionContext to add a HasSuppressionType method that tells whether a certain suppression type is currently used or not. It's a step to implement issue suppressions for ASan, see http://reviews.llvm.org/D6280.

Reviewed at http://reviews.llvm.org/D6443

llvm-svn: 222954
This commit is contained in:
Kuba Brecka 2014-11-29 14:18:05 +00:00
parent c7e220f6e0
commit 4bd88e3deb
3 changed files with 24 additions and 1 deletions

View File

@ -70,6 +70,10 @@ bool TemplateMatch(char *templ, const char *str) {
ALIGNED(64) static char placeholder[sizeof(SuppressionContext)];
static SuppressionContext *suppression_ctx = 0;
SuppressionContext::SuppressionContext() : suppressions_(1), can_parse_(true) {
internal_memset(has_suppresson_type_, 0, sizeof(has_suppresson_type_));
}
SuppressionContext *SuppressionContext::Get() {
CHECK(suppression_ctx);
return suppression_ctx;
@ -96,6 +100,8 @@ void SuppressionContext::InitIfNecessary() {
bool SuppressionContext::Match(const char *str, SuppressionType type,
Suppression **s) {
if (!has_suppresson_type_[type])
return false;
can_parse_ = false;
uptr i;
for (i = 0; i < suppressions_.size(); i++)
@ -151,6 +157,7 @@ void SuppressionContext::Parse(const char *str) {
s.hit_count = 0;
s.weight = 0;
suppressions_.push_back(s);
has_suppresson_type_[s.type] = true;
}
if (end[0] == 0)
break;
@ -162,6 +169,10 @@ uptr SuppressionContext::SuppressionCount() const {
return suppressions_.size();
}
bool SuppressionContext::HasSuppressionType(SuppressionType type) const {
return has_suppresson_type_[type];
}
const Suppression *SuppressionContext::SuppressionAt(uptr i) const {
CHECK_LT(i, suppressions_.size());
return &suppressions_[i];

View File

@ -43,6 +43,7 @@ class SuppressionContext {
void Parse(const char *str);
bool Match(const char* str, SuppressionType type, Suppression **s);
uptr SuppressionCount() const;
bool HasSuppressionType(SuppressionType type) const;
const Suppression *SuppressionAt(uptr i) const;
void GetMatched(InternalMmapVector<Suppression *> *matched);
@ -54,8 +55,9 @@ class SuppressionContext {
static SuppressionContext *Get();
private:
SuppressionContext() : suppressions_(1), can_parse_(true) {}
SuppressionContext();
InternalMmapVector<Suppression> suppressions_;
bool has_suppresson_type_[SuppressionTypeCount];
bool can_parse_;
friend class SuppressionContextTest;

View File

@ -153,4 +153,14 @@ TEST_F(SuppressionContextTest, ParseType) {
EXPECT_EQ(0, strcmp((*Suppressions())[0].templ, "foo"));
}
TEST_F(SuppressionContextTest, HasSuppressionType) {
ctx_->Parse(
"race:foo\n"
"thread:bar\n");
EXPECT_TRUE(ctx_->HasSuppressionType(SuppressionRace));
EXPECT_TRUE(ctx_->HasSuppressionType(SuppressionThread));
EXPECT_FALSE(ctx_->HasSuppressionType(SuppressionMutex));
EXPECT_FALSE(ctx_->HasSuppressionType(SuppressionSignal));
}
} // namespace __sanitizer