[flang-commits] [flang] [Flang][#212316] Fix -Wunused-template errors under -Werror (PR #218985)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 15 03:23:08 PDT 2026
https://github.com/laoshd updated https://github.com/llvm/llvm-project/pull/218985
>From 6f05fe4cc823e9cbb8203c42ffc903897d4c6a99 Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Wed, 26 Aug 2026 11:46:48 -0500
Subject: [PATCH 1/4] [Flang][#212316] Fix -Wunused-template errors under
-Werror
Some function templates with internal linkage are never instantiated in
their translation unit, which triggers -Wunused-template. With clang
builds that enable this warning by default and -DFLANG_ENABLE_WERROR=ON,
these become fatal errors.
Fix each case with the minimal change that preserves semantics:
- Drop 'static' (give external linkage) for free function templates at
namespace/file scope: DirectivesCommon.h, PFTBuilder.h, RTBuilder.h,
fold-reduction.h, formatting.cpp, check-cuda.cpp, resolve-directives.cpp.
- Add [[maybe_unused]] where dropping 'static' would change linkage/ODR
semantics (member, anonymous-namespace, or global generic-named
templates): ConvertType.cpp, IO.cpp, CUFAllocationConversion.cpp,
openmp-utils.cpp.
No functional change. With AI assistance.
---
flang/include/flang/Lower/DirectivesCommon.h | 4 ++--
flang/include/flang/Lower/PFTBuilder.h | 2 +-
.../flang/Optimizer/Builder/Runtime/RTBuilder.h | 4 ++--
flang/lib/Evaluate/fold-reduction.h | 12 ++++++------
flang/lib/Evaluate/formatting.cpp | 4 ++--
flang/lib/Lower/ConvertType.cpp | 3 ++-
flang/lib/Lower/IO.cpp | 5 +++--
.../Transforms/CUDA/CUFAllocationConversion.cpp | 2 +-
flang/lib/Semantics/check-cuda.cpp | 2 +-
flang/lib/Semantics/openmp-utils.cpp | 6 ++++--
flang/lib/Semantics/resolve-directives.cpp | 2 +-
11 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/flang/include/flang/Lower/DirectivesCommon.h b/flang/include/flang/Lower/DirectivesCommon.h
index 6f6089a4ffb6c..ac129ef18d7e0 100644
--- a/flang/include/flang/Lower/DirectivesCommon.h
+++ b/flang/include/flang/Lower/DirectivesCommon.h
@@ -75,11 +75,11 @@ getDataOperandBaseAddr(Fortran::lower::AbstractConverter &converter,
namespace detail {
template <typename T> //
-static T &&AsRvalueRef(T &&t) {
+T &&AsRvalueRef(T &&t) {
return std::move(t);
}
template <typename T> //
-static T AsRvalueRef(T &t) {
+T AsRvalueRef(T &t) {
return t;
}
template <typename T> //
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index f495046c66a32..3aa0bd024c382 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -852,7 +852,7 @@ struct Program {
/// Helper to get location from FunctionLikeUnit/ModuleLikeUnit begin/end
/// statements.
template <typename T>
-static parser::CharBlock stmtSourceLoc(const T &stmt) {
+parser::CharBlock stmtSourceLoc(const T &stmt) {
return stmt.visit(common::visitors{[](const auto &x) { return x.source; }});
}
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index e2131aa7708a3..f18b09fb3fd93 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -843,7 +843,7 @@ struct RuntimeTableEntry<RuntimeTableKey<KT>, RuntimeIdentifier<Cs...>> {
/// Get (or generate) the MLIR FuncOp for a given runtime function. Its template
/// argument is intended to be of the form: <mkRTKey(runtime function name)>.
template <typename RuntimeEntry>
-static mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
+mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
fir::FirOpBuilder &builder,
bool isIO = false) {
using namespace Fortran::runtime;
@@ -857,7 +857,7 @@ static mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
/// Get (or generate) the MLIR FuncOp for a given IO runtime function.
template <typename E>
-static mlir::func::FuncOp getIORuntimeFunc(mlir::Location loc,
+mlir::func::FuncOp getIORuntimeFunc(mlir::Location loc,
fir::FirOpBuilder &builder) {
return getRuntimeFunc<E>(loc, builder, /*isIO=*/true);
}
diff --git a/flang/lib/Evaluate/fold-reduction.h b/flang/lib/Evaluate/fold-reduction.h
index a068364135295..566e04ed772bf 100644
--- a/flang/lib/Evaluate/fold-reduction.h
+++ b/flang/lib/Evaluate/fold-reduction.h
@@ -15,7 +15,7 @@ namespace Fortran::evaluate {
// DOT_PRODUCT
template <typename T>
-static Expr<T> FoldDotProduct(
+Expr<T> FoldDotProduct(
FoldingContext &context, FunctionRef<T> &&funcRef) {
using Element = typename Constant<T>::Element;
auto args{funcRef.arguments()};
@@ -132,7 +132,7 @@ template <typename T> struct ArrayAndMask {
Constant<LogicalResult> mask;
};
template <typename T>
-static std::optional<ArrayAndMask<T>> ProcessReductionArgs(
+std::optional<ArrayAndMask<T>> ProcessReductionArgs(
FoldingContext &context, ActualArguments &arg, std::optional<int> &dim,
int arrayIndex, std::optional<int> dimIndex = std::nullopt,
std::optional<int> maskIndex = std::nullopt) {
@@ -174,7 +174,7 @@ static std::optional<ArrayAndMask<T>> ProcessReductionArgs(
// operator()(Scalar<T> &, const ConstantSubscripts &, bool first)
// and Done(Scalar<T> &).
template <typename T, typename ACCUMULATOR, typename ARRAY>
-static Constant<T> DoReduction(const Constant<ARRAY> &array,
+Constant<T> DoReduction(const Constant<ARRAY> &array,
const Constant<LogicalResult> &mask, std::optional<int> &dim,
const Scalar<T> &identity, ACCUMULATOR &accumulator) {
ConstantSubscripts at{array.lbounds()};
@@ -265,7 +265,7 @@ template <typename T, bool ABS = false> class MaxvalMinvalAccumulator {
};
template <typename T>
-static Expr<T> FoldMaxvalMinval(FoldingContext &context, FunctionRef<T> &&ref,
+Expr<T> FoldMaxvalMinval(FoldingContext &context, FunctionRef<T> &&ref,
RelationalOperator opr, const Scalar<T> &identity) {
static_assert(T::category == TypeCategory::Integer ||
T::category == TypeCategory::Unsigned ||
@@ -309,7 +309,7 @@ template <typename T> class ProductAccumulator {
};
template <typename T>
-static Expr<T> FoldProduct(
+Expr<T> FoldProduct(
FoldingContext &context, FunctionRef<T> &&ref, Scalar<T> identity) {
static_assert(T::category == TypeCategory::Integer ||
T::category == TypeCategory::Unsigned ||
@@ -371,7 +371,7 @@ template <typename T> class SumAccumulator {
};
template <typename T>
-static Expr<T> FoldSum(FoldingContext &context, FunctionRef<T> &&ref) {
+Expr<T> FoldSum(FoldingContext &context, FunctionRef<T> &&ref) {
static_assert(T::category == TypeCategory::Integer ||
T::category == TypeCategory::Unsigned ||
T::category == TypeCategory::Real ||
diff --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp
index fcedd15ee1791..1187daa5620cc 100644
--- a/flang/lib/Evaluate/formatting.cpp
+++ b/flang/lib/Evaluate/formatting.cpp
@@ -414,7 +414,7 @@ template <typename T> static Precedence ToPrecedence(const Expr<T> &expr) {
return common::visit([](const auto &x) { return ToPrecedence(x); }, expr.u);
}
-template <typename T> static bool IsNegatedScalarConstant(const Expr<T> &expr) {
+template <typename T> bool IsNegatedScalarConstant(const Expr<T> &expr) {
static constexpr TypeCategory cat{T::category};
if constexpr (cat == TypeCategory::Integer || cat == TypeCategory::Real) {
if (auto n{GetScalarConstantValue<T>(expr)}) {
@@ -425,7 +425,7 @@ template <typename T> static bool IsNegatedScalarConstant(const Expr<T> &expr) {
}
template <TypeCategory CAT>
-static bool IsNegatedScalarConstant(const Expr<SomeKind<CAT>> &expr) {
+bool IsNegatedScalarConstant(const Expr<SomeKind<CAT>> &expr) {
return common::visit(
[](const auto &x) { return IsNegatedScalarConstant(x); }, expr.u);
}
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 0fdbdfcc74424..ca4f19c6fcb92 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -536,7 +536,8 @@ struct TypeBuilderImpl {
}
template <typename A>
- Fortran::lower::LenParameterTy getCharacterLength(const A &expr) {
+ [[maybe_unused]] Fortran::lower::LenParameterTy getCharacterLength(
+ const A &expr) {
return fir::SequenceType::getUnknownExtent();
}
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 611b6918fc46c..3d724578d726b 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -126,14 +126,15 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter,
/// Helper function to retrieve the name of the IO function given the key `A`
template <typename A>
-static constexpr const char *getName() {
+[[maybe_unused]] static constexpr const char *getName() {
return std::get<A>(Fortran::lower::newIOTable).name;
}
/// Helper function to retrieve the type model signature builder of the IO
/// function as defined by the key `A`
template <typename A>
-static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
+[[maybe_unused]] static constexpr fir::runtime::FuncTypeBuilderFunc
+getTypeModel() {
return std::get<A>(Fortran::lower::newIOTable).getTypeModel();
}
diff --git a/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp b/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
index b75d289faca7a..c8fb7b0797188 100644
--- a/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
@@ -43,7 +43,7 @@ using namespace Fortran::runtime::cuda;
namespace {
template <typename OpTy>
-static bool isPinned(OpTy op) {
+[[maybe_unused]] bool isPinned(OpTy op) {
if (op.getDataAttr() && *op.getDataAttr() == cuf::DataAttribute::Pinned)
return true;
return false;
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 8922e0eb559e8..5d432fd1f3db3 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -208,7 +208,7 @@ struct FindHostArray
};
template <typename A>
-static MaybeMsg CheckUnwrappedExpr(
+MaybeMsg CheckUnwrappedExpr(
SemanticsContext &context, const A &x, bool allowHostCallees = false) {
if (const auto *expr{parser::Unwrap<parser::Expr>(x)}) {
return DeviceExprChecker{context, allowHostCallees}(expr->typedExpr);
diff --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp
index a341cf4fa1706..d227259f94f71 100644
--- a/flang/lib/Semantics/openmp-utils.cpp
+++ b/flang/lib/Semantics/openmp-utils.cpp
@@ -464,11 +464,13 @@ struct ContiguousHelper {
: fctx_(context.foldingContext()) {}
template <typename Contained>
- std::optional<bool> Visit(const common::Indirection<Contained> &x) {
+ [[maybe_unused]] std::optional<bool> Visit(
+ const common::Indirection<Contained> &x) {
return Visit(x.value());
}
template <typename Contained>
- std::optional<bool> Visit(const common::Reference<Contained> &x) {
+ [[maybe_unused]] std::optional<bool> Visit(
+ const common::Reference<Contained> &x) {
return Visit(x.get());
}
template <typename T> std::optional<bool> Visit(const evaluate::Expr<T> &x) {
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 143fe385768d7..165d879dea358 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -36,7 +36,7 @@
namespace Fortran::semantics {
template <typename T>
-static Scope *GetScope(SemanticsContext &context, const T &x) {
+Scope *GetScope(SemanticsContext &context, const T &x) {
if (auto source{GetLastSource(x)}) {
return &context.FindScope(*source);
} else {
>From 3b0bb44ed181ef2ca49a2a96edc4a5f9b53495fe Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Wed, 26 Aug 2026 13:13:08 -0500
Subject: [PATCH 2/4] [Flang][#212316] Corrects code formats.
---
.../include/flang/Optimizer/Builder/Runtime/RTBuilder.h | 6 +++---
flang/lib/Evaluate/fold-reduction.h | 9 ++++-----
flang/lib/Lower/ConvertType.cpp | 4 ++--
flang/lib/Semantics/resolve-directives.cpp | 3 +--
4 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index f18b09fb3fd93..67bdf6867251a 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -844,8 +844,8 @@ struct RuntimeTableEntry<RuntimeTableKey<KT>, RuntimeIdentifier<Cs...>> {
/// argument is intended to be of the form: <mkRTKey(runtime function name)>.
template <typename RuntimeEntry>
mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
- fir::FirOpBuilder &builder,
- bool isIO = false) {
+ fir::FirOpBuilder &builder,
+ bool isIO = false) {
using namespace Fortran::runtime;
auto name = RuntimeEntry::name;
auto func = builder.getNamedFunction(name);
@@ -858,7 +858,7 @@ mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
/// Get (or generate) the MLIR FuncOp for a given IO runtime function.
template <typename E>
mlir::func::FuncOp getIORuntimeFunc(mlir::Location loc,
- fir::FirOpBuilder &builder) {
+ fir::FirOpBuilder &builder) {
return getRuntimeFunc<E>(loc, builder, /*isIO=*/true);
}
diff --git a/flang/lib/Evaluate/fold-reduction.h b/flang/lib/Evaluate/fold-reduction.h
index 566e04ed772bf..aef5e93287297 100644
--- a/flang/lib/Evaluate/fold-reduction.h
+++ b/flang/lib/Evaluate/fold-reduction.h
@@ -15,8 +15,7 @@ namespace Fortran::evaluate {
// DOT_PRODUCT
template <typename T>
-Expr<T> FoldDotProduct(
- FoldingContext &context, FunctionRef<T> &&funcRef) {
+Expr<T> FoldDotProduct(FoldingContext &context, FunctionRef<T> &&funcRef) {
using Element = typename Constant<T>::Element;
auto args{funcRef.arguments()};
CHECK(args.size() == 2);
@@ -132,9 +131,9 @@ template <typename T> struct ArrayAndMask {
Constant<LogicalResult> mask;
};
template <typename T>
-std::optional<ArrayAndMask<T>> ProcessReductionArgs(
- FoldingContext &context, ActualArguments &arg, std::optional<int> &dim,
- int arrayIndex, std::optional<int> dimIndex = std::nullopt,
+std::optional<ArrayAndMask<T>> ProcessReductionArgs(FoldingContext &context,
+ ActualArguments &arg, std::optional<int> &dim, int arrayIndex,
+ std::optional<int> dimIndex = std::nullopt,
std::optional<int> maskIndex = std::nullopt) {
if (arg.empty()) {
return std::nullopt;
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index ca4f19c6fcb92..8bb8f359b2e79 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -536,8 +536,8 @@ struct TypeBuilderImpl {
}
template <typename A>
- [[maybe_unused]] Fortran::lower::LenParameterTy getCharacterLength(
- const A &expr) {
+ [[maybe_unused]] Fortran::lower::LenParameterTy
+ getCharacterLength(const A &expr) {
return fir::SequenceType::getUnknownExtent();
}
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 165d879dea358..1101dd7cfea48 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -35,8 +35,7 @@
namespace Fortran::semantics {
-template <typename T>
-Scope *GetScope(SemanticsContext &context, const T &x) {
+template <typename T> Scope *GetScope(SemanticsContext &context, const T &x) {
if (auto source{GetLastSource(x)}) {
return &context.FindScope(*source);
} else {
>From 23e08439473b2c2daefdfb454c5eb39ea36853bc Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Tue, 8 Sep 2026 04:35:22 -0500
Subject: [PATCH 3/4] [Flang][#212316] Remove unused template functions.
Also add [[maybe_unused]] attribute to relevant functions.
---
flang/include/flang/Lower/DirectivesCommon.h | 2 +-
flang/lib/Evaluate/formatting.cpp | 16 ----------------
flang/lib/Evaluate/tools.cpp | 7 ++++---
.../Transforms/CUDA/CUFAllocationConversion.cpp | 7 -------
flang/lib/Semantics/check-cuda.cpp | 2 +-
flang/lib/Semantics/resolve-directives.cpp | 8 --------
6 files changed, 6 insertions(+), 36 deletions(-)
diff --git a/flang/include/flang/Lower/DirectivesCommon.h b/flang/include/flang/Lower/DirectivesCommon.h
index ac129ef18d7e0..0d436bc61a51c 100644
--- a/flang/include/flang/Lower/DirectivesCommon.h
+++ b/flang/include/flang/Lower/DirectivesCommon.h
@@ -83,7 +83,7 @@ T AsRvalueRef(T &t) {
return t;
}
template <typename T> //
-static T AsRvalueRef(const T &t) {
+T AsRvalueRef(const T &t) {
return t;
}
diff --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp
index 1187daa5620cc..161372e3ab61b 100644
--- a/flang/lib/Evaluate/formatting.cpp
+++ b/flang/lib/Evaluate/formatting.cpp
@@ -414,22 +414,6 @@ template <typename T> static Precedence ToPrecedence(const Expr<T> &expr) {
return common::visit([](const auto &x) { return ToPrecedence(x); }, expr.u);
}
-template <typename T> bool IsNegatedScalarConstant(const Expr<T> &expr) {
- static constexpr TypeCategory cat{T::category};
- if constexpr (cat == TypeCategory::Integer || cat == TypeCategory::Real) {
- if (auto n{GetScalarConstantValue<T>(expr)}) {
- return n->IsNegative();
- }
- }
- return false;
-}
-
-template <TypeCategory CAT>
-bool IsNegatedScalarConstant(const Expr<SomeKind<CAT>> &expr) {
- return common::visit(
- [](const auto &x) { return IsNegatedScalarConstant(x); }, expr.u);
-}
-
struct OperatorSpelling {
const char *prefix{""}, *infix{","}, *suffix{""};
};
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index cd7e28b5724ac..d9e400c52bb41 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1483,7 +1483,8 @@ static SignedNumericExpr<CAT, KIND> buildSignedAdd(
}
template <typename T>
-static std::optional<Expr<SomeType>> tryBuildSplitSumExpressionTree(const T &) {
+[[maybe_unused]] static std::optional<Expr<SomeType>>
+tryBuildSplitSumExpressionTree(const T &) {
return std::nullopt;
}
@@ -1533,8 +1534,8 @@ static std::optional<NumericExpr<CAT, KIND>> tryBuildSplitSumExpressionTree(
}
template <common::TypeCategory CAT>
-static std::optional<Expr<SomeType>> tryBuildSplitSumExpressionTree(
- const Expr<SomeKind<CAT>> &expr) {
+[[maybe_unused]] static std::optional<Expr<SomeType>>
+tryBuildSplitSumExpressionTree(const Expr<SomeKind<CAT>> &expr) {
// Keep the supported categories explicit: integer reassociation requires a
// separate intermediate-range policy.
if constexpr (CAT == common::TypeCategory::Real ||
diff --git a/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp b/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
index c8fb7b0797188..7d62e4ca1ec1a 100644
--- a/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CUDA/CUFAllocationConversion.cpp
@@ -42,13 +42,6 @@ using namespace Fortran::runtime::cuda;
namespace {
-template <typename OpTy>
-[[maybe_unused]] bool isPinned(OpTy op) {
- if (op.getDataAttr() && *op.getDataAttr() == cuf::DataAttribute::Pinned)
- return true;
- return false;
-}
-
static inline unsigned getMemType(cuf::DataAttribute attr) {
if (attr == cuf::DataAttribute::Device)
return kMemTypeDevice;
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 5d432fd1f3db3..1cfd085cdd1aa 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -208,7 +208,7 @@ struct FindHostArray
};
template <typename A>
-MaybeMsg CheckUnwrappedExpr(
+[[maybe_unused]] static MaybeMsg CheckUnwrappedExpr(
SemanticsContext &context, const A &x, bool allowHostCallees = false) {
if (const auto *expr{parser::Unwrap<parser::Expr>(x)}) {
return DeviceExprChecker{context, allowHostCallees}(expr->typedExpr);
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 1101dd7cfea48..1566553484176 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -35,14 +35,6 @@
namespace Fortran::semantics {
-template <typename T> Scope *GetScope(SemanticsContext &context, const T &x) {
- if (auto source{GetLastSource(x)}) {
- return &context.FindScope(*source);
- } else {
- return nullptr;
- }
-}
-
template <typename T> class DirectiveAttributeVisitor {
public:
explicit DirectiveAttributeVisitor(SemanticsContext &context)
>From 2d1046bf861bb6e9e73cd0045c77db4154dec8c5 Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Fri, 11 Sep 2026 10:38:54 -0500
Subject: [PATCH 4/4] [Flang][llvm#212316] Remove unused template functions
from ConvertType, IO, and openmp-utils
---
flang/lib/Lower/ConvertType.cpp | 6 ---
flang/lib/Lower/IO.cpp | 58 ----------------------------
flang/lib/Semantics/openmp-utils.cpp | 10 -----
3 files changed, 74 deletions(-)
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 8bb8f359b2e79..c8253ba25fc6f 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -535,12 +535,6 @@ struct TypeBuilderImpl {
llvm_unreachable("unknown character kind");
}
- template <typename A>
- [[maybe_unused]] Fortran::lower::LenParameterTy
- getCharacterLength(const A &expr) {
- return fir::SequenceType::getUnknownExtent();
- }
-
template <typename T>
Fortran::lower::LenParameterTy
getCharacterLength(const Fortran::evaluate::FunctionRef<T> &funcRef) {
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 3d724578d726b..c089c7c1b0596 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -44,50 +44,6 @@ using namespace Fortran::runtime::io;
#define mkIOKey(X) FirmkKey(IONAME(X))
-namespace Fortran::lower {
-/// Static table of IO runtime calls
-///
-/// This logical map contains the name and type builder function for each IO
-/// runtime function listed in the tuple. This table is fully constructed at
-/// compile-time. Use the `mkIOKey` macro to access the table.
-static constexpr std::tuple<
- mkIOKey(BeginBackspace), mkIOKey(BeginClose), mkIOKey(BeginEndfile),
- mkIOKey(BeginExternalFormattedInput), mkIOKey(BeginExternalFormattedOutput),
- mkIOKey(BeginExternalListInput), mkIOKey(BeginExternalListOutput),
- mkIOKey(BeginFlush), mkIOKey(BeginInquireFile),
- mkIOKey(BeginInquireIoLength), mkIOKey(BeginInquireUnit),
- mkIOKey(BeginInternalArrayFormattedInput),
- mkIOKey(BeginInternalArrayFormattedOutput),
- mkIOKey(BeginInternalArrayListInput), mkIOKey(BeginInternalArrayListOutput),
- mkIOKey(BeginInternalFormattedInput), mkIOKey(BeginInternalFormattedOutput),
- mkIOKey(BeginInternalListInput), mkIOKey(BeginInternalListOutput),
- mkIOKey(BeginOpenNewUnit), mkIOKey(BeginOpenUnit), mkIOKey(BeginRewind),
- mkIOKey(BeginUnformattedInput), mkIOKey(BeginUnformattedOutput),
- mkIOKey(BeginWait), mkIOKey(BeginWaitAll),
- mkIOKey(CheckUnitNumberInRange64), mkIOKey(CheckUnitNumberInRange128),
- mkIOKey(EnableHandlers), mkIOKey(EndIoStatement),
- mkIOKey(GetAsynchronousId), mkIOKey(GetIoLength), mkIOKey(GetIoMsg),
- mkIOKey(GetNewUnit), mkIOKey(GetSize), mkIOKey(InputAscii),
- mkIOKey(InputComplex32), mkIOKey(InputComplex64), mkIOKey(InputDerivedType),
- mkIOKey(InputDescriptor), mkIOKey(InputInteger), mkIOKey(InputLogical),
- mkIOKey(InputNamelist), mkIOKey(InputReal32), mkIOKey(InputReal64),
- mkIOKey(InquireCharacter), mkIOKey(InquireInteger64),
- mkIOKey(InquireLogical), mkIOKey(InquirePendingId), mkIOKey(OutputAscii),
- mkIOKey(OutputComplex32), mkIOKey(OutputComplex64),
- mkIOKey(OutputDerivedType), mkIOKey(OutputDescriptor),
- mkIOKey(OutputInteger8), mkIOKey(OutputInteger16), mkIOKey(OutputInteger32),
- mkIOKey(OutputInteger64), mkIOKey(OutputInteger128), mkIOKey(OutputLogical),
- mkIOKey(OutputNamelist), mkIOKey(OutputReal32), mkIOKey(OutputReal64),
- mkIOKey(SetAccess), mkIOKey(SetAction), mkIOKey(SetAdvance),
- mkIOKey(SetAsynchronous), mkIOKey(SetBlank), mkIOKey(SetCarriagecontrol),
- mkIOKey(SetConvert), mkIOKey(SetDecimal), mkIOKey(SetDelim),
- mkIOKey(SetEncoding), mkIOKey(SetFile), mkIOKey(SetForm),
- mkIOKey(SetLeadingZero), mkIOKey(SetPad), mkIOKey(SetPos),
- mkIOKey(SetPosition), mkIOKey(SetRec), mkIOKey(SetRecl), mkIOKey(SetRound),
- mkIOKey(SetSign), mkIOKey(SetStatus)>
- newIOTable;
-} // namespace Fortran::lower
-
namespace {
/// IO statements may require exceptional condition handling. A statement that
/// encounters an exceptional condition may branch to a label given on an ERR
@@ -124,20 +80,6 @@ static void genIoLoop(Fortran::lower::AbstractConverter &converter,
bool isFormatted, bool checkResult, mlir::Value &ok,
bool inLoop);
-/// Helper function to retrieve the name of the IO function given the key `A`
-template <typename A>
-[[maybe_unused]] static constexpr const char *getName() {
- return std::get<A>(Fortran::lower::newIOTable).name;
-}
-
-/// Helper function to retrieve the type model signature builder of the IO
-/// function as defined by the key `A`
-template <typename A>
-[[maybe_unused]] static constexpr fir::runtime::FuncTypeBuilderFunc
-getTypeModel() {
- return std::get<A>(Fortran::lower::newIOTable).getTypeModel();
-}
-
inline int64_t getLength(mlir::Type argTy) {
return mlir::cast<fir::SequenceType>(argTy).getShape()[0];
}
diff --git a/flang/lib/Semantics/openmp-utils.cpp b/flang/lib/Semantics/openmp-utils.cpp
index d227259f94f71..a17350ec8accb 100644
--- a/flang/lib/Semantics/openmp-utils.cpp
+++ b/flang/lib/Semantics/openmp-utils.cpp
@@ -463,16 +463,6 @@ struct ContiguousHelper {
ContiguousHelper(SemanticsContext &context)
: fctx_(context.foldingContext()) {}
- template <typename Contained>
- [[maybe_unused]] std::optional<bool> Visit(
- const common::Indirection<Contained> &x) {
- return Visit(x.value());
- }
- template <typename Contained>
- [[maybe_unused]] std::optional<bool> Visit(
- const common::Reference<Contained> &x) {
- return Visit(x.get());
- }
template <typename T> std::optional<bool> Visit(const evaluate::Expr<T> &x) {
return common::visit([&](auto &&s) { return Visit(s); }, x.u);
}
More information about the flang-commits
mailing list