RFR: 8345580: Remove const from Node::_idx which is modified [v2]

Yagmur Eren duke at openjdk.org
Wed Dec 18 14:36:11 UTC 2024


> `Node::_idx` is declared as `const`, however, it is modified by `Node::set_idx`. Please see: https://github.com/openjdk/jdk/blob/166c12771d9d8c466e73a9490c4eb1fc9a5f6c24/src/hotspot/share/opto/node.hpp#L588
> 
> As already stated in [JDK-8345580](https://bugs.openjdk.org/browse/JDK-8345580) issue, this behavior is counterintuitive because a const variable is expected to remain unmodified throughout its lifetime. Additionally, C++ International Standard states that "_...any attempt to modify a `const` object during its lifetime results in undefined behavior._ ". 
> To address this, `const` should be removed from the declaration of `Node::_idx` to align with its intended use and avoid violating the C++ standard. Tested with tier1,2,3,4,5.

Yagmur Eren has updated the pull request incrementally with one additional commit since the last revision:

  remove casting trick in set_idx

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/22646/files
  - new: https://git.openjdk.org/jdk/pull/22646/files/a81f75bb..2322aa9c

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

  Stats: 2 lines in 1 file changed: 0 ins; 1 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/22646.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22646/head:pull/22646

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


More information about the hotspot-compiler-dev mailing list