From 4ee37ac356d09ad65cf485765fcdffaefcff5dfe Mon Sep 17 00:00:00 2001 From: peter klausler Date: Wed, 2 Oct 2019 15:48:20 -0700 Subject: [PATCH] [flang] Address review comments Original-commit: flang-compiler/f18@b2a0503614b325c62af920db5a183a2e254994f7 Reviewed-on: https://github.com/flang-compiler/f18/pull/774 Tree-same-pre-rewrite: false --- flang/lib/common/idioms.h | 2 +- flang/lib/parser/characters.cc | 7 +++---- flang/lib/parser/prescan.cc | 2 +- flang/lib/semantics/expression.cc | 2 +- flang/lib/semantics/resolve-names-utils.cc | 5 ++--- flang/lib/semantics/resolve-names.cc | 5 +++-- flang/lib/semantics/scope.cc | 5 ++--- flang/lib/semantics/type.cc | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/flang/lib/common/idioms.h b/flang/lib/common/idioms.h index ae1a6dfb453f..3a24ddd62d5d 100644 --- a/flang/lib/common/idioms.h +++ b/flang/lib/common/idioms.h @@ -76,7 +76,7 @@ template visitors(LAMBDAS... x)->visitors; // For switch statements whose cases have return statements for // all possibilities. Clang emits warnings if the default: is -// present, gcc emits warings if it is absent. +// present, gcc emits warnings if it is absent. #if __clang__ #define SWITCH_COVERS_ALL_CASES #else diff --git a/flang/lib/parser/characters.cc b/flang/lib/parser/characters.cc index 3b14e8af1a3d..8103f818ab38 100644 --- a/flang/lib/parser/characters.cc +++ b/flang/lib/parser/characters.cc @@ -121,10 +121,9 @@ template<> EncodedCharacter EncodeCharacter(char32_t ucs) { EncodedCharacter EncodeCharacter(Encoding encoding, char32_t ucs) { switch (encoding) { - case Encoding::LATIN_1: return EncodeCharacter(ucs); - case Encoding::UTF_8: - return EncodeCharacter(ucs); SWITCH_COVERS_ALL_CASES + case Encoding::LATIN_1: return EncodeCharacter(ucs); + case Encoding::UTF_8: return EncodeCharacter(ucs); } } @@ -252,11 +251,11 @@ template DecodedCharacter DecodeCharacter( DecodedCharacter DecodeCharacter(Encoding encoding, const char *cp, std::size_t bytes, bool backslashEscapes) { switch (encoding) { + SWITCH_COVERS_ALL_CASES case Encoding::LATIN_1: return DecodeCharacter(cp, bytes, backslashEscapes); case Encoding::UTF_8: return DecodeCharacter(cp, bytes, backslashEscapes); - SWITCH_COVERS_ALL_CASES } } diff --git a/flang/lib/parser/prescan.cc b/flang/lib/parser/prescan.cc index bdeada0977b0..5bf3df20d6ff 100644 --- a/flang/lib/parser/prescan.cc +++ b/flang/lib/parser/prescan.cc @@ -58,7 +58,7 @@ static void NormalizeCompilerDirectiveCommentMarker(TokenSequence &dir) { return; } } - CHECK(false && "compiler directive all blank"); + DIE("compiler directive all blank"); } void Prescanner::Prescan(ProvenanceRange range) { diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index 0ccc884c51fa..590727d62181 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -111,6 +111,7 @@ template typename WRAPPER, typename WRAPPED> common::IfNoLvalue TypedWrapper( const DynamicType &dyType, WRAPPED &&x) { switch (dyType.category()) { + SWITCH_COVERS_ALL_CASES case TypeCategory::Integer: return WrapperHelper( dyType.kind(), std::move(x)); @@ -128,7 +129,6 @@ common::IfNoLvalue TypedWrapper( dyType.kind(), std::move(x)); case TypeCategory::Derived: return AsGenericExpr(Expr{WRAPPER{std::move(x)}}); - SWITCH_COVERS_ALL_CASES } } diff --git a/flang/lib/semantics/resolve-names-utils.cc b/flang/lib/semantics/resolve-names-utils.cc index f73367de071d..f220743beb3e 100644 --- a/flang/lib/semantics/resolve-names-utils.cc +++ b/flang/lib/semantics/resolve-names-utils.cc @@ -176,6 +176,7 @@ void GenericSpecInfo::Analyze(const parser::GenericSpec &x) { // parser::DefinedOperator::IntrinsicOperator -> GenericKind static GenericKind MapIntrinsicOperator(IntrinsicOperator op) { switch (op) { + SWITCH_COVERS_ALL_CASES case IntrinsicOperator::Power: return GenericKind::OpPower; case IntrinsicOperator::Multiply: return GenericKind::OpMultiply; case IntrinsicOperator::Divide: return GenericKind::OpDivide; @@ -193,9 +194,7 @@ static GenericKind MapIntrinsicOperator(IntrinsicOperator op) { case IntrinsicOperator::OR: return GenericKind::OpOR; case IntrinsicOperator::XOR: return GenericKind::OpXOR; case IntrinsicOperator::EQV: return GenericKind::OpEQV; - case IntrinsicOperator::NEQV: - return GenericKind::OpNEQV; - SWITCH_COVERS_ALL_CASES + case IntrinsicOperator::NEQV: return GenericKind::OpNEQV; } } diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index f5e8ee06821b..35e9d0a018f4 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -4805,6 +4805,7 @@ void ConstructVisitor::PopAssociation() { const DeclTypeSpec &ConstructVisitor::ToDeclTypeSpec( evaluate::DynamicType &&type) { switch (type.category()) { + SWITCH_COVERS_ALL_CASES case common::TypeCategory::Integer: case common::TypeCategory::Real: case common::TypeCategory::Complex: @@ -4824,7 +4825,7 @@ const DeclTypeSpec &ConstructVisitor::ToDeclTypeSpec( ); } - case common::TypeCategory::Character: CRASH_NO_CASE; SWITCH_COVERS_ALL_CASES + case common::TypeCategory::Character: CRASH_NO_CASE; } } @@ -5718,6 +5719,7 @@ void ResolveNamesVisitor::AddSubpNames(const ProgramTree &node) { // Push a new scope for this node or return false on error. bool ResolveNamesVisitor::BeginScope(const ProgramTree &node) { switch (node.GetKind()) { + SWITCH_COVERS_ALL_CASES case ProgramTree::Kind::Program: PushScope(Scope::Kind::MainProgram, &MakeSymbol(node.name(), MainProgramDetails{})); @@ -5730,7 +5732,6 @@ bool ResolveNamesVisitor::BeginScope(const ProgramTree &node) { case ProgramTree::Kind::Module: BeginModule(node.name(), false); return true; case ProgramTree::Kind::Submodule: return BeginSubmodule(node.name(), node.GetParentId()); - SWITCH_COVERS_ALL_CASES } } diff --git a/flang/lib/semantics/scope.cc b/flang/lib/semantics/scope.cc index c5b00d126807..e62fccc40e4b 100644 --- a/flang/lib/semantics/scope.cc +++ b/flang/lib/semantics/scope.cc @@ -212,12 +212,11 @@ bool Scope::CanImport(const SourceName &name) const { return false; } switch (GetImportKind()) { + SWITCH_COVERS_ALL_CASES case ImportKind::None: return false; case ImportKind::All: case ImportKind::Default: return true; - case ImportKind::Only: - return importNames_.count(name) > 0; - SWITCH_COVERS_ALL_CASES + case ImportKind::Only: return importNames_.count(name) > 0; } } diff --git a/flang/lib/semantics/type.cc b/flang/lib/semantics/type.cc index df691524e878..916e773203c4 100644 --- a/flang/lib/semantics/type.cc +++ b/flang/lib/semantics/type.cc @@ -156,6 +156,7 @@ void ParamValue::SetExplicit(SomeIntExpr &&x) { std::string ParamValue::AsFortran() const { switch (category_) { + SWITCH_COVERS_ALL_CASES case Category::Assumed: return "*"; case Category::Deferred: return ":"; case Category::Explicit: @@ -166,7 +167,6 @@ std::string ParamValue::AsFortran() const { } else { return ""; } - SWITCH_COVERS_ALL_CASES } }