Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
67de53a6 by Cheng Shao at 2025-09-23T14:37:31-04:00
rts: remove obsolete __GNUC__ related logic
This patch removes obsolete `__GNUC__` related logic, given on any
currently supported platform and toolchain, `__GNUC__ >= 4` is
universally true. Also pulls some other weeds and most notably, use
`__builtin___clear_cache` for clang as well, since clang has supported
this gcc intrinsic since 2014, see
https://github.com/llvm/llvm-project/commit/c491a8d4577052bc6b3b4c72a7db6a7c....
- - - - -
10 changed files:
- libraries/ghc-internal/cbits/atomic.c
- libraries/ghc-internal/cbits/ctz.c
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/include/Rts.h
- rts/include/Stg.h
- rts/include/rts/Types.h
- rts/sm/BlockAlloc.c
- rts/sm/Evac.h
- rts/sm/Storage.c
Changes:
=====================================
libraries/ghc-internal/cbits/atomic.c
=====================================
@@ -163,7 +163,7 @@ hs_atomic_and64(StgWord x, StgWord64 val)
#pragma GCC diagnostic push
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wsync-fetch-and-nand-semantics-changed"
-#elif defined(__GNUC__)
+#else
#pragma GCC diagnostic ignored "-Wsync-nand"
#endif
=====================================
libraries/ghc-internal/cbits/ctz.c
=====================================
@@ -31,7 +31,7 @@ hs_ctz32(StgWord x)
StgWord
hs_ctz64(StgWord64 x)
{
-#if defined(__GNUC__) && (defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH))
+#if defined(i386_HOST_ARCH) || defined(powerpc_HOST_ARCH)
/* On Linux/i386, the 64bit `__builtin_ctzll()` intrinsic doesn't
get inlined by GCC but rather a short `__ctzdi2` runtime function
is inserted when needed into compiled object files.
=====================================
rts/RtsStartup.c
=====================================
@@ -125,13 +125,7 @@ void _fpreset(void)
x86_init_fpu();
}
-#if defined(__GNUC__)
void __attribute__((alias("_fpreset"))) fpreset(void);
-#else
-void fpreset(void) {
- _fpreset();
-}
-#endif
/* Set the console's CodePage to UTF-8 if using the new I/O manager and the CP
is still the default one. */
=====================================
rts/RtsSymbols.c
=====================================
@@ -963,7 +963,7 @@ extern char **environ;
RTS_INTCHAR_SYMBOLS
// 64-bit support functions in libgcc.a
-#if defined(__GNUC__) && SIZEOF_VOID_P <= 4 && !defined(_ABIN32)
+#if SIZEOF_VOID_P <= 4 && !defined(_ABIN32)
#define RTS_LIBGCC_SYMBOLS \
SymI_NeedsProto(__divdi3) \
SymI_NeedsProto(__udivdi3) \
@@ -974,7 +974,7 @@ extern char **environ;
SymI_NeedsProto(__ashrdi3) \
SymI_NeedsProto(__lshrdi3) \
SymI_NeedsProto(__fixunsdfdi)
-#elif defined(__GNUC__) && SIZEOF_VOID_P == 8
+#elif SIZEOF_VOID_P == 8
#define RTS_LIBGCC_SYMBOLS \
SymI_NeedsProto(__udivti3) \
SymI_NeedsProto(__umodti3)
=====================================
rts/include/Rts.h
=====================================
@@ -54,35 +54,19 @@ extern "C" {
#include "rts/Types.h"
#include "rts/Time.h"
-#if __GNUC__ >= 3
#define ATTRIBUTE_ALIGNED(n) __attribute__((aligned(n)))
-#else
-#define ATTRIBUTE_ALIGNED(n) /*nothing*/
-#endif
// Symbols that are extern, but private to the RTS, are declared
// with visibility "hidden" to hide them outside the RTS shared
// library.
#define RTS_PRIVATE GNUC3_ATTRIBUTE(visibility("hidden"))
-#if __GNUC__ >= 4
#define RTS_UNLIKELY(p) __builtin_expect((p),0)
-#else
-#define RTS_UNLIKELY(p) (p)
-#endif
-#if __GNUC__ >= 4
#define RTS_LIKELY(p) __builtin_expect(!!(p), 1)
-#else
-#define RTS_LIKELY(p) (p)
-#endif
/* __builtin_unreachable is supported since GNU C 4.5 */
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define RTS_UNREACHABLE __builtin_unreachable()
-#else
-#define RTS_UNREACHABLE abort()
-#endif
/* Prefetch primitives */
#define prefetchForRead(ptr) __builtin_prefetch(ptr, 0)
@@ -374,17 +358,8 @@ TICK_VAR(2)
Useful macros and inline functions
-------------------------------------------------------------------------- */
-#if defined(__GNUC__)
-#define SUPPORTS_TYPEOF
-#endif
-
-#if defined(SUPPORTS_TYPEOF)
#define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
#define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
-#else
-#define stg_min(a,b) ((a) <= (b) ? (a) : (b))
-#define stg_max(a,b) ((a) <= (b) ? (b) : (a))
-#endif
/* -------------------------------------------------------------------------- */
=====================================
rts/include/Stg.h
=====================================
@@ -131,20 +131,12 @@
/*
* GCC attributes
*/
-#if defined(__GNUC__)
#define GNU_ATTRIBUTE(at) __attribute__((at))
-#else
-#define GNU_ATTRIBUTE(at)
-#endif
-#if __GNUC__ >= 3
#define GNUC3_ATTRIBUTE(at) __attribute__((at))
-#else
-#define GNUC3_ATTRIBUTE(at)
-#endif
/* Used to mark a switch case that falls-through */
-#if (defined(__GNUC__) && __GNUC__ >= 7)
+#if __GNUC__ >= 7
// N.B. Don't enable fallthrough annotations when compiling with Clang.
// Apparently clang doesn't enable implicitly fallthrough warnings by default
// http://llvm.org/viewvc/llvm-project?revision=167655&view=revision
@@ -154,7 +146,7 @@
#define FALLTHROUGH ((void)0)
#endif /* __GNUC__ >= 7 */
-#if !defined(DEBUG) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+#if !defined(DEBUG)
#define GNUC_ATTR_HOT __attribute__((hot))
#else
#define GNUC_ATTR_HOT /* nothing */
@@ -168,21 +160,13 @@
See Note [Windows Stack allocations] */
#if defined(__clang__)
#define STG_NO_OPTIMIZE __attribute__((optnone))
-#elif defined(__GNUC__) || defined(__GNUG__)
-#define STG_NO_OPTIMIZE __attribute__((optimize("O0")))
#else
-#define STG_NO_OPTIMIZE /* nothing */
+#define STG_NO_OPTIMIZE __attribute__((optimize("O0")))
#endif
// Mark a function as accepting a printf-like format string.
-#if !defined(__GNUC__) && defined(mingw32_HOST_OS)
-/* On Win64, if we say "printf" then gcc thinks we are going to use
- MS format specifiers like %I64d rather than %llu */
-#define STG_PRINTF_ATTR(fmt_arg, rest) GNUC3_ATTRIBUTE(format(gnu_printf, fmt_arg, rest))
-#else
/* However, on OS X, "gnu_printf" isn't recognised */
#define STG_PRINTF_ATTR(fmt_arg, rest) GNUC3_ATTRIBUTE(format(printf, fmt_arg, rest))
-#endif
#define STG_RESTRICT __restrict__
@@ -204,13 +188,9 @@
# define stg__has_attribute(attr) (0)
#endif
-#ifdef __GNUC__
-# define STG_GNUC_GUARD_VERSION(major, minor) \
+#define STG_GNUC_GUARD_VERSION(major, minor) \
((__GNUC__ > (major)) || \
((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor))))
-#else
-# define STG_GNUC_GUARD_VERSION(major, minor) (0)
-#endif
/*
* The versions of the `__malloc__` attribute which take arguments are only
=====================================
rts/include/rts/Types.h
=====================================
@@ -16,16 +16,6 @@
#include