From 28bcd5c89f9c79b19aaf6ae82ad70253a2c9caff Mon Sep 17 00:00:00 2001 From: Victor Mustya 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 bd31fca5e525b..fcf6f0fb15280 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 { 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; +extern template class SymbolTableListTraits; +extern template class SymbolTableListTraits; +extern template class SymbolTableListTraits; +extern template class SymbolTableListTraits; + /// List that automatically updates parent links and symbol tables. /// /// When nodes are inserted into and removed from this list, the associated