-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 14
-
b23
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8247301 | 13.0.4 | Kim Barrett | P4 | Resolved | Fixed | b05 |
JDK-8243386 | 11.0.8-oracle | Kim Barrett | P4 | Resolved | Fixed | b04 |
JDK-8245270 | 11.0.8 | Kim Barrett | P4 | Resolved | Fixed | b04 |
JDK-8340314 | openjdk8u442 | Martin Balao Alonso | P4 | Resolved | Fixed | b01 |
JDK-8342411 | openjdk8u432 | Martin Balao Alonso | P4 | Resolved | Fixed | b06 |
JDK-8332425 | 8u431 | Fairoz Matte | P4 | Resolved | Fixed | b01 |
JDK-8332443 | 7u441 | Fairoz Matte | P4 | Resolved | Fixed | b01 |
The code is
jint mask = ~(~0 << (32 - shift));
if (shift == 0) mask = ~0;
The first problem is that the left shift of ~0 is a left shift of a negative number. C89 and C++98 don't explicitly specify the behavior, though one might infer there could be difficulties due to the different representations that are permitted. C99 and C++11 both explicitly specify this to be undefined. gcc warns about that shift when using -Wshift-negative-value (enabled by -Wextra) when compiling for C99 or C++11. This isn't a problem now, but will be for JEP 347.
The second problem exists today. If shift == 0, which is possible and is checked for by the second line, the shift quantity is 32, which is undefined behavior in any version of C/C++ when the left hand side has a size of 32 bits (or less). This means that a sufficiently aggressive compiler might elide the second line entirely, since the test can't be true without having already invoked undefined behavior.
There is a third problem a couple lines later with this line:
case Bytecodes::_ishl: set_constant(value << shift); return;
If value is negative, this is again a shift of a negative value. The C++ compiler probably isn't going to detect or be affected by this, but a runtime sanitizer could complain.
There is a second occurrence of essentially the same code with the same problems a few lines later for the jlong case.
- backported by
-
JDK-8243386 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8245270 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8247301 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8332425 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8332443 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8340314 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
-
JDK-8342411 Fix undefined behavior in Canonicalizer::do_ShiftOp
- Resolved
- relates to
-
JDK-8233144 undefined behavior: signed integer overflow
- Open
-
JDK-8211073 Remove -Wno-extra from Hotspot
- Resolved
-
JDK-8208089 JEP 347: Enable C++14 Language Features
- Closed
- links to
-
Commit(master) openjdk/jdk8u-dev/73056eb8
-
Review(master) openjdk/jdk8u-dev/577