- 
    Bug 
- 
    Resolution: Fixed
- 
     P3 P3
- 
    8, 11, 17, 19, 20, 21
- 
        b29
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build | 
|---|---|---|---|---|---|---|
| JDK-8298805 | 21 | Andrew Haley | P3 | Resolved | Fixed | b03 | 
| JDK-8299028 | 17.0.7-oracle | Tobias Hartmann | P3 | Resolved | Fixed | b01 | 
| JDK-8303190 | 17.0.7 | Goetz Lindenmaier | P3 | Resolved | Fixed | b04 | 
```
/home/shade/trunks/jdk/src/hotspot/share/opto/postaloc.cpp: In member function 'int PhaseChaitin::elide_copy(Node*, int, Block*, Node_List&, Node_List&, bool)':
/home/shade/trunks/jdk/src/hotspot/share/opto/postaloc.cpp:260:14: error: the compiler can assume that the address of 'value' will never be NULL [-Werror=address]
260 | if( &value == NULL ) return blk_adjust;
| ^
```
This thing is not theoretical, I played with the following snippet in Godbolt:
```
#include <cstddef>
class X {};
bool test(X& ref) {
return (&ref == NULL);
}
int main() {
return test(*((X*)NULL));
}
```
With -O2, GCC 5.5 and lower compiles `test` to actual check, like you would expect for pointers:
```
test rdi,rdi
sete al
ret
```
With -O2, GCC 6.1 and higher compiles `test` to "return false", as warning told it might happen:
```
xor eax,eax
ret
```
Plus, adding these asserts to Hotspot:
```
diff --git a/src/hotspot/share/opto/postaloc.cpp b/src/hotspot/share/opto/postaloc.cpp
index 96c30a122bb..23b78305af2 100644
--- a/src/hotspot/share/opto/postaloc.cpp
+++ b/src/hotspot/share/opto/postaloc.cpp
@@ -536,4 +536,6 @@ void PhaseChaitin::post_allocate_copy_removal() {
// Remove copies along phi edges
for (uint k = 1; k < phi_dex; k++) {
+ assert(blk2value[pb->_pre_order] != nullptr, "UB");
+ assert(blk2regnd[pb->_pre_order] != nullptr, "UB");
elide_copy(block->get_node(k), j, block, *blk2value[pb->_pre_order], *blk2regnd[pb->_pre_order], false);
}
```
Fails immediately during the build, so we do experience nulls here.
- backported by
- 
                    JDK-8298805 Undefined Behavior in C2 regalloc with null references -           
- Resolved
 
-         
- 
                    JDK-8299028 Undefined Behavior in C2 regalloc with null references -           
- Resolved
 
-         
- 
                    JDK-8303190 Undefined Behavior in C2 regalloc with null references -           
- Resolved
 
-         
- relates to
- 
                    JDK-8300080 offset_of for GCC/Clang exhibits undefined behavior and is not always a compile-time constant -           
- Resolved
 
-         
- links to
- 
                     Commit
        openjdk/jdk17u-dev/a0cda28d Commit
        openjdk/jdk17u-dev/a0cda28d
- 
                     Commit
        openjdk/jdk20/0bbc4181 Commit
        openjdk/jdk20/0bbc4181
- 
                     Review
        openjdk/jdk17u-dev/1106 Review
        openjdk/jdk17u-dev/1106
- 
                     Review
        openjdk/jdk20/26 Review
        openjdk/jdk20/26
- 
                     Review
        openjdk/jdk/10920 Review
        openjdk/jdk/10920