[llvm] [Analysis] Fix GCC warnings on ABI annotations (PR #222286)
Bruno De Fraine via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 03:01:12 PDT 2026
https://github.com/brunodf-gf created https://github.com/llvm/llvm-project/pull/222286
The GCC build is cluttered by type attribute warnings on some header files:
```
llvm/include/llvm/Analysis/RegionInfo.h:898:41: warning: type attributes ignored after type is already defined [-Wattributes]
898 | extern template class LLVM_TEMPLATE_ABI RegionBase<RegionTraits<Function>>;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
The annotations originate from PR #199019. These warnings occur because the template instantiation is triggered implicitly earlier, without the type attribute. This can be solved by placing the extern template instantiation before the implicit use.
Also, the implementation files were using LLVM_TEMPLATE_ABI instead of LLVM_EXPORT_TEMPLATE, as described in
llvm/docs/InterfaceExportAnnotations.rst#explicitly-instantiated-template-classes
This would also trigger this type of GCC warning.
>From 0b71564eeb7d78ddf010d2f3417756e57634e98e Mon Sep 17 00:00:00 2001
From: Bruno De Fraine <bruno.defraine at globalfoundries.com>
Date: Wed, 9 Sep 2026 11:39:17 +0200
Subject: [PATCH] [Analysis] Fix GCC warnings on ABI annotations
The GCC build is cluttered by type attribute warnings on some header files:
```
llvm/include/llvm/Analysis/RegionInfo.h:898:41: warning: type attributes ignored after type is already defined [-Wattributes]
898 | extern template class LLVM_TEMPLATE_ABI RegionBase<RegionTraits<Function>>;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
The annotations originate from PR#199019. These warnings occur because the
template instantiation is triggered implicitly earlier, without the type
attribute. This can be solved by placing the extern template instantiation
before the implicit use.
Also, the implementation files were using LLVM_TEMPLATE_ABI instead of
LLVM_EXPORT_TEMPLATE, as described in
llvm/docs/InterfaceExportAnnotations.rst#explicitly-instantiated-template-classes
This would also trigger this type of GCC warning.
---
llvm/include/llvm/Analysis/DominanceFrontier.h | 8 ++++----
llvm/include/llvm/Analysis/RegionInfo.h | 6 ++++--
llvm/lib/Analysis/DominanceFrontier.cpp | 4 ++--
llvm/lib/Analysis/RegionInfo.cpp | 6 +++---
4 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DominanceFrontier.h b/llvm/include/llvm/Analysis/DominanceFrontier.h
index 163914070d275..f659c688f27a0 100644
--- a/llvm/include/llvm/Analysis/DominanceFrontier.h
+++ b/llvm/include/llvm/Analysis/DominanceFrontier.h
@@ -91,6 +91,10 @@ class DominanceFrontierBase {
void analyze(const DomTreeT &DT);
};
+extern template class LLVM_TEMPLATE_ABI
+ DominanceFrontierBase<BasicBlock, false>;
+extern template class LLVM_TEMPLATE_ABI DominanceFrontierBase<BasicBlock, true>;
+
class DominanceFrontier : public DominanceFrontierBase<BasicBlock, false> {
public:
using DomTreeT = DomTreeBase<BasicBlock>;
@@ -126,10 +130,6 @@ class LLVM_ABI DominanceFrontierWrapperPass : public FunctionPass {
void dump() const;
};
-extern template class LLVM_TEMPLATE_ABI
- DominanceFrontierBase<BasicBlock, false>;
-extern template class LLVM_TEMPLATE_ABI DominanceFrontierBase<BasicBlock, true>;
-
/// Analysis pass which computes a \c DominanceFrontier.
class DominanceFrontierAnalysis
: public AnalysisInfoMixin<DominanceFrontierAnalysis> {
diff --git a/llvm/include/llvm/Analysis/RegionInfo.h b/llvm/include/llvm/Analysis/RegionInfo.h
index 8bda4c8d4e61c..289a2e2f0e370 100644
--- a/llvm/include/llvm/Analysis/RegionInfo.h
+++ b/llvm/include/llvm/Analysis/RegionInfo.h
@@ -874,6 +874,8 @@ class RegionInfoBase {
void verifyAnalysis() const;
};
+extern template class LLVM_TEMPLATE_ABI RegionNodeBase<RegionTraits<Function>>;
+
class RegionNode : public RegionNodeBase<RegionTraits<Function>> {
public:
inline RegionNode(Region *Parent, BasicBlock *Entry, bool isSubRegion = false)
@@ -884,6 +886,8 @@ class RegionNode : public RegionNodeBase<RegionTraits<Function>> {
}
};
+extern template class LLVM_TEMPLATE_ABI RegionBase<RegionTraits<Function>>;
+
class Region : public RegionBase<RegionTraits<Function>> {
public:
LLVM_ABI Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo *RI,
@@ -895,8 +899,6 @@ class Region : public RegionBase<RegionTraits<Function>> {
}
};
-extern template class LLVM_TEMPLATE_ABI RegionBase<RegionTraits<Function>>;
-extern template class LLVM_TEMPLATE_ABI RegionNodeBase<RegionTraits<Function>>;
extern template class LLVM_TEMPLATE_ABI RegionInfoBase<RegionTraits<Function>>;
class LLVM_ABI RegionInfo : public RegionInfoBase<RegionTraits<Function>> {
diff --git a/llvm/lib/Analysis/DominanceFrontier.cpp b/llvm/lib/Analysis/DominanceFrontier.cpp
index c833b482a2da2..31c34053d28c2 100644
--- a/llvm/lib/Analysis/DominanceFrontier.cpp
+++ b/llvm/lib/Analysis/DominanceFrontier.cpp
@@ -21,8 +21,8 @@ using namespace llvm;
namespace llvm {
-template class LLVM_TEMPLATE_ABI DominanceFrontierBase<BasicBlock, false>;
-template class LLVM_TEMPLATE_ABI DominanceFrontierBase<BasicBlock, true>;
+template class LLVM_EXPORT_TEMPLATE DominanceFrontierBase<BasicBlock, false>;
+template class LLVM_EXPORT_TEMPLATE DominanceFrontierBase<BasicBlock, true>;
} // end namespace llvm
diff --git a/llvm/lib/Analysis/RegionInfo.cpp b/llvm/lib/Analysis/RegionInfo.cpp
index bcb98acd038b7..09dbb60e8be31 100644
--- a/llvm/lib/Analysis/RegionInfo.cpp
+++ b/llvm/lib/Analysis/RegionInfo.cpp
@@ -28,9 +28,9 @@ using namespace llvm;
namespace llvm {
-template class LLVM_TEMPLATE_ABI RegionBase<RegionTraits<Function>>;
-template class LLVM_TEMPLATE_ABI RegionNodeBase<RegionTraits<Function>>;
-template class LLVM_TEMPLATE_ABI RegionInfoBase<RegionTraits<Function>>;
+template class LLVM_EXPORT_TEMPLATE RegionBase<RegionTraits<Function>>;
+template class LLVM_EXPORT_TEMPLATE RegionNodeBase<RegionTraits<Function>>;
+template class LLVM_EXPORT_TEMPLATE RegionInfoBase<RegionTraits<Function>>;
} // end namespace llvm
More information about the llvm-commits
mailing list