Skip to content

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

Merged
merged 2 commits into from
Jul 4, 2024
Merged

Conversation

cjjdespres
Copy link
Contributor

  • This store of NULL in address in TR_ResolvedRelocatableJ9JITServerMethod::staticAttributes is unnecessary, as the same store occurs later on in that function if fieldInfoCanBeUsed is false and address is not NULL. It has been removed, which also eliminates a clang error - it is wary of converting a (U_32)0 value to a void * value.

  • The weight check in TR_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 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.

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]>
@cjjdespres cjjdespres requested a review from dsouzai as a code owner July 3, 2024 18:10
@cjjdespres
Copy link
Contributor Author

Attn @mpirvu.

@@ -2570,7 +2570,6 @@ TR_ResolvedRelocatableJ9JITServerMethod::staticAttributes(TR::Compilation * comp

if (!resolveField)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.

Copy link
Contributor

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mpirvu
Copy link
Contributor

mpirvu commented Jul 4, 2024

jenkins test sanity zlinux,xlinuxjit,zlinuxjit,alinux64jit jdk17

@mpirvu mpirvu merged commit d473e74 into eclipse-openj9:master Jul 4, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants