[llvm] 15dc2d5 - [IR] Prevent implicit SymbolTableListTraits template instantiation (#111600)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 06:11:59 PDT 2024


Author: Victor Mustya
Date: 2024-10-09T06:11:55-07:00
New Revision: 15dc2d5c5e55e6f0b9e3a78d352698b8873f2566

URL: https://github.com/llvm/llvm-project/commit/15dc2d5c5e55e6f0b9e3a78d352698b8873f2566
DIFF: https://github.com/llvm/llvm-project/commit/15dc2d5c5e55e6f0b9e3a78d352698b8873f2566.diff

LOG: [IR] Prevent implicit SymbolTableListTraits template instantiation (#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.

Added: 
    

Modified: 
    llvm/include/llvm/IR/SymbolTableListTraits.h

Removed: 
    


################################################################################
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