[flang] Fixes for building with clang++ and other misc. from review
authorEric Schweitz <eschweitz@nvidia.com>
Wed, 20 Feb 2019 16:57:05 +0000 (08:57 -0800)
committerEric Schweitz <eschweitz@nvidia.com>
Mon, 11 Mar 2019 15:56:36 +0000 (08:56 -0700)
Original-commit: flang-compiler/f18@c3cdc327863036213dab26abf9e97f23a968c197
Reviewed-on: https://github.com/flang-compiler/f18/pull/319
Tree-same-pre-rewrite: false

12 files changed:
flang/lib/FIR/afforestation.cc
flang/lib/FIR/afforestation.h
flang/lib/FIR/builder.h
flang/lib/FIR/common.h
flang/lib/FIR/graph-writer.h
flang/lib/FIR/mixin.h
flang/lib/FIR/procedure.h
flang/lib/FIR/program.h
flang/lib/FIR/statement.def
flang/lib/FIR/statements.cc
flang/lib/FIR/statements.h
flang/lib/FIR/stmt.h

index 1934673..5d114fc 100644 (file)
@@ -240,6 +240,7 @@ std::tuple<const parser::Name *, LinearLabelRef, LinearLabelRef> FindStack(
   SEMANTICS_FAILED("construct name not on stack");
   return {};
 }
+
 template<typename T> parser::Label GetErr(const T &stmt) {
   if constexpr (std::is_same_v<T, parser::ReadStmt> ||
       std::is_same_v<T, parser::WriteStmt>) {
@@ -271,6 +272,7 @@ template<typename T> parser::Label GetErr(const T &stmt) {
   }
   return 0;
 }
+
 template<typename T> parser::Label GetEor(const T &stmt) {
   if constexpr (std::is_same_v<T, parser::ReadStmt> ||
       std::is_same_v<T, parser::WriteStmt>) {
@@ -289,6 +291,7 @@ template<typename T> parser::Label GetEor(const T &stmt) {
   }
   return 0;
 }
+
 template<typename T> parser::Label GetEnd(const T &stmt) {
   if constexpr (std::is_same_v<T, parser::ReadStmt> ||
       std::is_same_v<T, parser::WriteStmt>) {
@@ -307,6 +310,7 @@ template<typename T> parser::Label GetEnd(const T &stmt) {
   }
   return 0;
 }
+
 template<typename T>
 void errLabelSpec(const T &s, std::list<LinearOp> &ops,
     const parser::Statement<parser::ActionStmt> &ec, AnalysisData &ad) {
@@ -319,6 +323,7 @@ void errLabelSpec(const T &s, std::list<LinearOp> &ops,
     ops.emplace_back(LinearAction{ec});
   }
 }
+
 template<typename T>
 void threeLabelSpec(const T &s, std::list<LinearOp> &ops,
     const parser::Statement<parser::ActionStmt> &ec, AnalysisData &ad) {
@@ -339,6 +344,7 @@ void threeLabelSpec(const T &s, std::list<LinearOp> &ops,
     ops.emplace_back(LinearAction{ec});
   }
 }
+
 template<typename T>
 std::vector<LinearLabelRef> toLabelRef(AnalysisData &ad, const T &labels) {
   std::vector<LinearLabelRef> result;
@@ -523,12 +529,14 @@ Evaluation GetSwitchCaseSelector(const parser::CaseConstruct *caseConstruct) {
           .statement.t)
                         .thing.typedExpr.get()};
 }
+
 template<typename STMTTYPE, typename CT>
 const std::optional<parser::Name> &GetSwitchAssociateName(
     const CT *selectConstruct) {
   return std::get<1>(
       std::get<parser::Statement<STMTTYPE>>(selectConstruct->t).statement.t);
 }
+
 template<typename CONSTRUCT, typename GSF>
 void DumpSwitchWithSelector(
     const CONSTRUCT *construct, char const *const name, GSF getSelector) {
@@ -845,9 +853,10 @@ struct SwitchTypeArguments {
 };
 
 template<typename T>
-static bool IsDefault(const typename T::ValueType &valueType) {
+bool IsDefault(const typename T::ValueType &valueType) {
   return std::holds_alternative<typename T::Default>(valueType);
 }
+
 template<typename T>
 void cleanupSwitchPairs(LinearLabelRef &defLab,
     std::vector<typename T::ValueType> &values,
@@ -908,6 +917,7 @@ static std::vector<SwitchCaseStmt::ValueType> populateSwitchValues(
   }
   return result;
 }
+
 static std::vector<SwitchRankStmt::ValueType> populateSwitchValues(
     const std::list<parser::SelectRankConstruct::RankCase> &list) {
   std::vector<SwitchRankStmt::ValueType> result;
@@ -932,6 +942,7 @@ static std::vector<SwitchRankStmt::ValueType> populateSwitchValues(
   }
   return result;
 }
+
 static std::vector<SwitchTypeStmt::ValueType> populateSwitchValues(
     const std::list<parser::SelectTypeConstruct::TypeCase> &list) {
   std::vector<SwitchTypeStmt::ValueType> result;
@@ -1036,6 +1047,7 @@ const T *FindReadWriteSpecifier(
   }
   return nullptr;
 }
+
 const parser::IoUnit *FindReadWriteIoUnit(
     const std::optional<parser::IoUnit> &ioUnit,
     const std::list<parser::IoControlSpec> &specifiers) {
@@ -1142,7 +1154,9 @@ struct FortranIRLowering {
   ~FortranIRLowering() { CHECK(!builder_); }
 
   template<typename A> constexpr bool Pre(const A &) { return true; }
+
   template<typename A> constexpr void Post(const A &) {}
+
   void Post(const parser::MainProgram &mainp) {
     std::string mainName{"_MAIN"s};
     if (auto &ps{
@@ -1168,6 +1182,7 @@ struct FortranIRLowering {
   }
 
   Program *program() { return fir_; }
+
   template<typename T>
   void ProcessRoutine(const T &here, const std::string &name) {
     CHECK(!fir_->containsProcedure(name));
@@ -1853,6 +1868,7 @@ struct FortranIRLowering {
           falseBlock, _1));
     }
   }
+
   template<typename SWITCHTYPE, typename F>
   void AddOrQueueSwitch(const Evaluation &condition,
       LinearLabelRef defaultLabel,
index 3906665..4b89c36 100644 (file)
@@ -18,7 +18,7 @@
 #include <string>
 
 namespace Fortran::parser {
-class Program;
+struct Program;
 }
 
 namespace Fortran::semantics {
@@ -34,4 +34,4 @@ Program *CreateFortranIR(const parser::Program &program,
     semantics::SemanticsContext &semanticsContext, bool debugLinearIR = false);
 }
 
-#endif
+#endif  // FORTRAN_FIR_AFFORESTATION_H_
index fc653df..c962dac 100644 (file)
@@ -68,7 +68,7 @@ struct FIRBuilder {
     return Insert(DeallocateStmt::Create(object));
   }
   template<typename A> Statement &CreateExpr(const A *a) {
-    return Insert(ExprStmt::Create(a));
+    return Insert(ApplyExprStmt::Create(a));
   }
   Statement &CreateIOCall(
       InputOutputCallType call, IOCallArguments &&arguments) {
index e99af2d..e426ed0 100644 (file)
@@ -39,8 +39,8 @@
 namespace Fortran::FIR {
 class Statement;
 class BasicBlock;
-struct Program;
-struct GraphWriter;
+class Program;
+class GraphWriter;
 
 struct Attribute {
   enum { IntentIn, IntentOut, IntentInOut } attribute;
index bf380f9..14bea2a 100644 (file)
@@ -26,7 +26,8 @@
 
 namespace Fortran::FIR {
 
-struct GraphWriter {
+class GraphWriter {
+public:
   static void setOutput(llvm::raw_ostream *output) { defaultOutput_ = output; }
   static void setOutput(const std::string &filename) {
     std::error_code ec;
index 763bd33..bde2895 100644 (file)
 
 namespace Fortran::FIR {
 
+inline constexpr bool has_size(std::size_t size) { return size > 0; }
+
 template<typename T, typename E = void> struct SumTypeMixin {};
 template<typename T>  // T must be std::variant<...>
-struct SumTypeMixin<T, std::enable_if_t<std::variant_size_v<T>>> {
+struct SumTypeMixin<T, std::enable_if_t<has_size(std::variant_size_v<T>)>> {
   template<typename A> SumTypeMixin(A &&x) : u{std::move(x)} {}
   using SumTypeTrait = std::true_type;
   SumTypeMixin(SumTypeMixin &&) = default;
@@ -38,7 +40,9 @@ struct SumTypeMixin<T, std::enable_if_t<std::variant_size_v<T>>> {
 
 template<typename T, typename E = void> struct SumTypeCopyMixin {};
 template<typename T>  // T must be std::variant<...>
-struct SumTypeCopyMixin<T, std::enable_if_t<std::variant_size_v<T>>> {
+struct SumTypeCopyMixin<T, std::enable_if_t<has_size(std::variant_size_v<T>)>> {
+  template<typename A> SumTypeCopyMixin(A &&x) : u{std::move(x)} {}
+  template<typename A> SumTypeCopyMixin(const A &x) : u{x} {}
   using CopyableSumTypeTrait = std::true_type;
   SumTypeCopyMixin(SumTypeCopyMixin &&) = default;
   SumTypeCopyMixin &operator=(SumTypeCopyMixin &&) = default;
@@ -47,16 +51,16 @@ struct SumTypeCopyMixin<T, std::enable_if_t<std::variant_size_v<T>>> {
   SumTypeCopyMixin() = delete;
   T u;
 };
-#define SUM_TYPE_COPY_MIXIN(Derived) \
-  Derived(const Derived &derived) : SumTypeCopyMixin(derived) {} \
-  Derived &operator=(const Derived &derived) { \
-    SumTypeCopyMixin::operator=(derived); \
+#define SUM_TYPE_COPY_MIXIN(DT) \
+  DT(const DT &derived) : SumTypeCopyMixin(derived.u) {} \
+  DT &operator=(const DT &derived) { \
+    SumTypeCopyMixin::operator=(derived.u); \
     return *this; \
   }
 
 template<typename T, typename E = void> struct ProductTypeMixin {};
 template<typename T>  // T must be std::tuple<...>
-struct ProductTypeMixin<T, std::enable_if_t<std::tuple_size_v<T>>> {
+struct ProductTypeMixin<T, std::enable_if_t<has_size(std::tuple_size_v<T>)>> {
   template<typename A> ProductTypeMixin(A &&x) : t{std::move(x)} {}
   using ProductTypeTrait = std::true_type;
   ProductTypeMixin(ProductTypeMixin &&) = default;
index 750573c..043c937 100644 (file)
@@ -25,7 +25,7 @@ namespace Fortran::FIR {
 
 class Program;
 class Region;
-struct GraphWriter;
+class GraphWriter;
 
 class Procedure final : public llvm::ilist_node<Procedure>,
                         public ChildMixin<Procedure, Program> {
index b9022f3..d40853c 100644 (file)
@@ -26,7 +26,7 @@
 namespace Fortran::FIR {
 
 class Procedure;
-struct GraphWriter;
+class GraphWriter;
 
 class Program final {
 public:
index 7a24b64..713fc85 100644 (file)
 #define LAST_TERM_STMT(num)
 #endif
 
-#ifndef FIRST_BINARY_STMT
-#define FIRST_BINARY_STMT(num)
+#ifndef FIRST_COMPUTE_STMT
+#define FIRST_COMPUTE_STMT(num)
 #endif
-#ifndef HANDLE_BINARY_STMT
+#ifndef HANDLE_COMPUTE_STMT
 #ifndef HANDLE_STMT
-#define HANDLE_BINARY_STMT(num, opcode, instclass)
+#define HANDLE_COMPUTE_STMT(num, opcode, instclass)
 #else
-#define HANDLE_BINARY_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
+#define HANDLE_COMPUTE_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
 #endif
 #endif
-#ifndef LAST_BINARY_STMT
-#define LAST_BINARY_STMT(num)
+#ifndef LAST_COMPUTE_STMT
+#define LAST_COMPUTE_STMT(num)
 #endif
 
 #ifndef FIRST_MEMORY_STMT
@@ -116,12 +116,12 @@ LAST_TERM_STMT(8)
 
 // Standard actions - These instructions capture computations as
 // evaluate::expressions
-FIRST_BINARY_STMT(9)
-HANDLE_BINARY_STMT(9,  Assign,    AssignmentStmt)
-HANDLE_BINARY_STMT(10, PtrAssign, PointerAssignStmt)
-HANDLE_BINARY_STMT(11, LblAssign, LabelAssignStmt)
-HANDLE_BINARY_STMT(12, Expr,      ExprStmt)
-LAST_BINARY_STMT(12)
+FIRST_COMPUTE_STMT(9)
+HANDLE_COMPUTE_STMT(9,  Assign,    AssignmentStmt)
+HANDLE_COMPUTE_STMT(10, PtrAssign, PointerAssignStmt)
+HANDLE_COMPUTE_STMT(11, LblAssign, LabelAssignStmt)
+HANDLE_COMPUTE_STMT(12, ApplyExpr, ApplyExprStmt)
+LAST_COMPUTE_STMT(12)
 
 // Memory operators - These instructions capture ALLOCATE and DEALLOCATE
 // Fortran statements
@@ -148,9 +148,9 @@ LAST_OTHER_STMT(24)
 #undef HANDLE_TERM_STMT
 #undef LAST_TERM_STMT
 
-#undef FIRST_BINARY_STMT
-#undef HANDLE_BINARY_STMT
-#undef LAST_BINARY_STMT
+#undef FIRST_COMPUTE_STMT
+#undef HANDLE_COMPUTE_STMT
+#undef LAST_COMPUTE_STMT
 
 #undef FIRST_MEMORY_STMT
 #undef HANDLE_MEMORY_STMT
index afc3816..f2e29cc 100644 (file)
@@ -191,7 +191,7 @@ std::string Statement::dump() const {
           },
           [](const LabelAssignStmt &) { return "lblassn"s; },
           [](const DisassociateStmt &) { return "NULLIFY"s; },
-          [](const ExprStmt &expressionStatement) {
+          [](const ApplyExprStmt &applyExpression) {
             return std::visit(
                 common::visitors{
                     [](const parser::AssociateStmt *) {
@@ -215,7 +215,7 @@ std::string Statement::dump() const {
                       return FIR::dump(genericExpressionWrapper);
                     },
                 },
-                expressionStatement.u);
+                applyExpression.u);
           },
           [](const ScopeEnterStmt &) { return "scopeenter"s; },
           [](const ScopeExitStmt &) { return "scopeexit"s; },
index 01f6f19..8005259 100644 (file)
@@ -25,17 +25,17 @@ namespace Fortran::FIR {
 #define HANDLE_STMT(num, opcode, name) struct name;
 #include "statement.def"
 
-struct Statement;
+class Statement;
 
 CLASS_TRAIT(StatementTrait)
 CLASS_TRAIT(TerminatorTrait)
 CLASS_TRAIT(ActionTrait)
 
-struct Evaluation
-  : public SumTypeCopyMixin<std::variant<Expression *, Variable *,
-        PathVariable *, const semantics::Symbol *>> {
+class Evaluation : public SumTypeCopyMixin<std::variant<Expression *,
+                       Variable *, PathVariable *, const semantics::Symbol *>> {
+public:
   SUM_TYPE_COPY_MIXIN(Evaluation)
-  Evaluation(PathVariable *pv) : SumTypeCopyMixin{pv} {
+  Evaluation(PathVariable *pv) : SumTypeCopyMixin(pv) {
     if (const auto *designator{
             std::get_if<common::Indirection<parser::Designator>>(&pv->u)}) {
       if (const auto *obj{std::get_if<parser::ObjectName>(&(*designator)->u)}) {
@@ -358,17 +358,18 @@ private:
 };
 
 /// expressions that must be evaluated in various statements
-struct ExprStmt
+struct ApplyExprStmt
   : public ActionStmt_impl,
     public SumTypeCopyMixin<std::variant<const parser::AssociateStmt *,
         const parser::ChangeTeamStmt *, const parser::NonLabelDoStmt *,
         const parser::ForallConstructStmt *, const Expression *>> {
-  template<typename T> static ExprStmt Create(const T *e) {
-    return ExprStmt{e};
+  template<typename T> static ApplyExprStmt Create(const T *e) {
+    return ApplyExprStmt{e};
   }
 
 private:
-  template<typename T> explicit ExprStmt(const T *e) : SumTypeCopyMixin{e} {}
+  template<typename T>
+  explicit ApplyExprStmt(const T *e) : SumTypeCopyMixin{e} {}
   // Evaluation evaluation_;
 };
 
index 7ba99fa..5a33145 100644 (file)
 namespace Fortran::FIR {
 
 /// Sum type over all statement classes
-struct Statement : public SumTypeMixin<std::variant<
+class Statement : public SumTypeMixin<std::variant<
 #define HANDLE_STMT(num, opcode, name) name,
 #define HANDLE_LAST_STMT(num, opcode, name) name
 #include "statement.def"
-                       >>,
-                   public ChildMixin<Statement, BasicBlock>,
-                   public llvm::ilist_node<Statement> {
+                      >>,
+                  public ChildMixin<Statement, BasicBlock>,
+                  public llvm::ilist_node<Statement> {
+public:
   template<typename A>
   Statement(BasicBlock *p, A &&t) : SumTypeMixin{t}, ChildMixin{p} {
     parent->insertBefore(this);