[flang-commits] [flang] e3b2f1b - [flang] [NFC] Repair build with GCC 7.3

peter klausler via flang-commits flang-commits at lists.llvm.org
Tue Jun 22 13:52:43 PDT 2021


Author: peter klausler
Date: 2021-06-22T13:52:30-07:00
New Revision: e3b2f1b6823f4f06da222545857809e6ee7962b6

URL: https://github.com/llvm/llvm-project/commit/e3b2f1b6823f4f06da222545857809e6ee7962b6
DIFF: https://github.com/llvm/llvm-project/commit/e3b2f1b6823f4f06da222545857809e6ee7962b6.diff

LOG: [flang] [NFC] Repair build with GCC 7.3

Work around two problems with GCC 7.3.
One is its inability to implement "constexpr operator=(...) = default;"
in a class with a std::optional<> component; another is a legitimate-
looking warning about an unused variable.

Differential Revision: https://reviews.llvm.org/D104731

Added: 
    

Modified: 
    flang/include/flang/Evaluate/type.h
    flang/lib/Evaluate/formatting.cpp
    flang/lib/Evaluate/type.cpp
    flang/lib/Semantics/check-declarations.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/type.h b/flang/include/flang/Evaluate/type.h
index 124fb39f7fd6d..6ab09f60789d2 100644
--- a/flang/include/flang/Evaluate/type.h
+++ b/flang/include/flang/Evaluate/type.h
@@ -142,6 +142,11 @@ class DynamicType {
     return charLengthParamValue_;
   }
   constexpr std::optional<std::int64_t> knownLength() const {
+#if !__clang__ && __GNUC__ == 7
+    if (knownLength_ < 0) {
+      return std::nullopt;
+    }
+#endif
     return knownLength_;
   }
   std::optional<Expr<SubscriptInteger>> GetCharLength() const;
@@ -217,7 +222,12 @@ class DynamicType {
   TypeCategory category_{TypeCategory::Derived}; // overridable default
   int kind_{0};
   const semantics::ParamValue *charLengthParamValue_{nullptr};
+#if !__clang__ && __GNUC__ == 7
+  // GCC 7's optional<> lacks a constexpr operator=
+  std::int64_t knownLength_{-1};
+#else
   std::optional<std::int64_t> knownLength_;
+#endif
   const semantics::DerivedTypeSpec *derived_{nullptr}; // TYPE(T), CLASS(T)
 };
 

diff  --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp
index 25ed470a2a92a..5b5ae258d8b0b 100644
--- a/flang/lib/Evaluate/formatting.cpp
+++ b/flang/lib/Evaluate/formatting.cpp
@@ -475,10 +475,10 @@ std::string DynamicType::AsFortran() const {
   if (derived_) {
     CHECK(category_ == TypeCategory::Derived);
     return DerivedTypeSpecAsFortran(*derived_);
-  } else if (charLengthParamValue_ || knownLength_) {
+  } else if (charLengthParamValue_ || knownLength()) {
     std::string result{"CHARACTER(KIND="s + std::to_string(kind_) + ",LEN="};
-    if (knownLength_) {
-      result += std::to_string(*knownLength_) + "_8";
+    if (knownLength()) {
+      result += std::to_string(*knownLength()) + "_8";
     } else if (charLengthParamValue_->isAssumed()) {
       result += '*';
     } else if (charLengthParamValue_->isDeferred()) {

diff  --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index 1c28c56672bf6..22ea3ea27ad29 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -109,15 +109,15 @@ template <typename A> inline bool PointeeComparison(const A *x, const A *y) {
 bool DynamicType::operator==(const DynamicType &that) const {
   return category_ == that.category_ && kind_ == that.kind_ &&
       PointeeComparison(charLengthParamValue_, that.charLengthParamValue_) &&
-      knownLength_.has_value() == that.knownLength_.has_value() &&
-      (!knownLength_ || *knownLength_ == *that.knownLength_) &&
+      knownLength().has_value() == that.knownLength().has_value() &&
+      (!knownLength() || *knownLength() == *that.knownLength()) &&
       PointeeComparison(derived_, that.derived_);
 }
 
 std::optional<Expr<SubscriptInteger>> DynamicType::GetCharLength() const {
   if (category_ == TypeCategory::Character) {
-    if (knownLength_) {
-      return AsExpr(Constant<SubscriptInteger>(*knownLength_));
+    if (knownLength()) {
+      return AsExpr(Constant<SubscriptInteger>(*knownLength()));
     } else if (charLengthParamValue_) {
       if (auto length{charLengthParamValue_->GetExplicit()}) {
         return ConvertToType<SubscriptInteger>(std::move(*length));
@@ -194,7 +194,7 @@ bool DynamicType::IsAssumedLengthCharacter() const {
 bool DynamicType::IsNonConstantLengthCharacter() const {
   if (category_ != TypeCategory::Character) {
     return false;
-  } else if (knownLength_) {
+  } else if (knownLength()) {
     return false;
   } else if (!charLengthParamValue_) {
     return true;

diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index ddf0a011b2f77..5d063f14499a3 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -2209,15 +2209,14 @@ void DistinguishabilityHelper::Check(const Scope &scope) {
   for (const auto &[name, info] : nameToInfo_) {
     auto count{info.size()};
     for (std::size_t i1{0}; i1 < count - 1; ++i1) {
-      const auto &[kind1, symbol1, proc1] = info[i1];
+      const auto &[kind, symbol, proc]{info[i1]};
       for (std::size_t i2{i1 + 1}; i2 < count; ++i2) {
-        const auto &[kind2, symbol2, proc2] = info[i2];
-        auto distinguishable{kind1.IsName()
+        auto distinguishable{kind.IsName()
                 ? evaluate::characteristics::Distinguishable
                 : evaluate::characteristics::DistinguishableOpOrAssign};
-        if (!distinguishable(proc1, proc2)) {
-          SayNotDistinguishable(
-              GetTopLevelUnitContaining(scope), name, kind1, symbol1, symbol2);
+        if (!distinguishable(proc, info[i2].procedure)) {
+          SayNotDistinguishable(GetTopLevelUnitContaining(scope), name, kind,
+              symbol, info[i2].symbol);
         }
       }
     }


        


More information about the flang-commits mailing list