From e5f70fa778e0f4abcb4b9dd7b0ef3035d243b208 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Mon, 1 Dec 2025 16:11:07 -0800 Subject: [PATCH] [flang][runtime] Clean up C++ style & usage A recent patch to descriptor.cpp added some code whose style isn't conforming with the rest of the file (or the runtime). We always use braces around initializations and nested statements, and don't indent "case" lines any more than their "switch". Further, it dumps a rank 0 descriptor as just "scalar", which is fine as an interpretation of the rank but should not entirely replace the rank in the dump output. --- flang-rt/lib/runtime/descriptor.cpp | 33 +++++++++-------------- flang-rt/unittests/Runtime/Descriptor.cpp | 4 +-- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/flang-rt/lib/runtime/descriptor.cpp b/flang-rt/lib/runtime/descriptor.cpp index 066e94232c003..75bea976e2087 100644 --- a/flang-rt/lib/runtime/descriptor.cpp +++ b/flang-rt/lib/runtime/descriptor.cpp @@ -347,23 +347,21 @@ static const char *GetTypeStr(ISO::CFI_type_t type, bool dumpRawType) { CASE(CFI_type_uint32_t) CASE(CFI_type_uint64_t) CASE(CFI_type_uint128_t) + default: + return nullptr; } #undef CASE - return nullptr; } TypeCode code{type}; - - if (!code.IsValid()) + if (!code.IsValid()) { return "invalid"; - - common::optional> categoryAndKind = - code.GetCategoryAndKind(); - if (!categoryAndKind) + } + auto categoryAndKind{code.GetCategoryAndKind()}; + if (!categoryAndKind) { return nullptr; - - TypeCategory tcat; - int kind; - std::tie(tcat, kind) = *categoryAndKind; + } + TypeCategory tcat{categoryAndKind->first}; + int kind{categoryAndKind->second}; #define CASE(cat, k) \ case (k): \ @@ -434,18 +432,14 @@ void Descriptor::Dump(FILE *f, bool dumpRawType) const { std::fprintf(f, " base_addr %p\n", raw_.base_addr); std::fprintf(f, " elem_len %zd\n", ElementBytes()); std::fprintf(f, " version %d\n", static_cast(raw_.version)); - if (rank() > 0) { - std::fprintf(f, " rank %d\n", rank()); - } else { - std::fprintf(f, " scalar\n"); - } - int ty = static_cast(raw_.type); - if (const char *tyStr = GetTypeStr(raw_.type, dumpRawType)) { + std::fprintf(f, " rank %d%s\n", rank(), rank() ? "" : " (scalar)"); + int ty{static_cast(raw_.type)}; + if (const char *tyStr{GetTypeStr(raw_.type, dumpRawType)}) { std::fprintf(f, " type %d \"%s\"\n", ty, tyStr); } else { std::fprintf(f, " type %d\n", ty); } - int attr = static_cast(raw_.attribute); + int attr{static_cast(raw_.attribute)}; if (IsPointer()) { std::fprintf(f, " attribute %d (pointer) \n", attr); } else if (IsAllocatable()) { @@ -453,7 +447,6 @@ void Descriptor::Dump(FILE *f, bool dumpRawType) const { } else { std::fprintf(f, " attribute %d\n", attr); } - std::fprintf(f, " extra %d\n", static_cast(raw_.extra)); std::fprintf(f, " addendum %d\n", static_cast(HasAddendum())); std::fprintf(f, " alloc_idx %d\n", static_cast(GetAllocIdx())); diff --git a/flang-rt/unittests/Runtime/Descriptor.cpp b/flang-rt/unittests/Runtime/Descriptor.cpp index f86ff4cf16a55..6dcd5b8814afe 100644 --- a/flang-rt/unittests/Runtime/Descriptor.cpp +++ b/flang-rt/unittests/Runtime/Descriptor.cpp @@ -197,7 +197,7 @@ TEST(Descriptor, Dump) { " base_addr [address]\n" " elem_len 4\n" " version 20240719\n" - " scalar\n" + " rank 0 (scalar)\n" " type 9 \"INTEGER(kind=4)\"\n" " attribute 0\n" " extra 0\n" @@ -207,7 +207,7 @@ TEST(Descriptor, Dump) { " base_addr [address]\n" " elem_len 4\n" " version 20240719\n" - " scalar\n" + " rank 0 (scalar)\n" " type 9 \"CFI_type_int32_t\"\n" " attribute 0\n" " extra 0\n"