[llvm] [IR] Prevent implicit SymbolTableListTraits template instantiation (PR #111600)

Victor Mustya via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 15:51:50 PDT 2024


https://github.com/vmustya created https://github.com/llvm/llvm-project/pull/111600

The `SymbolTableListTraits` template is explicitly instantiated for the
following types:
  * `llvm/lib/IR/Function.cpp`
    - `BasicBlock`
  * `llvm/lib/IR/Module.cpp`
    - `Function`
    - `GlobalAlias`
    - `GlobalIFunc`
    - `GlobalVariable`

When LLVM is built on Windows with the `LLVM_EXPORT_SYMBOLS_FOR_PLUGINS`
option enabled, the implicit instantiation of the template prevents the
`SymbolTableListTraits` template from being exported. This causes link
errors when the template or IR API is used in a plugin.

This change prevents the template being implicitly instantiated for
these types.

>From 28bcd5c89f9c79b19aaf6ae82ad70253a2c9caff Mon Sep 17 00:00:00 2001
From: Victor Mustya <victor.mustya at intel.com>
Date: Mon, 7 Oct 2024 20:40:47 -0700
Subject: [PATCH] [IR] Prevent implicit SymbolTableListTraits template
 instantiation

The `SymbolTableListTraits` template is explicitly instantiated for the
following types:
  * `llvm/lib/IR/Function.cpp`
    - `BasicBlock`
  * `llvm/lib/IR/Module.cpp`
    - `Function`
    - `GlobalAlias`
    - `GlobalIFunc`
    - `GlobalVariable`

When LLVM is built on Windows with the `LLVM_EXPORT_SYMBOLS_FOR_PLUGINS`
option enabled, the implicit instantiation of the template prevents the
`SymbolTableListTraits` template from being exported. This causes link
errors when the template or IR API is used in a plugin.

This change prevents the template being implicitly instantiated for
these types.
---
 llvm/include/llvm/IR/SymbolTableListTraits.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/llvm/include/llvm/IR/SymbolTableListTraits.h b/llvm/include/llvm/IR/SymbolTableListTraits.h
index bd31fca5e525b6..fcf6f0fb152804 100644
--- a/llvm/include/llvm/IR/SymbolTableListTraits.h
+++ b/llvm/include/llvm/IR/SymbolTableListTraits.h
@@ -106,6 +106,15 @@ class SymbolTableListTraits : public ilist_alloc_traits<ValueSubClass> {
   static ValueSymbolTable *toPtr(ValueSymbolTable &R) { return &R; }
 };
 
+// The SymbolTableListTraits template is explicitly instantiated for the
+// following data types, so add extern template statements to prevent implicit
+// instantiation.
+extern template class SymbolTableListTraits<BasicBlock>;
+extern template class SymbolTableListTraits<Function>;
+extern template class SymbolTableListTraits<GlobalAlias>;
+extern template class SymbolTableListTraits<GlobalIFunc>;
+extern template class SymbolTableListTraits<GlobalVariable>;
+
 /// List that automatically updates parent links and symbol tables.
 ///
 /// When nodes are inserted into and removed from this list, the associated



More information about the llvm-commits mailing list