JDK-8200550 : Xcode 9.3 produce warning -Wexpansion-to-defined
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 8,11
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2018-03-30
  • Updated: 2021-03-23
  • Resolved: 2018-04-10
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 11 JDK 8 Other
11 b10Fixed 8u251Fixed openjdk8u302Fixed
Related Reports
Duplicate :  
Relates :  
Description
src/hotspot/share/gc/g1/g1HeapVerifier.hpp:81:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
#if HEAP_REGION_SET_FORCE_VERIFY
    ^
/Users/hjen/ws/panama.dev/src/hotspot/share/gc/g1/heapRegionSet.hpp:53:38: note: expanded from macro 'HEAP_REGION_SET_FORCE_VERIFY'
#define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
                                     ^
2 warnings generated.
Comments
Fix Request [8u] Part of allowing 8u to compile using xcode12. Applies cleanly. Replaces uses of HEAP_REGION_SET_FORCE_VERIFY with a method call, plus two minor syntax cleanups.
23-03-2021

The proposed patch for nativeCallStack.cpp doesn't work. WINDOWS is the wrong macro to be using; the correct macro is _WINDOWS (note the leading underscore). Visual Studio does something unexpected with the original form that seems to accidentally produce the desired answer.
06-04-2018

With a little test "program" I verified that, at least as of now, Xcode 9.3 still does the expected. The "undefined behaviour" risk remains, though. ---8<---- INPUT --- #if ASSERT #warning ASSERT is on #else #warning ASSERT is off #endif #if SWITCH #define TESTER defined(ASSERT) #endif #if TESTER #warning TESTER evaluates true #else #warning TESTER evaluates false #endif ---->8---- INPUT END / OUTPUT BEGIN --- gcc -UASSERT -USWITCH -c pptest.cpp pptest.cpp:5:4: warning: ASSERT is off [-W#warnings] pptest.cpp:15:4: warning: TESTER evaluates false [-W#warnings] gcc -DASSERT -USWITCH -c pptest.cpp pptest.cpp:3:4: warning: ASSERT is on [-W#warnings] pptest.cpp:15:4: warning: TESTER evaluates false [-W#warnings] gcc -UASSERT -DSWITCH -c pptest.cpp pptest.cpp:5:4: warning: ASSERT is off [-W#warnings] pptest.cpp:12:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined] #if TESTER ^ pptest.cpp:9:18: note: expanded from macro 'TESTER' #define TESTER defined(ASSERT) ^ pptest.cpp:15:4: warning: TESTER evaluates false [-W#warnings] gcc -DASSERT -DSWITCH -c pptest.cpp pptest.cpp:3:4: warning: ASSERT is on [-W#warnings] pptest.cpp:12:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined] #if TESTER ^ pptest.cpp:9:18: note: expanded from macro 'TESTER' #define TESTER defined(ASSERT) ^ pptest.cpp:13:4: warning: TESTER evaluates true [-W#warnings]
06-04-2018

Linking this to the toolchain upgrade task. This problem showed up with Xcode 9.3, and JDK-8194939 says the upgrade target is Xcode 9.2, so not currently blocking the planned upgrade.
05-04-2018

These warnings (and others) were reported by email to jdk-dev 11/30/2017: http://mail.openjdk.java.net/pipermail/jdk-dev/2017-November/000292.html http://mail.openjdk.java.net/pipermail/jdk-dev/2017-December/000296.html where it was recommended the offered patch be split up by component and sent to appropriate component mailing lists. I'm not finding any indication that such happened. I'm somewhat surprised these haven't shown up in the toolchain update effort.
02-04-2018

Following patch is a simple rewrite of the rules to address the warning, diff -r de0fd2c8a401 src/hotspot/share/gc/g1/heapRegionSet.hpp --- a/src/hotspot/share/gc/g1/heapRegionSet.hpp Fri Mar 30 14:36:18 2018 -0700 +++ b/src/hotspot/share/gc/g1/heapRegionSet.hpp Fri Mar 30 22:59:40 2018 -0700 @@ -50,7 +50,11 @@ // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which // asserts are compiled in. #ifndef HEAP_REGION_SET_FORCE_VERIFY -#define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT) + #if defined(ASSERT) + #define HEAP_REGION_SET_FORCE_VERIFY 1 + #else + #define HEAP_REGION_SET_FORCE_VERIFY 0 + #endif #endif // HEAP_REGION_SET_FORCE_VERIFY class HRSMtSafeChecker : public CHeapObj<mtGC> { diff -r de0fd2c8a401 src/hotspot/share/utilities/nativeCallStack.cpp --- a/src/hotspot/share/utilities/nativeCallStack.cpp Fri Mar 30 14:36:18 2018 -0700 +++ b/src/hotspot/share/utilities/nativeCallStack.cpp Fri Mar 30 22:59:40 2018 -0700 @@ -37,7 +37,12 @@ // to call os::get_native_stack. A tail call is used if _NMT_NOINLINE_ is not defined // (which means this is not a slowdebug build), and we are on 64-bit (except Windows). // This is not necessarily a rule, but what has been obvserved to date. -#define TAIL_CALL (!defined(_NMT_NOINLINE_) && !defined(WINDOWS) && defined(_LP64)) +#if (!defined(_NMT_NOINLINE_) && !defined(WINDOWS) && defined(_LP64)) + #define TAIL_CALL 1 +#else + #define TAIL_CALL 0 +#endif + #if !TAIL_CALL toSkip++; #if (defined(_NMT_NOINLINE_) && defined(BSD) && defined(_LP64))
31-03-2018