[clang] [Clang][TableGen] Add explicit symbol visibility macros to code generated (PR #109362)

Thomas Fransham via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 19:22:32 PDT 2024


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

>From 363e96ba9ed442698c134f7f716a667e65ba3dbb Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Mon, 8 Jul 2024 01:48:46 +0100
Subject: [PATCH 1/2] [Clang][TableGen] Add explicit symbol visibility macros
 to code generated

Update ClangAttrEmitter tablegen to add explicit symbol visibility macros
to function declarations it creates.
Both AnnotateFunctions and Attribute example plugins require clang::AnnotateAttr
TableGen created functions to be exported from the Clang shared library.
---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 87be48c215e230..43c423eb033890 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,7 @@ static void emitAttributes(const RecordKeeper &Records, raw_ostream &OS,
     }
 
     if (Header)
-      OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n";
+      OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName << " {\n";
     else
       OS << "\n// " << R.getName() << "Attr implementation\n\n";
 
@@ -3220,7 +3220,8 @@ void clang::EmitClangAttrClass(const RecordKeeper &Records, raw_ostream &OS) {
   emitSourceFileHeader("Attribute classes' definitions", OS, Records);
 
   OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
-  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
+  OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n";
+  OS << "#include \"clang/Support/Compiler.h\"\n\n";
 
   emitAttributes(Records, OS, true);
 

>From 8888f7ca7499008e9f18ed3b38fb1a224d22ad7f Mon Sep 17 00:00:00 2001
From: Thomas Fransham <tfransham at gmail.com>
Date: Fri, 20 Sep 2024 03:10:15 +0100
Subject: [PATCH 2/2] Fix formatting

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 43c423eb033890..624b7d46fb535a 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2762,7 +2762,8 @@ static void emitAttributes(const RecordKeeper &Records, raw_ostream &OS,
     }
 
     if (Header)
-      OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName << " {\n";
+      OS << "class CLANG_ABI " << R.getName() << "Attr : public " << SuperName
+         << " {\n";
     else
       OS << "\n// " << R.getName() << "Attr implementation\n\n";
 



More information about the cfe-commits mailing list