On Mon, 25 Nov 2024 07:08:56 GMT, David Holmes <dhol...@openjdk.org> wrote:
>> Hi all, >> File `src/java.base/share/native/libjli/java.c` compile `error: control >> reaches end of non-void function [-Werror=return-type]` with gcc options >> `-fsanitize=address -O0`. The function `int JavaMain(void* _args)` in this >> file will execute `return ret` in `LEAVE()` macro, but gcc with -O0 is not >> smart enough to recognized that the function already has `return` statement >> before at the end of function. >> This PR add final return statement make gcc with options `-fsanitize=address >> -O0` happy, to make jdk compile success with configure option >> `--enable-asan` by slowdebug mode. The added `return ret` make no sence >> because the `LEAVE()` macro make sure that function will execute `returun >> ret` statement at java.c:348. So I think this change is no risk. >> >> Additional testing: >> >> - [x] jtreg tests(include tier1/2/3 etc.) with linux-x64 release build >> - [x] jtreg tests(include tier1/2/3 etc.) with linux-x64 fastdebug build >> - [x] jtreg tests(include tier1/2/3 etc.) with linux-aarch64 release build >> - [x] jtreg tests(include tier1/2/3 etc.) with linux-aarch64 fastdebug >> build > > src/java.base/share/native/libjli/java.c line 663: > >> 661: } >> 662: LEAVE(); >> 663: return ret; > > A `do-while` loop is always executed at least once, that is why the `LEAVE > macro is structured as it is: > > do { \ > if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \ > JLI_ReportErrorMessage(JVM_ERROR2); \ > ret = 1; \ > } \ > if (JNI_TRUE) { \ > (*vm)->DestroyJavaVM(vm); \ > return ret; \ > } \ > } while (JNI_FALSE) > > So this will always return and the sanitizer seems incorrect. Yes, I was make a mistake prior, the do-while(false) loop will execute once. But I think this PR still a bit usefull and no risk, the analyze seen as [below](https://github.com/openjdk/jdk/pull/22355#issuecomment-2497997812). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/22355#discussion_r1857554793