[flang-commits] [flang] b3c1f53 - [flang] Recode a switch() to dodge a sketchy warning

peter klausler via flang-commits flang-commits at lists.llvm.org
Fri Jun 18 16:58:54 PDT 2021


Author: peter klausler
Date: 2021-06-18T16:58:44-07:00
New Revision: b3c1f53c989f6aefad581955e3add222cfb5d890

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

LOG: [flang] Recode a switch() to dodge a sketchy warning

One of the buildbots uses a compiler (can't tell which) that
doesn't approve of a "default:" in a switch statement whose
cases appear to completely cover all possible values of an
enum class.  But this switch is in raw data dumping code that
needs to allow for incorrect values in memory.  So rewrite it
as a cascade of if statements; performance doesn't matter here.

Added: 
    

Modified: 
    flang/runtime/type-info.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/type-info.cpp b/flang/runtime/type-info.cpp
index ef3c4724fa00..df72fc466a29 100644
--- a/flang/runtime/type-info.cpp
+++ b/flang/runtime/type-info.cpp
@@ -158,22 +158,16 @@ FILE *Component::Dump(FILE *f) const {
   std::fprintf(f, "Component @ 0x%p:\n", reinterpret_cast<const void *>(this));
   std::fputs("    name: ", f);
   DumpScalarCharacter(f, name(), "Component::name");
-  switch (genre_) {
-  case Genre::Data:
+  if (genre_ == Genre::Data) {
     std::fputs("    Data       ", f);
-    break;
-  case Genre::Pointer:
+  } else if (genre_ == Genre::Pointer) {
     std::fputs("    Pointer    ", f);
-    break;
-  case Genre::Allocatable:
+  } else if (genre_ == Genre::Allocatable) {
     std::fputs("    Allocatable", f);
-    break;
-  case Genre::Automatic:
+  } else if (genre_ == Genre::Automatic) {
     std::fputs("    Automatic  ", f);
-    break;
-  default:
+  } else {
     std::fprintf(f, "    (bad genre 0x%x)", static_cast<int>(genre_));
-    break;
   }
   std::fprintf(f, " category %d  kind %d  rank %d  offset 0x%zx\n", category_,
       kind_, rank_, static_cast<std::size_t>(offset_));


        


More information about the flang-commits mailing list