[flang-commits] [flang] b656189 - [flang][msvc] Avoid ReferenceVariantBase ctor ambiguity. NFC.
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Wed Sep 30 18:54:18 PDT 2020
Author: Michael Kruse
Date: 2020-09-30T20:54:09-05:00
New Revision: b656189e6a602aaf86714ccbf89d94f2ef05b644
URL: https://github.com/llvm/llvm-project/commit/b656189e6a602aaf86714ccbf89d94f2ef05b644
DIFF: https://github.com/llvm/llvm-project/commit/b656189e6a602aaf86714ccbf89d94f2ef05b644.diff
LOG: [flang][msvc] Avoid ReferenceVariantBase ctor ambiguity. NFC.
Msvc reports the following error when a ReferenceVariantBase is constructed using an r-value reference or instantiated as std::vector template parameter. The error message is:
```
PFTBuilder.h(59,1): error C2665: 'std::variant<...>::variant': none of the 2 overloads could convert all the argument types
variant(1248,1): message : could be 'std::variant<...>::variant(std::variant<...> &&) noexcept(false)'
variant(1248,1): message : or 'std::variant<...>::variant(const std::variant<...> &) noexcept(false)'
PFTBuilder.h(59,1): message : while trying to match the argument list '(common::Reference<lower::pft::ReferenceVariantBase<false,...>>)'
```
Work around the ambiguity by only taking `common::Reference` arguments in the constructor. That is, conversion to common::Reference has to be done be the caller instead of being done inside the ctor. Unfortunately, with this change clang/gcc (but not msvc) insist on that the ReferenceVariantBase is stored in a `std::initializer_list`-initialized variable before being used, like being passed to a function or returned.
This patch is part of the series to make flang compilable with MS Visual Studio <http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html>.
Reviewed By: DavidTruby
Differential Revision: https://reviews.llvm.org/D88109
Added:
Modified:
flang/include/flang/Lower/PFTBuilder.h
flang/lib/Lower/PFTBuilder.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 3230d36e0e9a..044e6084330f 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -55,8 +55,9 @@ class ReferenceVariantBase {
using Ref = common::Reference<BaseType<B>>;
ReferenceVariantBase() = delete;
- template <typename B>
- ReferenceVariantBase(B &b) : u{Ref<B>{b}} {}
+ ReferenceVariantBase(std::variant<Ref<A>...> b) : u(b) {}
+ template <typename T>
+ ReferenceVariantBase(Ref<T> b) : u(b) {}
template <typename B>
constexpr BaseType<B> &get() const {
diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index 7195086d8e3f..349f76ee80ac 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -64,8 +64,11 @@ struct UnwrapStmt<parser::UnlabeledStatement<A>> {
class PFTBuilder {
public:
PFTBuilder(const semantics::SemanticsContext &semanticsContext)
- : pgm{std::make_unique<lower::pft::Program>()},
- parentVariantStack{*pgm.get()}, semanticsContext{semanticsContext} {}
+ : pgm{std::make_unique<lower::pft::Program>()}, semanticsContext{
+ semanticsContext} {
+ lower::pft::ParentVariant parent{*pgm.get()};
+ parentVariantStack.push_back(parent);
+ }
/// Get the result
std::unique_ptr<lower::pft::Program> result() { return std::move(pgm); }
@@ -905,11 +908,15 @@ class PFTDumper {
template <typename A, typename T>
static lower::pft::FunctionLikeUnit::FunctionStatement
getFunctionStmt(const T &func) {
- return std::get<parser::Statement<A>>(func.t);
+ lower::pft::FunctionLikeUnit::FunctionStatement result{
+ std::get<parser::Statement<A>>(func.t)};
+ return result;
}
template <typename A, typename T>
static lower::pft::ModuleLikeUnit::ModuleStatement getModuleStmt(const T &mod) {
- return std::get<parser::Statement<A>>(mod.t);
+ lower::pft::ModuleLikeUnit::ModuleStatement result{
+ std::get<parser::Statement<A>>(mod.t)};
+ return result;
}
static const semantics::Symbol *getSymbol(
@@ -1078,7 +1085,8 @@ Fortran::lower::pft::FunctionLikeUnit::FunctionLikeUnit(
const auto &ps{
std::get<std::optional<parser::Statement<parser::ProgramStmt>>>(func.t)};
if (ps.has_value()) {
- beginStmt = ps.value();
+ FunctionStatement begin{ps.value()};
+ beginStmt = begin;
symbol = getSymbol(beginStmt);
processSymbolTable(*symbol->scope());
} else {
More information about the flang-commits
mailing list