[llvm-remarkutil] filter: Add --exclude flag (#187163)

Add --exclude to invert filter behavior, keeping all remarks excluding
those matching the filter.

Pull Request: https://github.com/llvm/llvm-project/pull/187163
This commit is contained in:
Tobias Stadler 2026-03-18 10:39:35 -07:00 committed by GitHub
parent 7166468957
commit d54da68973
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,9 @@
RUN: llvm-remarkutil filter --exclude --function=func1 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace
; CHECK: --- !Missed
; CHECK: Name: Remark2
; CHECK: ...
; CHECK-NEXT: --- !Analysis
; CHECK: Name: Remark3
; CHECK: ...
; CHECK-NOT: {{.}}

View File

@ -40,6 +40,11 @@ static cl::list<std::string> InputFileNames(
cl::Positional, cl::OneOrMore, cl::list_init<std::string>({"-"}),
cl::desc("<input file> [<input file> ...]"), cl::sub(FilterSub));
static cl::opt<bool>
ExcludeOpt("exclude",
cl::desc("Keep all remarks except those matching the filter"),
cl::init(false), cl::sub(FilterSub));
REMARK_FILTER_SETUP_FUNC()
namespace {
@ -47,6 +52,7 @@ namespace {
class FilterTool {
public:
Filters Filter;
bool Exclude = false;
FilterTool(Filters Filter) : Filter(std::move(Filter)) {}
~FilterTool() { finalize(); }
@ -67,7 +73,7 @@ public:
auto MaybeRemark = Parser.next();
for (; MaybeRemark; MaybeRemark = Parser.next()) {
Remark &Remark = **MaybeRemark;
if (!Filter.filterRemark(Remark))
if (Filter.filterRemark(Remark) == Exclude)
continue;
Serializer->emit(Remark);
}
@ -116,6 +122,7 @@ static Error tryFilter() {
if (!MaybeFilter)
return MaybeFilter.takeError();
FilterTool Tool(std::move(*MaybeFilter));
Tool.Exclude = ExcludeOpt;
for (auto &InputFileName : InputFileNames) {
if (Error E = Tool.processInputFile(InputFileName))