[llvm] Fix compiler errors in GVN.h for clang versions older than 15 (PR #107636)

Thomas Fransham via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 14:07:44 PDT 2024


https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/107636

>From b6606c2e6bcb6779f61dddf14ea9d1799bc2a4aa Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 6 Sep 2024 20:05:40 +0100
Subject: [PATCH 1/4] Fix compiler errors from clang versions older than 15 not
 supporting gnu style attributes on namespaces

Fixes errors in GVN.h after changes in #96630 to how LLVM_LIBRARY_VISIBILITY is defined
---
 llvm/include/llvm/Support/Compiler.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index e1d54af7dfcce1..0452f88cbf2c66 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -130,7 +130,12 @@
 
 #if (!(defined(_WIN32) || defined(__CYGWIN__)) ||                              \
      (defined(__MINGW32__) && defined(__clang__)))
+// Clang compilers older then 15 do not support gnu style attributes on namespaces
+#if defined(__clang__) && _clang_major__ < 15
+#define LLVM_LIBRARY_VISIBILITY [[gnu::visibility("hidden")]]
+#else
 #define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
+#endif
 #define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #elif defined(_WIN32)
 #define LLVM_ALWAYS_EXPORT __declspec(dllexport)

>From 6148ee3b0e66fa5ecac45cdc51e93e6378628d30 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 6 Sep 2024 21:05:45 +0100
Subject: [PATCH 2/4] Fix formatting

---
 llvm/include/llvm/Support/Compiler.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 0452f88cbf2c66..f3340fe73c387d 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -130,7 +130,8 @@
 
 #if (!(defined(_WIN32) || defined(__CYGWIN__)) ||                              \
      (defined(__MINGW32__) && defined(__clang__)))
-// Clang compilers older then 15 do not support gnu style attributes on namespaces
+// Clang compilers older then 15 do not support gnu style attributes on
+// namespaces.
 #if defined(__clang__) && _clang_major__ < 15
 #define LLVM_LIBRARY_VISIBILITY [[gnu::visibility("hidden")]]
 #else

>From 3dffc508faae87ad3ef5b8a292cfd1227d8fc78b Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 6 Sep 2024 21:15:34 +0100
Subject: [PATCH 3/4] Fix typo on clang version macro

---
 llvm/include/llvm/Support/Compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index f3340fe73c387d..211ac9fe3a532e 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -132,7 +132,7 @@
      (defined(__MINGW32__) && defined(__clang__)))
 // Clang compilers older then 15 do not support gnu style attributes on
 // namespaces.
-#if defined(__clang__) && _clang_major__ < 15
+#if defined(__clang__) && __clang_major__ < 15
 #define LLVM_LIBRARY_VISIBILITY [[gnu::visibility("hidden")]]
 #else
 #define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN

>From 946d770d6b9d8917fa4e5ffbaef89c2cedaabb94 Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 6 Sep 2024 22:06:07 +0100
Subject: [PATCH 4/4] Switch to a separate visibility macro for namespaces

---
 llvm/include/llvm/Support/Compiler.h      | 7 +++++--
 llvm/include/llvm/Transforms/Scalar/GVN.h | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 211ac9fe3a532e..140ff611af79fb 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -130,20 +130,23 @@
 
 #if (!(defined(_WIN32) || defined(__CYGWIN__)) ||                              \
      (defined(__MINGW32__) && defined(__clang__)))
+#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
 // Clang compilers older then 15 do not support gnu style attributes on
 // namespaces.
 #if defined(__clang__) && __clang_major__ < 15
-#define LLVM_LIBRARY_VISIBILITY [[gnu::visibility("hidden")]]
+#define LLVM_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]]
 #else
-#define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
+#define LLVM_LIBRARY_VISIBILITY_NAMESPACE LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
 #endif
 #define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #elif defined(_WIN32)
 #define LLVM_ALWAYS_EXPORT __declspec(dllexport)
 #define LLVM_LIBRARY_VISIBILITY
+#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
 #else
 #define LLVM_LIBRARY_VISIBILITY
 #define LLVM_ALWAYS_EXPORT
+#define LLVM_LIBRARY_VISIBILITY_NAMESPACE
 #endif
 
 /// LLVM_ABI is the main export/visibility macro to mark something as explicitly
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index debe2ee7991728..be6c0ec5edab07 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -56,7 +56,7 @@ class TargetLibraryInfo;
 class Value;
 /// A private "module" namespace for types and utilities used by GVN. These
 /// are implementation details and should not be used by clients.
-namespace LLVM_LIBRARY_VISIBILITY gvn {
+namespace LLVM_LIBRARY_VISIBILITY_NAMESPACE gvn {
 
 struct AvailableValue;
 struct AvailableValueInBlock;



More information about the llvm-commits mailing list