Skip to content

Commit 51d1758

Browse files
authored
fixed #11930 (Create daca report for valueFlowBailoutIncompleteVar) (#5417)
This provides a report of the top incomplete variables reported by the ValueFlow analysis. This is based on the implementation of the existing `--check-library` reports.
1 parent 3cbbb77 commit 51d1758

2 files changed

Lines changed: 51 additions & 24 deletions

File tree

tools/donate-cpu-server.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
2727
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
2828
# changes)
29-
SERVER_VERSION = "1.3.41"
29+
SERVER_VERSION = "1.3.42"
3030

3131
OLD_VERSION = '2.11'
3232

@@ -111,7 +111,7 @@ def overviewReport() -> str:
111111
#html += '<a href="head-valueFlowBailout">valueFlowBailout</a><br>\n'
112112
#html += '<a href="head-bailoutUninitVar">bailoutUninitVar</a><br>\n'
113113
#html += '<a href="head-symbolDatabaseWarning">symbolDatabaseWarning</a><br>\n'
114-
#html += '<a href="head-valueFlowBailoutIncompleteVar">valueFlowBailoutIncompleteVar</a><br>\n'
114+
html += '<a href="value_flow_bailout_incomplete_var.html">valueFlowBailoutIncompleteVar report</a><br>\n'
115115
html += '<br>\n'
116116
html += 'Important errors:<br>\n'
117117
html += '<a href="head-cppcheckError">cppcheckError</a><br>\n'
@@ -897,17 +897,23 @@ def timeReportSlow(resultPath: str) -> str:
897897

898898

899899
def check_library_report(result_path: str, message_id: str) -> str:
900-
if message_id not in ('checkLibraryNoReturn', 'checkLibraryFunction', 'checkLibraryUseIgnore', 'checkLibraryCheckType'):
900+
if message_id not in ('checkLibraryNoReturn', 'checkLibraryFunction', 'checkLibraryUseIgnore', 'checkLibraryCheckType', 'valueFlowBailoutIncompleteVar'):
901901
error_message = 'Invalid value ' + message_id + ' for message_id parameter.'
902902
print_ts(error_message)
903903
return error_message
904904

905-
if message_id == 'checkLibraryCheckType':
905+
if message_id == 'valueFlowBailoutIncompleteVar':
906+
metric = 'variables'
907+
m_column = 'Variable'
908+
metric_link = 'incomplete_var'
909+
elif message_id == 'checkLibraryCheckType':
906910
metric = 'types'
907911
m_column = 'Type'
912+
metric_link = 'check_library'
908913
else:
909914
metric = 'functions'
910915
m_column = 'Function'
916+
metric_link = 'check_library'
911917

912918
functions_shown_max = 5000
913919
html = '<!DOCTYPE html>\n'
@@ -933,25 +939,32 @@ def check_library_report(result_path: str, message_id: str) -> str:
933939
else:
934940
# Current package, parse on
935941
continue
936-
if line == 'info messages:\n':
937-
info_messages = True
938-
if not info_messages:
939-
continue
942+
if message_id != 'valueFlowBailoutIncompleteVar':
943+
if line == 'info messages:\n':
944+
info_messages = True
945+
if not info_messages:
946+
continue
940947
if line.endswith('[' + message_id + ']\n'):
941-
if message_id == 'checkLibraryFunction':
942-
function_name = line[(line.find('for function ') + len('for function ')):line.rfind('[') - 1]
948+
if message_id == 'valueFlowBailoutIncompleteVar':
949+
marker = 'incomplete variable '
950+
function_name = line[(line.find(marker) + len(marker)):line.rfind('[') - 1]
951+
elif message_id == 'checkLibraryFunction':
952+
marker = 'for function '
953+
function_name = line[(line.find(marker) + len(marker)):line.rfind('[') - 1]
943954
elif message_id == 'checkLibraryCheckType':
944-
function_name = line[(line.find('configuration for ') + len('configuration for ')):line.rfind('[') - 1]
955+
marker = 'configuration for '
956+
function_name = line[(line.find(marker) + len(marker)):line.rfind('[') - 1]
945957
else:
946-
function_name = line[(line.find(': Function ') + len(': Function ')):line.rfind('should have') - 1]
958+
marker = ': Function '
959+
function_name = line[(line.find(marker) + len(marker)):line.rfind('should have') - 1]
947960
function_counts[function_name] = function_counts.setdefault(function_name, 0) + 1
948961

949962
function_details_list = []
950963
for function_name, count in sorted(list(function_counts.items()), key=operator.itemgetter(1), reverse=True):
951964
if len(function_details_list) >= functions_shown_max:
952965
break
953966
function_details_list.append(str(count).rjust(column_widths[0]) + ' ' +
954-
'<a href="check_library-' + urllib.parse.quote_plus(function_name) + '">' + function_name + '</a>\n')
967+
'<a href="' + metric_link + '-' + urllib.parse.quote_plus(function_name) + '">' + function_name + '</a>\n')
955968

956969
html += ''.join(function_details_list)
957970
html += '</pre>\n'
@@ -961,12 +974,15 @@ def check_library_report(result_path: str, message_id: str) -> str:
961974

962975

963976
# Lists all checkLibrary* messages regarding the given function name
964-
def check_library_function_name(result_path: str, function_name: str) -> str:
965-
function_name = urllib.parse.unquote_plus(function_name)
966-
if function_name.endswith('()'):
967-
id = '[checkLibrary'
977+
def check_library_function_name(result_path: str, function_name: str, is_var: bool=False) -> str:
978+
if is_var:
979+
id = '[valueFlowBailoutIncompleteVar'
968980
else:
969-
id = '[checkLibraryCheckType]'
981+
function_name = urllib.parse.unquote_plus(function_name)
982+
if function_name.endswith('()'):
983+
id = '[checkLibrary'
984+
else:
985+
id = '[checkLibraryCheckType]'
970986
output_lines_list = []
971987
for filename in glob.glob(result_path + '/*'):
972988
if not os.path.isfile(filename) or filename.endswith('.diff'):
@@ -977,12 +993,16 @@ def check_library_function_name(result_path: str, function_name: str) -> str:
977993
for line in open(filename, 'rt'):
978994
if line.startswith('ftp://'):
979995
url = line
980-
elif line.startswith('cppcheck-options:'):
996+
continue
997+
if line.startswith('cppcheck-options:'):
981998
cppcheck_options = line
982-
elif line == 'info messages:\n':
983-
info_messages = True
984-
if not info_messages:
985999
continue
1000+
if not is_var:
1001+
if line == 'info messages:\n':
1002+
info_messages = True
1003+
continue
1004+
if not info_messages:
1005+
continue
9861006
if id in line:
9871007
if (' ' + function_name + ' ') in line:
9881008
if url:
@@ -1115,6 +1135,13 @@ def run(self):
11151135
function_name = url[len('/check_library-'):]
11161136
text = check_library_function_name(self.infoPath, function_name)
11171137
httpGetResponse(self.connection, text, 'text/plain')
1138+
elif url == '/value_flow_bailout_incomplete_var.html':
1139+
text = check_library_report(self.resultPath, message_id='valueFlowBailoutIncompleteVar')
1140+
httpGetResponse(self.connection, text, 'text/html')
1141+
elif url.startswith('/incomplete_var-'):
1142+
var_name = url[len('/incomplete_var-'):]
1143+
text = check_library_function_name(self.resultPath, var_name, True)
1144+
httpGetResponse(self.connection, text, 'text/plain')
11181145
else:
11191146
filename = resultPath + url
11201147
if not os.path.isfile(filename):

tools/donate_cpu_lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1717
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1818
# changes)
19-
CLIENT_VERSION = "1.3.47"
19+
CLIENT_VERSION = "1.3.48"
2020

2121
# Timeout for analysis with Cppcheck in seconds
2222
CPPCHECK_TIMEOUT = 30 * 60
@@ -443,7 +443,7 @@ def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True):
443443
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
444444
# Reference for GNU C: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
445445
options = libs + ' --showtime=top5 --check-library --inconclusive --enable=style,information --inline-suppr --disable=missingInclude --suppress=unmatchedSuppression --template=daca2'
446-
options += ' --debug-warnings --suppress=autoNoType --suppress=valueFlowBailout --suppress=bailoutUninitVar --suppress=symbolDatabaseWarning --suppress=valueFlowBailoutIncompleteVar'
446+
options += ' --debug-warnings --suppress=autoNoType --suppress=valueFlowBailout --suppress=bailoutUninitVar --suppress=symbolDatabaseWarning'
447447
options += ' -D__GNUC__ --platform=unix64'
448448
options_rp = options + ' -rp={}'.format(dir_to_scan)
449449
if __make_cmd == 'msbuild.exe':

0 commit comments

Comments
 (0)