JDK-8300825 : UB: Signed integer overflow: 9223372036854775807 + 3 cannot be represented in type 'long'
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2023-01-22
  • Updated: 2023-04-20
  • Resolved: 2023-04-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
Undefined Behavior discovered after turning "UndefinedBehaviorSanitizer" in Xcode running simple HelloWorld java app. More info on clang undefined behavior sanitizer can be found https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html 

/Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:1894 Signed integer overflow: 9223372036854775807 + 3 cannot be represented in type 'long'
/Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:1894 Signed integer overflow: 9223372036854775807 + 4 cannot be represented in type 'long'
/Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:1894 Signed integer overflow: 9223372036854775807 + 9223372036854775807 cannot be represented in type 'long'

Signed integer overflow
#0	0x0000000111d8bb83 in TypeLong::hash() const at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:1894
#1	0x0000000110f2f13f in Dict::operator[](void const*) const at /Users/gerard/Work/tmp/jdk/src/hotspot/share/libadt/dict.cpp:205
#2	0x0000000111d81027 in Type::hashcons() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:753
#3	0x0000000111d83fd7 in TypeLong::make(long, long, int) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:1728
#4	0x0000000111d81bb7 in Type::Initialize_shared(Compile*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:499
#5	0x0000000111d8514b in Type::Initialize(Compile*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/type.cpp:715
#6	0x0000000111c200fb in CompileWrapper::CompileWrapper(Compile*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.cpp:486
#7	0x0000000111c2076c in CompileWrapper::CompileWrapper(Compile*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.cpp:470
#8	0x0000000111c2641b in Compile::Compile(ciEnv*, TypeFunc const* (*)(), unsigned char*, char const*, int, bool, bool, DirectiveSet*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.cpp:939
#9	0x0000000111ceb407 in OptoRuntime::generate_stub(ciEnv*, TypeFunc const* (*)(), unsigned char*, char const*, int, bool, bool) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/runtime.cpp:175
#10	0x0000000111ceb093 in OptoRuntime::generate(ciEnv*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/runtime.cpp:143
#11	0x0000000111cad217 in C2Compiler::init_c2_runtime() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/c2compiler.cpp:82
#12	0x0000000111cad2cf in C2Compiler::initialize() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/c2compiler.cpp:95
#13	0x0000000111e8437b in CompileBroker::init_compiler_runtime() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/compiler/compileBroker.cpp:1730
#14	0x0000000111e8504f in CompileBroker::compiler_thread_loop() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/compiler/compileBroker.cpp:1867
#15	0x0000000110eed6cb in JavaThread::thread_main_inner() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/javaThread.cpp:710
#16	0x0000000110eed4bb in JavaThread::run() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/javaThread.cpp:695
#17	0x0000000110d9837b in Thread::call_run() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/thread.cpp:224
#18	0x00000001109abd1f in thread_native_entry(Thread*) at /Users/gerard/Work/tmp/jdk/src/hotspot/os/bsd/os_bsd.cpp:572
#19	0x00000001000995d3 in _pthread_start ()
Comments
Thanks for the details, Kim. Let's close this one as duplicate of JDK-8306544 which has more information in it and re-prioritize.
20-04-2023

Not surprisingly, I ran into this same issue trying out gcc's -fsanitize=signed-integer-overflow (JDK-8306544). Many of the Type::hash implementations contain potential overflows. Some avoid undefined overflows by using java_add instead of ordinary "operator+" or "operator+=". (Though this is arguably an abuse of that function. The description of that suite of functions suggests their purpose is to emulate Java operations, not for "general-purpose arithmetic".) The rest are probably "harmless" in that it seems unlikely the compiler will do anything screwy based on potential overflow. However, this blocks using this sanitizer more broadly to try to look for non-harmless cases, such as JDK-8306331. So making this P5 might not be appropriate.
20-04-2023

Initial ILW = Integer overflow in C2's node hash code (harmless), found with UndefinedBehaviorSanitizer in Xcode - never observed any issues, no known workaround = LLH = P5
23-01-2023