This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix ASSUME definition
authorKarl Williamson <khw@cpan.org>
Sun, 30 May 2021 17:55:33 +0000 (11:55 -0600)
committerKarl Williamson <khw@cpan.org>
Tue, 15 Jun 2021 13:40:01 +0000 (07:40 -0600)
Commit 5d5b9c460e2a06563d2b5e35a1a79991460696eb fixed the definition of
ASSUME for some purposes, but broke it on Windows.  This commit should
fix that.

perl.h

diff --git a/perl.h b/perl.h
index a4be596..513de1f 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -3876,42 +3876,41 @@ intrinsic function, see its documents for more details.
 =cut
 */
 
-#ifdef DEBUGGING
-#  define ASSUME(x) assert(x)
-#  if __has_builtin(__builtin_unreachable)
+#if __has_builtin(__builtin_unreachable)
 #    define HAS_BUILTIN_UNREACHABLE
-#  elif (defined(__GNUC__) && (   __GNUC__ > 4                              \
-                               || __GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+#elif (defined(__GNUC__) && (   __GNUC__ > 4                              \
+                             || __GNUC__ == 4 && __GNUC_MINOR__ >= 5))
 #    define HAS_BUILTIN_UNREACHABLE
-#  endif
 #endif
 
-#if defined(__sun) || (defined(__hpux) && !defined(__GNUC__))
-#  ifndef ASSUME
-#    define ASSUME(x)      /* ASSUME() generates warnings on Solaris */
-#  endif
-#  define NOT_REACHED
+#ifdef DEBUGGING
+#  define ASSUME(x) assert(x)
+#elif defined(_MSC_VER)
+#  define ASSUME(x) __assume(x)
+#elif defined(__ARMCC_VERSION) /* untested */
+#  define ASSUME(x) __promise(x)
 #elif defined(HAS_BUILTIN_UNREACHABLE)
-#  ifndef ASSUME
+    /* Compilers can take the hint from something being unreachable */
 #    define ASSUME(x) ((x) ? (void) 0 : __builtin_unreachable())
-#  endif
+#else
+    /* Not DEBUGGING, so assert() is a no-op, but a random compiler might
+     * define assert() to its own special optimization token so pass it through
+     * to C lib as a last resort */
+#  define ASSUME(x) assert(x)
+#endif
+
+#ifdef HAS_BUILTIN_UNREACHABLE
 #  define NOT_REACHED                                                       \
         STMT_START {                                                        \
             ASSUME(!"UNREACHABLE"); __builtin_unreachable();                \
         } STMT_END
+#  undef HAS_BUILTIN_UNREACHABLE /* Don't leak out this internal symbol */
+#elif ! defined(__GNUC__) && (defined(__sun) || defined(__hpux))
+    /* These just complain that NOT_REACHED isn't reached */
+#  define NOT_REACHED
 #else
-#  if defined(_MSC_VER)
-#    define ASSUME(x) __assume(x)
-#  elif defined(__ARMCC_VERSION) /* untested */
-#    define ASSUME(x) __promise(x)
-#  else
-    /* a random compiler might define assert to its own special optimization
-     * token so pass it through to C lib as a last resort */
-#    define ASSUME(x) assert(x)
-#  endif
-#  define NOT_REACHED ASSUME(!"UNREACHABLE")
+#  define NOT_REACHED  ASSUME(!"UNREACHABLE")
 #endif
-#undef HAS_BUILTIN_UNREACHABLE
 
 /* Some unistd.h's give a prototype for pause() even though
    HAS_PAUSE ends up undefined.  This causes the #define