Skip to content

Commit e9c1e17

Browse files
committed
gcc-parser: experimental support for smatch
1 parent d688ba1 commit e9c1e17

File tree

5 files changed

+880
-1
lines changed

5 files changed

+880
-1
lines changed

gcc-parser.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class AbstractTokenFilter: public ITokenizer {
6363
#define RE_EVENT_GCC "(?:(?:(?:fatal|internal) )?[a-z]+)"
6464
#define RE_EVENT_PROSPECTOR "(?:[A-Z]+[0-9]+\\[[a-z0-9]+\\])"
6565
#define RE_EVENT RE_EVENT_GCC "|" RE_EVENT_PROSPECTOR
66+
#define RE_FNC_SMATCH "(\\(null\\)|[_A-Za-z][_A-Za-z0-9]*)\\(\\)"
6667

6768
class Tokenizer: public ITokenizer {
6869
public:
@@ -73,7 +74,10 @@ class Tokenizer: public ITokenizer {
7374
reInc_("^(?:In file included| +) from " RE_LOCATION "[:,]"
7475
RE_TOOL_SUFFIX),
7576
reScope_("^" RE_LOCATION ": ([A-Z].+):" RE_TOOL_SUFFIX),
76-
reMsg_("^" RE_LOCATION /* evt/msg */ ": (" RE_EVENT "): (.*)$")
77+
reMsg_("^" RE_LOCATION /* evt/msg */ ": (" RE_EVENT "): (.*)$"),
78+
reSmatch_("^([^:]+):([0-9]+)() " /* file:line */
79+
RE_FNC_SMATCH /* fnc */
80+
" ([a-z]+): (.*)$") /* evt: msg */
7781
{
7882
}
7983

@@ -90,6 +94,7 @@ class Tokenizer: public ITokenizer {
9094
const boost::regex reInc_;
9195
const boost::regex reScope_;
9296
const boost::regex reMsg_;
97+
const boost::regex reSmatch_;
9398
};
9499

95100
EToken Tokenizer::readNext(DefEvent *pEvt) {
@@ -128,6 +133,12 @@ EToken Tokenizer::readNext(DefEvent *pEvt) {
128133
pEvt->event = "included_from";
129134
pEvt->msg = "Included from here.";
130135
}
136+
else if (boost::regex_match(line, sm, reSmatch_)) {
137+
tok = T_MSG;
138+
pEvt->event = sm[/* evt */ 5];
139+
pEvt->msg = sm[/* fnc */ 4] + "(): ";
140+
pEvt->msg += sm[/* msg */ 6];
141+
}
131142
else
132143
return T_UNKNOWN;
133144

@@ -391,6 +402,10 @@ bool BasicGccParser::exportAndReset(Defect *pDef) {
391402
// <--[shellcheck]
392403
def.checker = "SHELLCHECK_WARNING";
393404

405+
else if (tool == "smatch")
406+
// <--[smatch]
407+
def.checker = "SMATCH_WARNING";
408+
394409
else if (tool == "cppcheck" && !this->digCppcheckEvt(&def))
395410
// <--[cppcheck] ... assume cppcheck running with --template=gcc
396411
def.checker = "CPPCHECK_WARNING";

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ test_csgrep(csgrep "38-csparser-remediation" )
148148
test_csgrep(csgrep "39-csparser-remediation" )
149149
test_csgrep(csgrep "40-csparser-code-snippet" )
150150
test_csgrep(csgrep "41-gcc-parser-pylint" )
151+
test_csgrep(csgrep "42-gcc-parser-smatch" )
151152
test_csparser(csparser-5.8 00)
152153
test_csparser(csparser-5.8 01)
153154
test_csparser(csparser-5.8 02)

tests/csgrep/42-gcc-parser-smatch-args.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)