Integrated: 8350197: [UBSAN] Node::dump_idx reported float-cast-overflow

SendaoYan syan at openjdk.org
Wed Feb 19 01:32:56 UTC 2025


On Mon, 17 Feb 2025 13:04:34 GMT, SendaoYan <syan at openjdk.org> wrote:

> 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:
> 
> - [x] Jtreg tests(include tier1/2/3 etc.) on linux-x64 with release build
> - [x] Jtreg tests(include tier1/2/3 etc.) on linux-aarch64 with release build
> - [x] Jtreg tests(include tier1/2/3 etc.) on linux-x64 with fastdebug build
> - [x] Jtreg tests(include tier1/2/3 etc.) on linux-aarch64 with fastdebug 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

This pull request has now been integrated.

Changeset: 04659a40
Author:    SendaoYan <syan at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/04659a40736610164855ac161120e63fcd46fe31
Stats:     4 lines in 2 files changed: 0 ins; 0 del; 4 mod

8350197: [UBSAN] Node::dump_idx reported float-cast-overflow

Reviewed-by: chagedorn

-------------

PR: https://git.openjdk.org/jdk/pull/23662


More information about the hotspot-compiler-dev mailing list