[libcxx-commits] [libcxxabi] [llvm] [Demangle] Guard DEMANGLE_ABI and add missing annotation (PR #202920)

Fabrice de Gans via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 07:08:05 PDT 2026


https://github.com/Steelskin updated https://github.com/llvm/llvm-project/pull/202920

>From 153512c33a096b7eb692a448c2309db60e9c4186 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <steelskin at gmail.com>
Date: Wed, 10 Jun 2026 12:24:46 +0200
Subject: [PATCH 1/3] [Demangle] Guard DEMANGLE_ABI and add missing annotation

This updates the DEMANGLE_ABI annotation to only be defined if it is not
already defined. This is required to parse the Demangle headers with the
ids-check script.
In addition, this adds one missing DEMANGLE_ABI annotation.

This effort is tracked in #109483.
---
 llvm/include/llvm/Demangle/DemangleConfig.h | 30 ++++++++++++++-------
 llvm/include/llvm/Demangle/Utility.h        |  2 +-
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/Demangle/DemangleConfig.h b/llvm/include/llvm/Demangle/DemangleConfig.h
index 5c48ae1972bec..7502df48a50e8 100644
--- a/llvm/include/llvm/Demangle/DemangleConfig.h
+++ b/llvm/include/llvm/Demangle/DemangleConfig.h
@@ -97,24 +97,36 @@
 #define DEMANGLE_NAMESPACE_BEGIN namespace llvm { namespace itanium_demangle {
 #define DEMANGLE_NAMESPACE_END } }
 
-/// DEMANGLE_ABI is the export/visibility macro used to mark symbols delcared in
+/// DEMANGLE_ABI is the export/visibility macro used to mark symbols declared in
 /// llvm/Demangle as exported when built as a shared library.
+#if !defined(DEMANGLE_ABI)
+
 #if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
+
 #define DEMANGLE_ABI
-#else
+
+#else // !(defined(LLVM_BUILD_STATIC) || [...])
+
 #if defined(_WIN32) && !defined(__MINGW32__)
+
 #if defined(LLVM_EXPORTS)
 #define DEMANGLE_ABI __declspec(dllexport)
-#else
+#else // !defined(LLVM_EXPORTS)
 #define DEMANGLE_ABI __declspec(dllimport)
-#endif
-#else
+#endif // defined(LLVM_EXPORTS)
+
+#else // !(defined(_WIN32) && !defined(__MINGW32__))
+
 #if __has_attribute(visibility)
 #define DEMANGLE_ABI __attribute__((__visibility__("default")))
-#else
+#else // !__has_attribute(visibility)
 #define DEMANGLE_ABI
-#endif
-#endif
-#endif
+#endif // __has_attribute(visibility)
+
+#endif // defined(_WIN32) && !defined(__MINGW32__)
+
+#endif // defined(LLVM_BUILD_STATIC) || [...]
+
+#endif // !defined(DEMANGLE_ABI)
 
 #endif
diff --git a/llvm/include/llvm/Demangle/Utility.h b/llvm/include/llvm/Demangle/Utility.h
index afdc1a397ca6f..56c052e6a2cf8 100644
--- a/llvm/include/llvm/Demangle/Utility.h
+++ b/llvm/include/llvm/Demangle/Utility.h
@@ -31,7 +31,7 @@ class Node;
 
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
-class OutputBuffer {
+class DEMANGLE_ABI OutputBuffer {
   char *Buffer = nullptr;
   size_t CurrentPosition = 0;
   size_t BufferCapacity = 0;

>From 06e7acb372dfd0ecebce133bc93202e10b64ab00 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <steelskin at gmail.com>
Date: Wed, 10 Jun 2026 13:23:36 +0200
Subject: [PATCH 2/3] Edit corresponding libcxxabi header

---
 libcxxabi/src/demangle/Utility.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index df5b54dca492d..ca420bce66d9c 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -31,7 +31,7 @@ class Node;
 
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
-class OutputBuffer {
+class DEMANGLE_ABI OutputBuffer {
   char *Buffer = nullptr;
   size_t CurrentPosition = 0;
   size_t BufferCapacity = 0;

>From 3cf926b80e042495e82f4be43eeac51ec886640c Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <steelskin at gmail.com>
Date: Wed, 10 Jun 2026 16:07:36 +0200
Subject: [PATCH 3/3] Re-indent the DEMANGLE_ABI preprocessor block

---
 llvm/include/llvm/Demangle/DemangleConfig.h | 49 +++++++++------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/llvm/include/llvm/Demangle/DemangleConfig.h b/llvm/include/llvm/Demangle/DemangleConfig.h
index 7502df48a50e8..9cd85efbbd232 100644
--- a/llvm/include/llvm/Demangle/DemangleConfig.h
+++ b/llvm/include/llvm/Demangle/DemangleConfig.h
@@ -99,34 +99,27 @@
 
 /// DEMANGLE_ABI is the export/visibility macro used to mark symbols declared in
 /// llvm/Demangle as exported when built as a shared library.
+// clang-format off
+// Autoformatting removes indentation, making this harder to read.
 #if !defined(DEMANGLE_ABI)
-
-#if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
-
-#define DEMANGLE_ABI
-
-#else // !(defined(LLVM_BUILD_STATIC) || [...])
-
-#if defined(_WIN32) && !defined(__MINGW32__)
-
-#if defined(LLVM_EXPORTS)
-#define DEMANGLE_ABI __declspec(dllexport)
-#else // !defined(LLVM_EXPORTS)
-#define DEMANGLE_ABI __declspec(dllimport)
-#endif // defined(LLVM_EXPORTS)
-
-#else // !(defined(_WIN32) && !defined(__MINGW32__))
-
-#if __has_attribute(visibility)
-#define DEMANGLE_ABI __attribute__((__visibility__("default")))
-#else // !__has_attribute(visibility)
-#define DEMANGLE_ABI
-#endif // __has_attribute(visibility)
-
-#endif // defined(_WIN32) && !defined(__MINGW32__)
-
-#endif // defined(LLVM_BUILD_STATIC) || [...]
-
-#endif // !defined(DEMANGLE_ABI)
+# if defined(LLVM_BUILD_STATIC) || !defined(LLVM_ENABLE_LLVM_EXPORT_ANNOTATIONS)
+#  define DEMANGLE_ABI
+# else
+#  if defined(_WIN32) && !defined(__MINGW32__)
+#   if defined(LLVM_EXPORTS)
+#    define DEMANGLE_ABI __declspec(dllexport)
+#   else
+#    define DEMANGLE_ABI __declspec(dllimport)
+#   endif
+#  else
+#   if __has_attribute(visibility)
+#    define DEMANGLE_ABI __attribute__((__visibility__("default")))
+#   else
+#    define DEMANGLE_ABI
+#   endif
+#  endif
+# endif
+#endif
+// clang-format on
 
 #endif



More information about the libcxx-commits mailing list