-
Notifications
You must be signed in to change notification settings - Fork 86
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
Fix compiler warnings #329
Conversation
Codecov Report
@@ Coverage Diff @@
## master #329 +/- ##
==========================================
- Coverage 75.30% 75.21% -0.09%
==========================================
Files 281 282 +1
Lines 19453 19493 +40
==========================================
+ Hits 14649 14662 +13
- Misses 4804 4831 +27
|
For some reason with GCC 5.4 the fix to suppress the OpenCL polyfill unused variables doesn't seem to work. Still spits a bunch of warnings. |
Hm, looks like that might be a compiler bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69967 |
cd32c39
to
19eaa82
Compare
Rebased on new master and changed new function |
@SFrijters Cool thanks, I'll take a look at the code changes tonight! |
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.
Aside from removing some of the primitive methods, most of the changes look really good. Thanks for fixing these compiler warnings!
@@ -248,8 +249,8 @@ namespace occa { | |||
case primitiveType::uint32_ : return primitive(!p.value.uint32_); | |||
case primitiveType::int64_ : return primitive(!p.value.int64_); | |||
case primitiveType::uint64_ : return primitive(!p.value.uint64_); | |||
case primitiveType::float_ : return primitive(!p.value.float_); | |||
case primitiveType::double_ : return primitive(!p.value.double_); | |||
case primitiveType::float_ : OCCA_FORCE_ERROR("Cannot apply operator ! to float type"); break; |
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.
These might be potentially used int he preprocessor, so we can't take them away
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.
Ok, I can do something like return primitive(areBitwiseEqual(p.value.float_, static_cast<float>(0))
?
Is it just this one, or do you want similar changes for &&
and ||
? Since &
and |
are already disallowed in the current implementation I would say no?
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.
Maybe for these operations, we can first cast the float
/double
as int
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.
Ha ha, for float values, what is "zero" anyway?
My preference is the "...cannot apply operator ! to float type". Just leave it up to the user to explore the possibilities when a float type is involved based on his program logic. The user should already know he is in trouble if he's thinking about using logical not with a float value!
Allow me to illustrate.
For this primitive (not
), is a sort of "near-!
" acceptable, which checks for zero within macheps? e.g.,
case primitiveType::float_ : return primitive( ((float)1.0 + p.value.float_) == (float)1.0 )
My view: this is not acceptable for general use cases at this level. But others may disagree.
FYI possibly another approach to !
based on an equality to zero comparison without employing the explicit ==
(i.e., partial-order trick):
case primitiveType::float_ : return primitive( !(p.value.float_ < -p.value.float_ || -p.value.float_ < p.value.float_) )
All the above mutatis mutandis for the double case.
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 argument made here is that we want to support as much C/C++ as possible, regardless of whether it's considered "good practice" or "bad practice". I 100% agree we shouldn't be doing exact comparisons with float
or double
"in practice". However, the goal here is language coverage.
TIL: Looks like floats aren't supported in the preprocessor!
main.cpp:4:6: error: floating constant in preprocessor expression
#if !0.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.
Since the preprocessor won't accept them anyway, can we keep these operators unimplemented for float/double? That would still be my preferred solution.
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.
Sounds good!
src/c/types.cpp
Outdated
@@ -646,7 +651,7 @@ const int OCCA_PROPERTIES = occa::c::typeType::properties; | |||
const occaType occaUndefined = occa::c::undefinedOccaType(); | |||
const occaType occaDefault = occa::c::defaultOccaType(); | |||
const occaType occaNull = occa::c::nullOccaType(); | |||
const occaUDim_t occaAllBytes = -1; | |||
const occaUDim_t occaAllBytes = static_cast<occaUDim_t>(-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.
Is this cast really necessary? I would hope the compiler can figure this out on its own, at least for such primitive types.
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 reports it as an implicit conversion, so yes, it's needed to fix the warning.
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.
OK. I just think this makes the code look ugly and cluttered. IMHO, code should be easy to read and intuitive, this is far from that. I would rather consider to add an exception (i.e. suppress the warning) for Clang than adding something like this to the code. Just my two cents...
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 we define a const value once and reuse it?
const occa::udim_t UDIM_DEFAULT = static_cast<occa::udim_t>(-1);
This would also make the code a bit clearer in places where -1
is set as the default because of how high the number is
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.
@dmed256 that's probably a sensible compromise. I like the simple -1
since it's rather intuitive and easy to understand as is, but having a predefined constant works as well - anything that avoids cluttering the source code with type casts.
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've redone the relevant commit to use the const UDIM_DEFAULT, as suggested.
19eaa82
to
4b03c0b
Compare
The testBadType call corrupts the data in the JSON object to be serialized. After this the roundtripping doesn't work anymore. Fix it by reordering the tests.
Floating point equality checks are complained about by many compilers. Changes to make them happy: * For C tests: change comparison to check for equality up to a small epsilon. Since we know we fill the arrays with integer numbers, this should suffice. * For C++ tests: check for bitwise equality of the floating point numbers. * For the general code: disallow various operations for floating point numbers that are wrapped in primitives. * For indexOf: add specialization for floating point that checks for bitwise equality. * Bitwise equality check for floating point numbers is tentatively placed in a new fp.hpp header.
4b03c0b
to
e144223
Compare
Thank you to everyone that made this possible! |
Description
Attempts to fix #327 .
I've tried to restructure my changes into separate commits to address separate issues for easier reviewing My commit c57a0bd in particular is rather opinionated, so that one probably warrants extra attention.
In general I'm trying to make the compilers as happy as possible by making actual changes, but some warnings have been suppressed explicitly.
This has been tested with Intel 2019, GCC 8.3 and Clang 9.