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

Thomas Fransham via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 2 14:42:21 PDT 2024


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

>From f4e51ecd076a73d1ebc7a439001d0ed22071b019 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 3031d81b3df731..a683a989487b42 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2727,7 +2727,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";
 
@@ -3185,7 +3185,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 e395af0fe39591382fdd33ebc31c8aee10cb8314 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 a683a989487b42..5a80c8c0b7ad36 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2727,7 +2727,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