Skip to content

Commit 58cbb33

Browse files
authored
Fix #14590: Missing id in DumpData type-info (#8451)
1 parent cf3f0fa commit 58cbb33

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

lib/tokenize.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,18 @@ void Tokenizer::simplifyTypedef()
11151115
syntaxError(t.second.getTypedefToken());
11161116
} else {
11171117
const Token* const typedefToken = t.second.getTypedefToken();
1118+
const Token* const nameToken = t.second.nameToken();
11181119
TypedefInfo typedefInfo;
11191120
typedefInfo.name = t.second.name();
1120-
typedefInfo.filename = list.file(typedefToken);
1121-
typedefInfo.lineNumber = typedefToken->linenr();
1122-
typedefInfo.column = typedefToken->column();
1123-
if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {") && typedefToken->strAt(2) == typedefInfo.name) {
1124-
typedefInfo.tagLine = typedefToken->tokAt(2)->linenr();
1125-
typedefInfo.tagColumn = typedefToken->tokAt(2)->column();
1121+
typedefInfo.filename = list.file(nameToken);
1122+
typedefInfo.lineNumber = nameToken->linenr();
1123+
typedefInfo.column = nameToken->column();
1124+
if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {")) {
1125+
typedefInfo.originalName = typedefToken->strAt(2);
1126+
if (typedefToken->strAt(2) == typedefInfo.name) {
1127+
typedefInfo.tagLine = typedefToken->tokAt(2)->linenr();
1128+
typedefInfo.tagColumn = typedefToken->tokAt(2)->column();
1129+
}
11261130
}
11271131
typedefInfo.used = t.second.isUsed();
11281132
typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken());
@@ -6380,6 +6384,12 @@ std::string Tokenizer::dumpTypedefInfo() const
63806384
outs += typedefInfo.name;
63816385
outs += "\"";
63826386

6387+
if (!typedefInfo.originalName.empty()) {
6388+
outs += " originalName=\"";
6389+
outs += typedefInfo.originalName;
6390+
outs += "\"";
6391+
}
6392+
63836393
outs += " file=\"";
63846394
outs += ErrorLogger::toxml(typedefInfo.filename);
63856395
outs += "\"";

lib/tokenize.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ class CPPCHECKLIB Tokenizer {
698698
};
699699
struct TypedefInfo {
700700
std::string name;
701+
std::string originalName;
701702
std::string filename;
702703
int lineNumber;
703704
int column;

test/cli/other_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def test_addon_misra(tmpdir):
420420
assert lines == [
421421
'Checking {} ...'.format(test_file)
422422
]
423-
assert stderr == '{}:2:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n^\n'.format(test_file)
423+
assert stderr == '{}:2:13: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n ^\n'.format(test_file)
424424

425425

426426
def test_addon_y2038(tmpdir):
@@ -2674,7 +2674,7 @@ def __test_addon_suppr(tmp_path, extra_args):
26742674
assert exitcode == 0, stdout
26752675
assert stdout == ''
26762676
assert stderr.splitlines() == [
2677-
'{}:4:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]'.format(test_file),
2677+
'{}:4:13: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]'.format(test_file),
26782678
]
26792679

26802680

test/testsimplifytypedef.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,7 +4615,7 @@ class TestSimplifyTypedef : public TestFixture {
46154615
void typedefInfo1() {
46164616
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
46174617
ASSERT_EQUALS(" <typedef-info>\n"
4618-
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4618+
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"13\" used=\"1\" isFunctionPointer=\"0\"/>\n"
46194619
" </typedef-info>\n",
46204620
xml);
46214621
}
@@ -4627,7 +4627,7 @@ class TestSimplifyTypedef : public TestFixture {
46274627
" typedef fp16 ( *pfp16 ) ( void );\n"
46284628
"}\n");
46294629
ASSERT_EQUALS(" <typedef-info>\n"
4630-
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"1\" used=\"1\" isFunctionPointer=\"1\">\n"
4630+
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"17\" used=\"1\" isFunctionPointer=\"1\">\n"
46314631
" <token line=\"2\" column=\"1\" str=\"typedef\"/>\n"
46324632
" <token line=\"2\" column=\"9\" str=\"void\"/>\n"
46334633
" <token line=\"2\" column=\"14\" str=\"(\"/>\n"
@@ -4639,7 +4639,7 @@ class TestSimplifyTypedef : public TestFixture {
46394639
" <token line=\"2\" column=\"33\" str=\"n\"/>\n"
46404640
" <token line=\"2\" column=\"35\" str=\")\"/>\n"
46414641
" </info>\n"
4642-
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4642+
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"22\" used=\"1\" isFunctionPointer=\"0\"/>\n"
46434643
" <info name=\"pfp16\" file=\"file.c\" line=\"4\" column=\"4\" used=\"0\" isFunctionPointer=\"1\">\n"
46444644
" <token line=\"4\" column=\"4\" str=\"typedef\"/>\n"
46454645
" <token line=\"4\" column=\"12\" str=\"void\"/>\n"
@@ -4677,7 +4677,7 @@ class TestSimplifyTypedef : public TestFixture {
46774677
"} coord;\n"
46784678
"coord c;");
46794679
ASSERT_EQUALS(" <typedef-info>\n"
4680-
" <info name=\"coord\" file=\"file.c\" line=\"1\" column=\"1\" tagline=\"1\" tagcolumn=\"16\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4680+
" <info name=\"coord\" originalName=\"coord\" file=\"file.c\" line=\"4\" column=\"3\" tagline=\"1\" tagcolumn=\"16\" used=\"1\" isFunctionPointer=\"0\"/>\n"
46814681
" </typedef-info>\n", xml);
46824682
}
46834683
};

0 commit comments

Comments
 (0)