-
Notifications
You must be signed in to change notification settings - Fork 754
Fix various cast errors #19802
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 various cast errors #19802
Conversation
The store of NULL in the address pointer is unnecessary, as a few lines down this store occurs if fieldInfoCanBeUsed is false and the address pointer is not NULL. Removing this store has the effect of eliminating a clang warning; clang is wary of converting the `U_32` value 0 to a `void *` value, which is what was happening on this line. Signed-off-by: Christian Despres <[email protected]>
The check here is supposed to guard against the UB of casting a floating-point value outside the int32_t range to an int32_t. The value 0x7fffffff (decimal 2147483647) is not exactly representable as a 32-bit float; both gcc and clang convert it to the float value 2147483648.0 (one more than the literal). The added explicit `(float)` cast eliminates a clang warning about the issue of inexact representation. The check is also changed to `>=`, as in light of the above the previous code would fail if `weight` were ever exactly the floating-point value 2147483648.0. Signed-off-by: Christian Despres <[email protected]>
Attn @mpirvu. |
@@ -2570,7 +2570,6 @@ TR_ResolvedRelocatableJ9JITServerMethod::staticAttributes(TR::Compilation * comp | |||
|
|||
if (!resolveField) |
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 possible that resolvedField
is false
and fieldInfoCanBeUsed
is true
. Under these circumstances we would have written a NULL into *address
which no longer happens in the new code.
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 fact that we write at *address
without checking whether that address is not NULL is not 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.
If resolvedInfo
is false, it looked like we set fieldInfoCanBeUsed
to false inside the if (!resolveField)
block, so we'd end up execute the if (!fieldInfoCanBeUsed)
block anyway. I could be misreading that.
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.
You are right.
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
jenkins test sanity zlinux,xlinuxjit,zlinuxjit,alinux64jit jdk17 |
This store of
NULL
inaddress
inTR_ResolvedRelocatableJ9JITServerMethod::staticAttributes
is unnecessary, as the same store occurs later on in that function iffieldInfoCanBeUsed
is false andaddress
is notNULL
. It has been removed, which also eliminates a clang error - it is wary of converting a(U_32)0
value to avoid *
value.The
weight
check inTR_MultipleCallTargetInliner::scaleSizeBasedOnBlockFrequency
is supposed to guard against the UB of casting a floating-point value outside the int32_t range to an int32_t. The value0x7fffffff
(decimal 2147483647) is not exactly representable as a 32-bit float; both gcc and clang convert it to the float value 2147483648.0 (one more than the literal). The added explicit(float)
cast eliminates a clang warning about the issue of inexact representation.The check is also changed to
>=
, as in light of the above the previous code would fail ifweight
were ever exactly the floating-point value 2147483648.0.