JDK-8152856 : Xcode 7.3 -Wshift-negative-value compile failure on Mac OS X
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2016-03-28
  • Updated: 2020-08-14
  • Resolved: 2016-05-24
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.
JDK 8 JDK 9 Other
8u251Fixed 9 b122Fixed openjdk8u232Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
After modifying gcc.make, on Mac OSX 10.11.4 with Xcode 7.3, the build fails with this error:

Generating precompiled header precompiled.hpp.pch
In file included from <built-in>:332:
In file included from <command line>:22:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/precompiled/precompiled.hpp:30:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/asm/assembler.inline.hpp:31:
In file included from /Users/morris/hotspot/hs9/hotspot/src/cpu/x86/vm/assembler_x86.inline.hpp:30:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/code/codeCache.hpp:28:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/code/codeBlob.hpp:30:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/runtime/frame.hpp:28:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/method.hpp:33:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/constantPool.hpp:32:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/typeArrayOop.hpp:29:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/typeArrayKlass.hpp:29:
In file included from /Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/arrayKlass.hpp:29:
/Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/klass.hpp:327:58: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
    return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
                                ~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/morris/hotspot/hs9/hotspot/src/share/vm/oops/klass.hpp:331:55: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
    return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
                             ~~~~~~~~~~~~~~~~~~~~~~~~ ^
2 errors generated.
Comments
The JDK OpenJDK 8u backport seems to break builds due to new warnings on certain XCode versions (e.g. 4.6.3). See: https://github.com/AdoptOpenJDK/openjdk-build/issues/1202
12-08-2019

Fix Request 8u. Satisfies compiler warning, very low risk. Patch applies cleanly net of line numbers and file locations.
18-07-2019

The fix seems fine though I would have argued for making all of those into consts instead of having a mix of enums and const for those constants. Anyway, thanks for pushing a real fix for this.
31-05-2016

Re Tom Rodriquez: my proposed fix (at http://cr.openjdk.java.net/~gziemski/8152856_rev3/ ) seems much less intrusive and follows the current hotspot style guide - i.e. using const instead of enums.
24-05-2016

I reported the "-Wlogical-not-parentheses" issue from JRSUIConstantSync.m here: JDK-8157476
20-05-2016

Instead of manually casting the uses, it might be nicer to introduce _lh_array_tag_type_value_in_place which performs the proper casts and change the uses to use that value. This mirrors other mask enums like in markOopDesc that provide foo and foo_in_place which have already performed the proper shifts.
13-05-2016

The workaround is to configure the build by passing "--disable-warnings-as-errors", ex: ./configure --with-jobs=8 --disable-warnings-as-errors --with-jvm-variants=server or if you build not using makefiles, you can pass "-Wno-shift-negative-value" to your compiler directly.
10-05-2016

I have 7.3.1 and 6.2. Is there a workaround until this is fixed?
09-05-2016

There's also some changes need in one of the make files: Building configuration 'macosx-x86_64-normal-server-release' (matching CONF=release) Building target 'images' in configuration 'macosx-x86_64-normal-server-release' /Users/dsimon/hs-comp/hotspot/make/bsd/makefiles/gcc.make:341: *** "Update compiler workarounds for Clang 7.3". Stop.
04-04-2016

There are only 4 following issues with the hotspot/runtime, there are others, but they belong in other components: /Volumes/Work/bugs/0000000/jdk9/hotspot/src/share/vm/oops/klass.hpp:327:58: warning: shifting a negative signed value is undefined [-Wshift-negative-value] return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift); ~~~~~~~~~~~~~~~~~~~~~~~~ ^ /Volumes/Work/bugs/0000000/jdk9/hotspot/src/share/vm/oops/klass.hpp:331:55: warning: shifting a negative signed value is undefined [-Wshift-negative-value] return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift); ~~~~~~~~~~~~~~~~~~~~~~~~ ^ /Volumes/Work/bugs/0000000/jdk9/hotspot/src/share/vm/opto/library_call.cpp:3766:20: warning: shifting a negative signed value is undefined [-Wshift-negative-value] << Klass::_lh_array_tag_shift) ^ /Volumes/Work/bugs/0000000/jdk9/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp:2723:56: warning: shifting a negative signed value is undefined [-Wshift-negative-value] __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
28-03-2016

There are other places in hotspot & jdk where new warnings are fired w/ Xcode 7.3: /Users/vlivanov/ws/jdk/hs-comp9/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp:2723:56: warning: shifting a negative signed value is undefined [-Wshift-negative-value] __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ /Users/vlivanov/ws/jdk/hs-comp9/jdk/src/java.desktop/share/native/libjavajpeg/jdhuff.c:458:13: warning: shifting a negative signed value is undefined [-Wshift-negative-value] { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ~~~~^ /Users/vlivanov/ws/jdk/hs-comp9/jdk/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m:132:5: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses] CONSISTENCY_CHECK(Key, value); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/vlivanov/ws/jdk/hs-comp9/jdk/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m:96:10: note: expanded from macro 'CONSISTENCY_CHECK' if ( !CONSTANT_CHECK(clazz, constant) ) return NO; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ / /Users/vlivanov/ws/jdk/hs-comp9/hotspot/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m:691:21: warning: 'ePtAttachDeprecated' is deprecated: PT_ATTACH is deprecated. See PT_ATTACHEXC [-Wdeprecated-declarations] if ((res = ptrace(PT_ATTACH, pid, 0, 0)) < 0) { ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/sys/ptrace.h:85:19: note: expanded from macro 'PT_ATTACH' #define PT_ATTACH ePtAttachDeprecated /* trace some running process */ ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/sys/ptrace.h:71:2: note: 'ePtAttachDeprecated' has been explicitly marked deprecated here ePtAttachDeprecated __deprecated_enum_msg("PT_ATTACH is deprecated. See PT_ATTACHEXC") = 10 ^ /Users/vlivanov/ws/jdk/hs-comp9/hotspot/src/share/vm/opto/library_call.cpp:3762:20: warning: shifting a negative signed value is undefined [-Wshift-negative-value] << Klass::_lh_array_tag_shift) ^
28-03-2016