RFR: 8350197: [UBSAN] Node::dump_idx reported float-cast-overflow
SendaoYan
syan at openjdk.org
Mon Feb 17 13:10:00 UTC 2025
Hi all,
The function of 'Node::dump_idx(bool, outputStream*, Node::DumpConfig*)' in file src/hotspot/share/opto/node.cpp:2430 reported "runtime error: -inf is outside the range of representable values of type 'unsigned int'" by clang17's UndefinedBehaviorSanitizer.
This PR add an extra check for the argument before pass call to `log10`. Risk is low.
Additional testing:
- [ ] Jtreg tests(include tier1/2/3 etc.) on linux-x64 with release build
- [ ] Jtreg tests(include tier1/2/3 etc.) on linux-aarch64 with release build
Below code snippet demonstrate the undefined behaviour of float-cast-overflow:
#include <stdio.h>
#include <math.h>
int input = 0;
int main()
{
printf("result = %lf\n", log10((double)input));
printf("result = %u\n", (unsigned int)log10((double)input));
printf("result = %u\n", input==0 ? 0 : (unsigned int)log10((double)input));
return 0;
}
> clang -fsanitize=undefined log10.c -lm && ./a.out
result = -inf
log10.c:9:27: runtime error: -inf is outside the range of representable values of type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior log10.c:9:27 in
result = 0
result = 0
-------------
Commit messages:
- add necessary braces
- 8350197: [UBSAN] Node::dump_idx reported float-cast-overflow
Changes: https://git.openjdk.org/jdk/pull/23662/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23662&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8350197
Stats: 4 lines in 2 files changed: 0 ins; 0 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/23662.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/23662/head:pull/23662
PR: https://git.openjdk.org/jdk/pull/23662
More information about the hotspot-compiler-dev
mailing list