[flang] Retain no-op default: cases when compiling with gcc

Original-commit: flang-compiler/f18@8ebfd8d2e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/774
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-10-02 14:24:44 -07:00
parent 637b933202
commit 5c35f3288a
7 changed files with 25 additions and 5 deletions

View File

@ -74,6 +74,16 @@ template<typename... LAMBDAS> visitors(LAMBDAS... x)->visitors<LAMBDAS...>;
// For switch statements without default: labels.
#define CRASH_NO_CASE DIE("no case")
// 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.
#if __clang__
#define SWITCH_COVERS_ALL_CASES
#else
#define SWITCH_COVERS_ALL_CASES \
default: CRASH_NO_CASE; \
#endif
// For cheap assertions that should be applied in production.
// To disable, compile with '-DCHECK=(void)'
#ifndef CHECK

View File

@ -122,7 +122,9 @@ template<> EncodedCharacter EncodeCharacter<Encoding::UTF_8>(char32_t ucs) {
EncodedCharacter EncodeCharacter(Encoding encoding, char32_t ucs) {
switch (encoding) {
case Encoding::LATIN_1: return EncodeCharacter<Encoding::LATIN_1>(ucs);
case Encoding::UTF_8: return EncodeCharacter<Encoding::UTF_8>(ucs);
case Encoding::UTF_8:
return EncodeCharacter<Encoding::UTF_8>(ucs);
SWITCH_COVERS_ALL_CASES
}
}
@ -254,6 +256,7 @@ DecodedCharacter DecodeCharacter(Encoding encoding, const char *cp,
return DecodeCharacter<Encoding::LATIN_1>(cp, bytes, backslashEscapes);
case Encoding::UTF_8:
return DecodeCharacter<Encoding::UTF_8>(cp, bytes, backslashEscapes);
SWITCH_COVERS_ALL_CASES
}
}

View File

@ -128,6 +128,7 @@ common::IfNoLvalue<MaybeExpr, WRAPPED> TypedWrapper(
dyType.kind(), std::move(x));
case TypeCategory::Derived:
return AsGenericExpr(Expr<SomeDerived>{WRAPPER<SomeDerived>{std::move(x)}});
SWITCH_COVERS_ALL_CASES
}
}

View File

@ -193,7 +193,9 @@ 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;
case IntrinsicOperator::NEQV:
return GenericKind::OpNEQV;
SWITCH_COVERS_ALL_CASES
}
}

View File

@ -4824,7 +4824,7 @@ const DeclTypeSpec &ConstructVisitor::ToDeclTypeSpec(
);
}
case common::TypeCategory::Character: CRASH_NO_CASE;
case common::TypeCategory::Character: CRASH_NO_CASE; SWITCH_COVERS_ALL_CASES
}
}
@ -5730,6 +5730,7 @@ 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
}
}

View File

@ -215,7 +215,9 @@ bool Scope::CanImport(const SourceName &name) const {
case ImportKind::None: return false;
case ImportKind::All:
case ImportKind::Default: return true;
case ImportKind::Only: return importNames_.count(name) > 0;
case ImportKind::Only:
return importNames_.count(name) > 0;
SWITCH_COVERS_ALL_CASES
}
}

View File

@ -166,6 +166,7 @@ std::string ParamValue::AsFortran() const {
} else {
return "";
}
SWITCH_COVERS_ALL_CASES
}
}
@ -251,7 +252,7 @@ std::string DeclTypeSpec::AsFortran() const {
case TypeDerived: return "TYPE(" + derivedTypeSpec().AsFortran() + ')';
case ClassDerived: return "CLASS(" + derivedTypeSpec().AsFortran() + ')';
case TypeStar: return "TYPE(*)";
case ClassStar: return "CLASS(*)";
case ClassStar: return "CLASS(*)"; SWITCH_COVERS_ALL_CASES
}
}