[flang-commits] [flang] 27004e0 - [flang] Fix build warning

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Feb 1 14:08:57 PST 2023


Author: Peter Klausler
Date: 2023-02-01T14:08:02-08:00
New Revision: 27004e027312a59e3b6645f5df58e97c2a2da6ef

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

LOG: [flang] Fix build warning

It's basically impossible to write a switch statement with a case
for every enumerator in an enum class if the cases each have a
return statement and get it to compile without warnings for all
of our build compilers & versions.  Rewrite as a sequence of
if statements.

Added: 
    

Modified: 
    flang/lib/Evaluate/check-expression.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 6cf1f8504708..12ffdc9b0a19 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -494,20 +494,23 @@ static bool IsPermissibleInquiry(const semantics::Symbol &firstSymbol,
     return true;
   }
   // Inquiries on local objects may not access a deferred bound or length.
+  // (This code used to be a switch, but it proved impossible to write it
+  // thus without running afoul of bogus warnings from 
diff erent C++
+  // compilers.)
+  if (field == DescriptorInquiry::Field::Rank) {
+    return true; // always known
+  }
   const auto *object{lastSymbol.detailsIf<semantics::ObjectEntityDetails>()};
-  switch (field) {
-  case DescriptorInquiry::Field::LowerBound:
-  case DescriptorInquiry::Field::Extent:
-  case DescriptorInquiry::Field::Stride:
+  if (field == DescriptorInquiry::Field::LowerBound ||
+      field == DescriptorInquiry::Field::Extent ||
+      field == DescriptorInquiry::Field::Stride) {
     return object && !object->shape().CanBeDeferredShape();
-  case DescriptorInquiry::Field::Rank:
-    return true; // always known
-  case DescriptorInquiry::Field::Len:
+  }
+  if (field == DescriptorInquiry::Field::Len) {
     return object && object->type() &&
         object->type()->category() == semantics::DeclTypeSpec::Character &&
         !object->type()->characterTypeSpec().length().isDeferred();
   }
-  // TODO: Handle non-deferred LEN type parameters of PDTs
   return false;
 }
 


        


More information about the flang-commits mailing list