clang-10: Fix -Wimplicit-int-float-conversion warnings
Categories
(Developer Infrastructure :: Source Code Analysis, defect, P2)
Tracking
(firefox70 fixed)
Tracking | Status | |
---|---|---|
firefox70 | --- | fixed |
People
(Reporter: Sylvestre, Assigned: Sylvestre)
References
(Blocks 1 open bug)
Details
Attachments
(13 files)
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review |
A Clang warning has been improved in https://reviews.llvm.org/D64666 and we have a bunch of occurrences in the code base
/var/lib/jenkins/workspace/firefox-clang-lld-last/obj-x86_64-pc-linux-gnu/dist/include/mozilla/FastBernoulliTrial.h:368:21: error: implicit conversion from 'unsigned long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
if (skipCount < SIZE_MAX)
~ ^~~~~~~~
/usr/include/stdint.h:261:22: note: expanded from macro 'SIZE_MAX'
# define SIZE_MAX (18446744073709551615UL)
^~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Assignee | ||
Comment 2•5 years ago
|
||
I am fixing more than this just one :)
Assignee | ||
Comment 3•5 years ago
|
||
Assignee | ||
Comment 4•5 years ago
|
||
Depends on D43776
Assignee | ||
Comment 5•5 years ago
|
||
Depends on D43778
Assignee | ||
Comment 6•5 years ago
|
||
Depends on D43779
Assignee | ||
Comment 7•5 years ago
|
||
Depends on D43780
Assignee | ||
Comment 8•5 years ago
|
||
Depends on D43781
Assignee | ||
Comment 9•5 years ago
|
||
Depends on D43782
Assignee | ||
Comment 10•5 years ago
|
||
Depends on D43783
Assignee | ||
Comment 11•5 years ago
|
||
Depends on D43784
Assignee | ||
Comment 12•5 years ago
|
||
Depends on D43785
Comment 13•5 years ago
•
|
||
Coincidentally I discovered this warning when I happened to need to rebuild my tip clang yesterday. I took care of one of the MFBT warning in bug 1577051 and one of the JS warnings in bug 1577065. We're hashing out a proper fix for the other JS warning in bug 1577066.
While merely making the conversions explicit is enough to silence the warning, it's not always the best, most ideal fix IMO. Inexact int-to-float conversions have only implementation-defined behavior, which is a bit more obfuscatory than writing code that doesn't depend on such. And in likely an awful lot of these cases, what is being tested is overflow conditions (because FOO_MAX
is what's being cast). It often is going to be better to convert flt <= FOO_MAX
to flt < float(FOO_MAX + 1 carefully calculated to not immediately overflow)
, which is what the JS changes ended up doing. Reviewers probably should consider similar sorts of changes to just spraying explicit conversions everywhere.
Comment 14•5 years ago
|
||
Comment 15•5 years ago
|
||
Comment 16•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/776b650e4d08
https://hg.mozilla.org/mozilla-central/rev/9dcc8e550559
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Comment 17•5 years ago
|
||
Updated•5 years ago
|
Comment 18•5 years ago
|
||
Comment 19•5 years ago
|
||
bugherder |
Comment 20•5 years ago
|
||
Comment 21•5 years ago
|
||
bugherder |
Comment 22•5 years ago
|
||
Comment 23•5 years ago
|
||
Comment 24•5 years ago
|
||
bugherder |
Comment 25•5 years ago
|
||
Comment 26•5 years ago
|
||
bugherder |
Comment 27•5 years ago
|
||
bugherder uplift |
https://hg.mozilla.org/releases/mozilla-beta/rev/d4b4d46545b3
https://hg.mozilla.org/releases/mozilla-beta/rev/80d4cec02dc9
https://hg.mozilla.org/releases/mozilla-beta/rev/fcc8383a1c4f
https://hg.mozilla.org/releases/mozilla-beta/rev/6eb3bfbbad08
https://hg.mozilla.org/releases/mozilla-beta/rev/127fb176c023
https://hg.mozilla.org/releases/mozilla-beta/rev/da9a6db4b59b
Comment 28•5 years ago
|
||
Comment 29•5 years ago
|
||
Comment 30•5 years ago
|
||
Comment 31•5 years ago
|
||
bugherder |
Comment 32•5 years ago
|
||
Looks like a change landed shortly after your gfx/ patch that stomped on some of your fixes: https://searchfox.org/mozilla-central/rev/23f836a71cfe961373c8bd0d0219ec60a64b3c8f/gfx/layers/opengl/CompositorOGL.cpp#946
Assignee | ||
Comment 33•5 years ago
|
||
The change has been reverted involuntary by bug 1574745
Assignee | ||
Comment 34•5 years ago
|
||
Thanks, I pushed:
https://phabricator.services.mozilla.com/D47734
Comment 35•5 years ago
|
||
Comment 36•5 years ago
|
||
bugherder |
Comment 37•5 years ago
|
||
bugherder |
Comment 38•5 years ago
|
||
Sylvestre, are you still working on this? Looks like only one patch remains.
Comment 39•5 years ago
•
|
||
Here is another one that only comes up on Windows:
[task 2019-11-20T19:15:08.157Z] z:/task_1574273573/src/mozglue/misc/TimeStamp_windows.cpp(385,16): error: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
[task 2019-11-20T19:15:08.157Z] if (result > INT64_MAX) {
[task 2019-11-20T19:15:08.157Z] ~ ^~~~~~~~~
[task 2019-11-20T19:15:08.157Z] z:\task_1574273573\vs2017_15.8.4\VC\include\stdint.h(55,26): note: expanded from macro 'INT64_MAX'
[task 2019-11-20T19:15:08.157Z] #define INT64_MAX 9223372036854775807i64
[task 2019-11-20T19:15:08.157Z] ^~~~~~~~~~~~~~~~~~~~~~
Edit: I see the same code in TimeStamp_darwin.cpp too.
Comment 40•5 years ago
|
||
Comment 41•5 years ago
|
||
Comment 42•5 years ago
|
||
bugherder |
Assignee | ||
Comment 43•5 years ago
|
||
Published a new version:
https://phabricator.services.mozilla.com/D43786
Updated•5 years ago
|
Updated•5 years ago
|
Comment 44•5 years ago
|
||
Updated•5 years ago
|
Comment 45•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Updated•5 years ago
|
Comment 46•5 years ago
|
||
Comment 47•5 years ago
|
||
Comment 48•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Assignee | ||
Comment 49•5 years ago
|
||
I think we are now good.
Updated•5 years ago
|
Updated•2 years ago
|
Description
•