From 4ec233ecfc7f061c19d0c5ef98ad05719b1161e7 Mon Sep 17 00:00:00 2001
From: Sylvain Henry <sylvain@haskus.fr>
Date: Tue, 25 Jun 2019 18:53:22 +0200
Subject: [PATCH] Fix GCC warnings with __clear_cache builtin (#16867)

---
 rts/sm/Storage.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c
index f889e2262bee..2e03b776956a 100644
--- a/rts/sm/Storage.c
+++ b/rts/sm/Storage.c
@@ -1363,13 +1363,18 @@ StgWord calcTotalCompactW (void)
 #include <libkern/OSCacheControl.h>
 #endif
 
+/* __builtin___clear_cache is supported since GNU C 4.3.6.
+ * We pick 4.4 to simplify condition a bit.
+ */
+#define GCC_HAS_BUILTIN_CLEAR_CACHE (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+
 #if defined(__clang__)
 /* clang defines __clear_cache as a builtin on some platforms.
  * For example on armv7-linux-androideabi. The type slightly
  * differs from gcc.
  */
 extern void __clear_cache(void * begin, void * end);
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) && !GCC_HAS_BUILTIN_CLEAR_CACHE
 /* __clear_cache is a libgcc function.
  * It existed before __builtin___clear_cache was introduced.
  * See #8562.
@@ -1397,15 +1402,12 @@ void flushExec (W_ len, AdjustorExecutable exec_addr)
   __clear_cache((void*)begin, (void*)end);
 # endif
 #elif defined(__GNUC__)
-  /* For all other platforms, fall back to a libgcc builtin. */
   unsigned char* begin = (unsigned char*)exec_addr;
   unsigned char* end   = begin + len;
-  /* __builtin___clear_cache is supported since GNU C 4.3.6.
-   * We pick 4.4 to simplify condition a bit.
-   */
-# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# if GCC_HAS_BUILTIN_CLEAR_CACHE
   __builtin___clear_cache((void*)begin, (void*)end);
 # else
+  /* For all other platforms, fall back to a libgcc builtin. */
   __clear_cache((void*)begin, (void*)end);
 # endif
 #else
-- 
GitLab