[llvm] Stop using __attribute__((retain)) in GCC builds (PR #133793)

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 31 13:43:30 PDT 2025


https://github.com/MatzeB updated https://github.com/llvm/llvm-project/pull/133793

>From cf44f472b66cf3d2a22e3e81e0518d02072e3515 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Mon, 31 Mar 2025 13:36:49 -0700
Subject: [PATCH] Stop using __attribute__((retain)) in GCC builds

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

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index ff6f5e44ae2f1..a6058955c4038 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -231,8 +231,15 @@
 #endif
 
 #if __has_attribute(retain)
+#if defined(__clang__) || !defined(__GNUC__)
 #define LLVM_ATTRIBUTE_RETAIN __attribute__((__retain__))
 #else
+// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587
+// GCC may produce "warning: ‘retain’ attribute ignored" (despite
+// __has_attribute(retain) being 1).
+#define LLVM_ATTRIBUTE_RETAIN
+#endif
+#else
 #define LLVM_ATTRIBUTE_RETAIN
 #endif
 



More information about the llvm-commits mailing list