-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add -Werror to acceptance builds for C and CPP #4369
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
57ef039
to
a558412
Compare
It caught the warning as an error. Will remove the OTA test change and put in a final git commit:
|
a558412
to
dcf5340
Compare
fe004b3
to
82f719a
Compare
Ugh, looks like many examples and even several libraries have problems when -Wall is enabled. This is not as straightforward as I'd hoped. |
I very much like the idea of -Wall for the tests. Should we be using -Wextra too ? |
At some point, maybe. Right now, though, it's looking like 10s to 100s of changes will be required to get all the examples to build w/o warning-errors. Some changes will be in the libraries, not just the sample code, too, so it's going to be somewhat intrusive. I need to find a way to get the Travis tests to dump raw output from arduino-builder to get a good list, because individually building the dozens of examples is painful and slow... |
9a316ac
to
985ea3a
Compare
Use platform.local.txt to add -Werror to GCC for the build of all code. Any warnings on a submitted patch will cause an error. Several examples and libraries had warnings/errors (missing returns on functions). Clean those up with this commit as well.
985ea3a
to
50b282a
Compare
This is now completed and there are no errors or warnings reported when run with -Wall -Werror as part of the build process. Ready for review. Most changes were trivial. A couple library functions had missing returns in non-void functions that were either converted to void fcns()s or updated to actually report success/failure. The only one that's a little squirrely is in DNS.cpp where they were accessing a byte array as several uint16_t*s. Because the offsets in the byte array were all even it worked, but it does produce a warning in GCC about type-punning. These were replaced by a fully legal (even on odd-offset) memcpy of the 2-bytes to a local uint16_t and using that staging value instead. |
XR = constrain(XR, MIN_X,MAX_X); | ||
YU = constrain(YU, MIN_Y,MAX_Y); | ||
YD = constrain(YD, MIN_Y,MAX_Y); | ||
XL = (XL > MAX_X) ? MAX_X : XL; |
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.
how about using std::min here?
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.
By the way, why is constraint on MIN_Y being dropped?
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.
GCC is pedantic here. MIN_X/Y =0, and constrain is a macro that compares a to b So you end up with "(uint16_t)XR < 0" as one of the conditions it checks, and that's by definition always false. I will put std::min in on next push.
libraries/SD/src/utility/SdFile.cpp
Outdated
@@ -905,7 +906,7 @@ uint8_t SdFile::rmRfStar(void) { | |||
if (!f.remove()) return false; | |||
} | |||
// position to next entry if required | |||
if (curPosition_ != (32*(index + 1))) { | |||
if (curPosition_ != (uint32_t)(32*(index + 1))) { |
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.
index is uint16_t, and the value is being expanded.
I think this is ok, after reading up on usual arithmetic conversions, but I'm not positive. Please double check that the cast is ok on the final arithmetic result, and that it shouldn't be done directly on index before the arithmetic operations.
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.
Didn't mean to expand it, thought curPosition_ was 32-bits. Will correct to uint16_t.
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.
Misread your comment, will move the cast inside. No 16 bits.
@@ -40,7 +40,7 @@ function build_sketches() | |||
local build_arg=$3 | |||
local build_dir=build.tmp | |||
mkdir -p $build_dir | |||
local build_cmd="python tools/build.py -b generic -v -k -p $PWD/$build_dir $build_arg " | |||
local build_cmd="python tools/build.py -b generic -v -w all -k -p $PWD/$build_dir $build_arg " |
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.
If all warnings are now eliminated, isn't it ok to build with -werror? I'd like to enforce no warnings, sooner rather than later.
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.
It's already done below where platform.local.txt is modified.
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.
Also, that parameter is not passed to GCC but to build.yp,which passes it to arduino-builder, which then uses it to lookup into a GCC setting array. Can't send in -werror (it's included now in platform.local.txt that's generated before running the builder.
I'm approving despite my comments, which are minor. My one pet peeve is that I'd like to enforce no warning builds asap (i.e.: -werror), so as to not accumulate again in the future. |
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.
LGTM, just one question in TFT library.
@@ -242,8 +245,8 @@ void LLMNRResponder::_process_packet() { | |||
|
|||
// Header | |||
uint8_t header[] = { | |||
id >> 8, id & 0xff, // ID | |||
FLAGS_QR >> 8, 0, // FLAGS | |||
(uint8_t)(id >> 8), (uint8_t)(id & 0xff), // ID |
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.
since there's a cast to uint8_t now, masking the low byte with & 0xff
is not needed.
XR = constrain(XR, MIN_X,MAX_X); | ||
YU = constrain(YU, MIN_Y,MAX_Y); | ||
YD = constrain(YD, MIN_Y,MAX_Y); | ||
XL = (XL > MAX_X) ? MAX_X : XL; |
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.
By the way, why is constraint on MIN_Y being dropped?
@@ -40,7 +40,7 @@ function build_sketches() | |||
local build_arg=$3 | |||
local build_dir=build.tmp | |||
mkdir -p $build_dir | |||
local build_cmd="python tools/build.py -b generic -v -k -p $PWD/$build_dir $build_arg " | |||
local build_cmd="python tools/build.py -b generic -v -w all -k -p $PWD/$build_dir $build_arg " |
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.
It's already done below where platform.local.txt is modified.
@@ -97,6 +103,9 @@ function install_ide() | |||
mkdir esp8266com | |||
cd esp8266com | |||
ln -s $core_path esp8266 | |||
# Set custom warnings for all builds (i.e. could add -Wextra at some point) |
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.
The last part of the comment seems to be outdated as -Werror
is already present.
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.
Actually, "-Werror" is included, but the comment says "-Wextra" :) So this is really OK.
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.
I'll stop reviewing PRs until I wake up. Sorry.
-edit- This is now completed and there are no errors or warnings reported when run with -Wall -Werror as part of the build process. Ready for review
Use platform.local.txt to add -Werror to GCC for the build of all
code. Any warnings on a submitted patch will cause an error.