Skip to content

Commit 515dbd3

Browse files
committed
gcc-parser: fix parsing of sidebar produced by gcc-9.2.1
Reported-by: Lukas Zaoral
1 parent f03447f commit 515dbd3

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

gcc-parser.cc

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum EToken {
3232
T_INC,
3333
T_SCOPE,
3434
T_MSG,
35+
T_SIDEBAR,
3536
T_MARKER
3637
};
3738

@@ -70,6 +71,7 @@ class Tokenizer: public ITokenizer {
7071
Tokenizer(std::istream &input):
7172
input_(input),
7273
lineNo_(0),
74+
reSideBar_("^ *((([0-9]+)? \\| )|(\\+\\+\\+ \\|\\+)).*$"),
7375
reMarker_("^ *[ ~^|]+$"),
7476
reInc_("^(?:In file included| +) from " RE_LOCATION "[:,]"
7577
RE_TOOL_SUFFIX),
@@ -90,6 +92,7 @@ class Tokenizer: public ITokenizer {
9092
private:
9193
std::istream &input_;
9294
int lineNo_;
95+
const boost::regex reSideBar_;
9396
const boost::regex reMarker_;
9497
const boost::regex reInc_;
9598
const boost::regex reScope_;
@@ -112,6 +115,14 @@ EToken Tokenizer::readNext(DefEvent *pEvt) {
112115
*pEvt = DefEvent();
113116
pEvt->msg = line;
114117

118+
// check for line markers produced by gcc-9.2.1 (a.k.a. sidebar)
119+
if (boost::regex_match(pEvt->msg, reSideBar_))
120+
// xxx.c:2:1: note: include '<stdlib.h>' or provide a declaration...
121+
// 1 | #include <stdio.h>
122+
// +++ |+#include <stdlib.h>
123+
// 2 |
124+
return T_SIDEBAR;
125+
115126
if (boost::regex_match(line, reMarker_))
116127
return T_MARKER;
117128

@@ -222,12 +233,28 @@ EToken MarkerConverter::readNext(DefEvent *pEvt) {
222233

223234
tok = slave_->readNext(pEvt);
224235
lineNo_ = slave_->lineNo();
225-
if (T_UNKNOWN != tok)
226-
return tok;
236+
switch (tok) {
237+
case T_SIDEBAR:
238+
pEvt->event = "#";
239+
tok = T_MSG;
240+
break;
241+
242+
case T_UNKNOWN:
243+
break;
244+
245+
default:
246+
return tok;
247+
}
227248

228249
lastTok_ = slave_->readNext(&lastEvt_);
229-
if (T_MARKER != lastTok_)
230-
return tok;
250+
switch (lastTok_) {
251+
case T_SIDEBAR:
252+
case T_MARKER:
253+
break;
254+
255+
default:
256+
return tok;
257+
}
231258

232259
// translate both events to comments
233260
lastEvt_.event = pEvt->event = "#";
@@ -492,6 +519,7 @@ bool BasicGccParser::getNext(Defect *pDef) {
492519
hasKeyEvent_ = true;
493520
break;
494521

522+
case T_SIDEBAR:
495523
case T_MARKER:
496524
case T_UNKNOWN:
497525
this->handleError();

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ test_csgrep(csgrep "46-cov-json-v2" )
166166
test_csgrep(csgrep "47-csparser-new-key-evts" )
167167
test_csgrep(csgrep "48-csparser-missing-break-key-evt")
168168
test_csgrep(csgrep "49-csparser-findbugs-jsr166" )
169+
test_csgrep(csgrep "50-gcc-parser-gcc-9.2.1" )
169170
test_csparser(csparser-5.8 00)
170171
test_csparser(csparser-5.8 01)
171172
test_csparser(csparser-5.8 02)

tests/csgrep/50-gcc-parser-gcc-9.2.1-args.txt

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test2.c: In function ‘foo’:
2+
test2.c:1:14: warning: implicit declaration of function ‘abort’ [-Wimplicit-function-declaration]
3+
1 | void foo() { abort(); }
4+
| ^~~~~
5+
test2.c:1:14: warning: incompatible implicit declaration of built-in function ‘abort’
6+
test2.c:1:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘abort’
7+
+++ |+#include <stdlib.h>
8+
1 | void foo() { abort(); }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Error: COMPILER_WARNING:
2+
test2.c: scope_hint: In function ‘foo’
3+
test2.c:1:14: warning: implicit declaration of function ‘abort’ [-Wimplicit-function-declaration]
4+
# 1 | void foo() { abort(); }
5+
# | ^~~~~
6+
7+
Error: COMPILER_WARNING:
8+
test2.c:1:14: warning: incompatible implicit declaration of built-in function ‘abort’
9+
test2.c:1:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘abort’
10+
# +++ |+#include <stdlib.h>
11+
# 1 | void foo() { abort(); }

0 commit comments

Comments
 (0)