RFR: 8346193: Test runtime/ErrorHandling/TestDwarf.java fails build with clang17 [v3]

SendaoYan syan at openjdk.org
Tue Dec 31 10:22:24 UTC 2024


> Hi all,
> Function `frame::oops_do_internal` in src/hotspot/share/runtime/frame.cpp assign value to a nullptr `char *t` and intended to cause jvm crash. But after the assignment the nullptr do not use anymore, so clang17 consider the `char *t` initialization and assignment is "dead code". This PR add `volatile` modifier to `char *t`, to make avoid clang do the "dead code" elimination. Risk is low.
> 
> Here is the example explain the "dead code" elimination.
> 
> 1. Without volatile modifier, clang will delete the "dead code" and cause no more Segmentation fault error by -O1.
> 
> 
>> cat demo.c 
> int main() { char *t = 0; *t = 'c'; return 0; }
>> clang -O0 demo.c && ./a.out ; echo $?
> Segmentation fault (core dumped)
> 139
>> clang -O1 demo.c && ./a.out ; echo $?
> 0
> 
> 
> 2. With volatile modifier, clang do not delete the "dead code" again and and the expected Segmentation fault occur by -O1.
> 
>> cat demo.c 
> int main() { volatile char *t = 0; *t = 'c'; return 0; }
>> clang -O0 demo.c && ./a.out ; echo $?
> Segmentation fault (core dumped)
> 139
>> clang -O1 demo.c && ./a.out ; echo $?
> Segmentation fault (core dumped)
> 139

SendaoYan has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'openjdk:master' into jbs8346193
 - update comment "Use volatile to prevent compiler from optimising away the store"
 - 8346193: Test runtime/ErrorHandling/TestDwarf.java fails build with clang17

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/22757/files
  - new: https://git.openjdk.org/jdk/pull/22757/files/caa26be4..1f5c1955

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=22757&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=22757&range=01-02

  Stats: 17346 lines in 466 files changed: 13217 ins; 2375 del; 1754 mod
  Patch: https://git.openjdk.org/jdk/pull/22757.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22757/head:pull/22757

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


More information about the hotspot-dev mailing list