-
Notifications
You must be signed in to change notification settings - Fork 106
Add clang-tidy script; make the least-impact changes found by clang-tidy #1518
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
Conversation
|
CLANG-FORMAT TEST - FAILED (on last commit): |
fb8c802 to
2cc5467
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CLANG-FORMAT TEST - FAILED (on last commit): |
1 similar comment
|
CLANG-FORMAT TEST - FAILED (on last commit): |
bdaca56 to
83320b0
Compare
|
CLANG-FORMAT TEST - PASSED |
| fflush(stdout); | ||
|
|
||
| int launch_sst = execve(real_binary_path, argv, environ); | ||
| free(real_binary_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy complained about a possible memory leak in real_binary_path.
| { | ||
| printf("SST-Core Version (" PACKAGE_VERSION); | ||
| if ( strcmp(SSTCORE_GIT_HEADSHA, PACKAGE_VERSION) ) { | ||
| if ( strcmp(SSTCORE_GIT_HEADSHA, PACKAGE_VERSION) != 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy complained about the integer result of strcmp() being converted to bool without a comparison or boolean operator like !. I added != 0 which gets rid of the warning and has the same effect, but I would double-check this logic.
| if ( columns ) { | ||
| errno = E_OK; | ||
| uint32_t x = strtoul(getenv("COLUMNS"), nullptr, 0); | ||
| uint32_t x = strtoul(columns, nullptr, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy complained about getenv("COLUMNS") possibly passing nullptr as the first argument of strtoul(), even though we test getenv("COLUMNS") above. By loading getenv("COLUMNS") into columns and making sure it is not nullptr before passing it to strtoul(), the warning goes away, besides it being more efficient.
|
|
||
| } // namespace Core | ||
| } // namespace SST | ||
| } // namespace SST::Core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were still a few places where nested namespace names were not used. clang-tidy was able to fix these automatically, although it sometimes left the old namespace closing comment around, so I had to manually remove them.
| */ | ||
| decimal_fixedpoint& operator=(const decimal_fixedpoint& v) | ||
| { | ||
| if ( &v == this ) return *this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy complained about decimal_fixedpoint's assignment operator not checking for self-assignment.
| } | ||
|
|
||
| delete[] pathCopy; | ||
| free(pathCopy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy complained about strcpy() being inherently insecure. Since here we are simply allocating and copying a string, strdup() is simpler, and removes the warning.
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
| if ( nullptr != envConfigPaths ) { | ||
| char* envConfigPathBuffer = (char*)malloc(sizeof(char) * (strlen(envConfigPaths) + 1)); | ||
| strcpy(envConfigPathBuffer, envConfigPaths); | ||
| char* envConfigPathBuffer = strdup(envConfigPaths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again, but here, the old code used malloc()/free() instead of new[]/delete[].
| #include "sst/core/model/configGraph.h" | ||
| #include "sst/core/warnmacros.h" | ||
|
|
||
| #include <cstdlib> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are numerous places where C-style headers were replaced with C++ headers ( <stdlib.h> -> <cstdlib> etc.).
| namespace SST { | ||
|
|
||
| using genPythonModuleFunction = void* (*)(void); | ||
| using genPythonModuleFunction = void* (*)(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(void) function parameter lists are the same as () in C++
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
3 similar comments
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
berquist
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This review is for the script only, and not the actual clang-tidy checks used.
|
Status Flag 'Pre-Merge Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
All Jobs Finished; status = PASSED, However Inspection must be performed before merge can occur... |
|
CLANG-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
6535fca to
95a1b12
Compare
|
CLANG-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED by label AT: PRE-TEST INSPECTED! Autotester is Removing Label; this inspection will remain valid until a new commit to source branch is performed. |
|
Status Flag 'Pull Request AutoTester' - Testing Jenkins Projects: Pull Request Auto Testing STARTING (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-15-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
Using Repos:
Pull Request Author: leekillough |
|
Status Flag 'Pull Request AutoTester' - Jenkins Testing: all Jobs PASSED Pull Request Auto Testing has PASSED (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.9_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-15-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
|
|
Status Flag 'Pre-Merge Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
All Jobs Finished; status = PASSED, However Inspection must be performed before merge can occur... |
|
Status Flag 'Pre-Merge Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED AND APPROVED by [ feldergast ]! |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
Items addressed. Can revisit at a future date if anything else comes up.
This adds a
clang-tidy.shscript which runsclang-tidywith a modest default set of checks, a more aggressive--pickyset of checks, and a--checksoption for specifying specific tests.--fixcan be used to invoke theclang-tidyautomatic fixer, and it modifies files in the working tree similar to howtest-includes.pl --fixautomatically adds#includes.This
clang-tidy.shis not intended for CI runs, but for periodic manual runs to detect potential issues and to modernize the SST code to modern C++ idioms.I recommend running it with no arguments at first, inspecting the output file, and if one of the suggestions is acceptable, running it with the
--fix --checks <check_name>with the check name listed in brackets near the suggestion ([<check_name>]), running tests, and merging the changes if they are acceptable. Some of the automatic fixes might require massaging the code after it is edited, because it is not always perfect.I found one
va_argleak (va_end()was not called), and I found a reversed name string comparison. I also saw anif ( strcmp(...) )whichclang-tidywarned about because theintresult was implicitly converted tobool, but I only added!= 0since I am not sure whether the comparison was reversed or not.A self-assignment check had to be added to
decimal_fixedpoint.clang-tidydetected that self-assignment wasn't accounted for.There were warnings about
strcpy()being insecure, but in two such cases thestrcpy()was preceded by amalloc()ornew[]and both the allocation andstrcpy()could be replaced withstrdup().I will add comments below each of these changes.
The changes are minimal, to avoid disruptions, but the script is robust enough to be used in the future for
clang-tidyresearch into possible issues, as well as ideas for modernizing the code.