Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csgrep --warning-rate-limit: drop location from key events #185

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/defect.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ struct DefEvent {
event(event)
{
}

void clearLoc()
{
this->fileName.clear();
this->line = 0;
this->column = 0;
this->hSize = 0;
this->vSize = 0;
}
};

///< return (end - beg) if it is positive and fits into target type, 0 otherwise
Expand Down
3 changes: 3 additions & 0 deletions src/lib/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ void RateLimitter::flush()
evtErr.event = "error[too-many]";
evtErr.msg = err.str();

// drop location from the key event to ease finding deduplication
evtErr.clearLoc();

// construct a note event
note << (cnt - d->rateLimit) << " occurrences of "
<< evtNote.event << " were discarded because of this";
Expand Down
16 changes: 9 additions & 7 deletions src/lib/parser-cov.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,19 @@ EToken ErrFileLexer::readNext()
return T_UNKNOWN;
}

// read file name, event, and msg
evt_.fileName = sm[/* file */ 1];
evt_.event = sm[/* event */ 4];
evt_.msg = sm[/* msg */ 5];
// read file name
evt_.fileName = sm[/* file */ 1];
if (evt_.fileName == "<unknown>")
evt_.fileName.clear();

// parse line number
// parse line/col
evt_.line = parseInt(sm[/* line */ 2]);

// parse column number
evt_.column = parseInt(sm[/* col */ 3]);

// read event and msg
evt_.event = sm[/* event */ 4];
evt_.msg = sm[/* msg */ 5];

return T_EVENT;
}

Expand Down
24 changes: 15 additions & 9 deletions src/lib/writer-cov.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,8 @@ void CovWriter::handleDef(const Defect &def)
if (!isKeyEvt)
str << d->cw.setColor(C_DARK_GRAY);

if (!evt.fileName.empty())
str << evt.fileName << ":";

if (0 < evt.line)
str << evt.line << ":";

if (0 < evt.column)
str << evt.column << ":";

if (evt.event == "#") {
// comment --> ignore location info
str << d->cw.setColor(C_LIGHT_CYAN) << "#";

static CtxEventDetector detector;
Expand All @@ -86,6 +78,20 @@ void CovWriter::handleDef(const Defect &def)
}
}
else {
// write file name
std::string fn = evt.fileName;
if (fn.empty())
fn = "<unknown>";
str << fn << ":";

// write line/col
if (0 < evt.line) {
str << evt.line << ":";
if (0 < evt.column)
str << evt.column << ":";
}

// write event
str << " ";
if (!evt.event.empty())
str << d->cw.setColorIf(isKeyEvt, C_WHITE) << evt.event
Expand Down
10 changes: 4 additions & 6 deletions tests/csgrep/0110-warning-rate-limit-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1880,9 +1880,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "./doc/example/compiler-etc-dependencies/example-sessions/ompi-defaults.sh",
"line": 3,
"column": 8,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "115 occurrences of note[SC2086] exceeded the specified limit 16",
"verbosity_level": 0
Expand All @@ -1905,9 +1904,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "./init/bash_completion.in",
"line": 128,
"column": 37,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "29 occurrences of warning[SC2207] exceeded the specified limit 16",
"verbosity_level": 0
Expand Down
28 changes: 14 additions & 14 deletions tests/csgrep/0116-csgrep-warning-rate-limit-stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4988,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of var_deref_model exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -52,8 +52,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 5058,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "3 occurrences of var_deref_op exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -77,8 +77,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4600,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "2 occurrences of alloc_strlen exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -102,8 +102,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 3811,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of leaked_handle exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -127,8 +127,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 4786,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "2 occurrences of leaked_storage exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -151,8 +151,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 402,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of fs_check_call exceeded the specified limit 1",
"verbosity_level": 0
Expand All @@ -176,8 +176,8 @@
"key_event_idx": 0,
"events": [
{
"file_name": "/builddir/build/BUILD/units-2.22/units.c",
"line": 550,
"file_name": "",
"line": 0,
"event": "error[too-many]",
"message": "1 occurrences of uninit_use_in_call exceeded the specified limit 1",
"verbosity_level": 0
Expand Down
Empty file.
Loading