[flang] Enable more warnings, clean them up

Original-commit: flang-compiler/f18@c6b3420e5f
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 12:40:52 -07:00
parent 1c2cb4bfe5
commit 637b933202
16 changed files with 25 additions and 45 deletions

View File

@ -30,6 +30,8 @@ if(BUILD_WITH_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-toolchain=${GCC}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstring-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcovered-switch-default")
endif()
# Set RPATH in every executable, overriding the default setting.

View File

@ -112,8 +112,7 @@ std::optional<A> JoinOptional(std::optional<std::optional<A>> &&x) {
}
// Convert an std::optional to an ordinary pointer
template<typename A>
const A *GetPtrFromOptional(const std::optional<A> &x) {
template<typename A> const A *GetPtrFromOptional(const std::optional<A> &x) {
if (x.has_value()) {
return &*x;
} else {
@ -192,8 +191,8 @@ constexpr bool AreSameType{AreSameTypeHelper<Ts...>::value()};
template<typename> struct TupleToVariantHelper;
template<typename... Ts> struct TupleToVariantHelper<std::tuple<Ts...>> {
static_assert(AreTypesDistinct<Ts...> ||
!"TupleToVariant: types are not pairwise distinct");
static_assert(AreTypesDistinct<Ts...>,
"TupleToVariant: types are not pairwise distinct");
using type = std::variant<Ts...>;
};
template<typename TUPLE>

View File

@ -265,9 +265,10 @@ std::ostream &Operation<D, R, O...>::AsFortran(std::ostream &o) const {
template<typename TO, TypeCategory FROMCAT>
std::ostream &Convert<TO, FROMCAT>::AsFortran(std::ostream &o) const {
static_assert(TO::category == TypeCategory::Integer ||
TO::category == TypeCategory::Real ||
TO::category == TypeCategory::Character ||
TO::category == TypeCategory::Logical || !"Convert<> to bad category!");
TO::category == TypeCategory::Real ||
TO::category == TypeCategory::Character ||
TO::category == TypeCategory::Logical,
"Convert<> to bad category!");
if constexpr (TO::category == TypeCategory::Character) {
this->left().AsFortran(o << "achar(iachar(") << ')';
} else if constexpr (TO::category == TypeCategory::Integer) {

View File

@ -1195,7 +1195,6 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
common::die("INTERNAL: result-only rank code appears on argument '%s' "
"for intrinsic '%s'",
d.keyword, name);
default: CRASH_NO_CASE;
}
if (!argOk) {
messages.Say("'%s=' argument has unacceptable rank %d"_err_en_US,
@ -1354,7 +1353,6 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
case Rank::reduceOperation:
common::die("INTERNAL: bad Rank code on intrinsic '%s' result", name);
break;
default: CRASH_NO_CASE;
}
CHECK(resultRank >= 0);
@ -1764,22 +1762,19 @@ IntrinsicProcTable IntrinsicProcTable::Configure(
}
bool IntrinsicProcTable::IsIntrinsic(const std::string &name) const {
CHECK(impl_ != nullptr || !"IntrinsicProcTable: not configured");
return impl_->IsIntrinsic(name);
return DEREF(impl_).IsIntrinsic(name);
}
std::optional<SpecificCall> IntrinsicProcTable::Probe(
const CallCharacteristics &call, ActualArguments &arguments,
FoldingContext &context) const {
CHECK(impl_ != nullptr || !"IntrinsicProcTable: not configured");
return impl_->Probe(call, arguments, context, *this);
return DEREF(impl_).Probe(call, arguments, context, *this);
}
std::optional<UnrestrictedSpecificIntrinsicFunctionInterface>
IntrinsicProcTable::IsUnrestrictedSpecificIntrinsicFunction(
const std::string &name) const {
CHECK(impl_ != nullptr || !"IntrinsicProcTable: not configured");
return impl_->IsUnrestrictedSpecificIntrinsicFunction(name);
return DEREF(impl_).IsUnrestrictedSpecificIntrinsicFunction(name);
}
std::ostream &TypePattern::Dump(std::ostream &o) const {

View File

@ -592,7 +592,6 @@ std::optional<Expr<SomeType>> ConvertToType(
}
}
break;
default: CRASH_NO_CASE;
}
return std::nullopt;
}

View File

@ -498,7 +498,7 @@ std::optional<Expr<SomeComplex>> ConstructComplex(parser::ContextualMessages &,
template<typename A> Expr<TypeOf<A>> ScalarConstantToExpr(const A &x) {
using Ty = TypeOf<A>;
static_assert(
std::is_same_v<Scalar<Ty>, std::decay_t<A>> || !"TypeOf<> is broken");
std::is_same_v<Scalar<Ty>, std::decay_t<A>>, "TypeOf<> is broken");
return Expr<TypeOf<A>>{Constant<Ty>{x}};
}

View File

@ -123,7 +123,6 @@ 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);
default: CRASH_NO_CASE;
}
}
@ -255,7 +254,6 @@ 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);
default: CRASH_NO_CASE;
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -76,7 +76,7 @@ void ParsingLog::Dump(std::ostream &o, const CookedSource &cooked) const {
Message{at, tagLog.first}.Emit(o, cooked, true);
auto &entry{tagLog.second};
o << " " << (entry.pass ? "pass" : "fail") << " " << entry.count << '\n';
entry.messages.Emit(o, cooked, " ");
entry.messages.Emit(o, cooked);
}
}
}

View File

@ -58,7 +58,7 @@ static void NormalizeCompilerDirectiveCommentMarker(TokenSequence &dir) {
return;
}
}
CHECK(!"compiler directive all blank");
CHECK(false && "compiler directive all blank");
}
void Prescanner::Prescan(ProvenanceRange range) {

View File

@ -679,7 +679,6 @@ public:
break;
case common::ImportKind::None: Word(", NONE"); break;
case common::ImportKind::All: Word(", ALL"); break;
default: CRASH_NO_CASE;
}
}
void Unparse(const NamelistStmt &x) { // R868
@ -1451,7 +1450,6 @@ public:
FMT(A);
FMT(D);
#undef FMT
default: CRASH_NO_CASE;
}
Walk(x.width), Walk(".", x.digits), Walk("E", x.exponentWidth);
}
@ -1511,7 +1509,6 @@ public:
#undef FMT
case format::ControlEditDesc::Kind::Dollar: Put('$'); break;
case format::ControlEditDesc::Kind::Backslash: Put('\\'); break;
default: CRASH_NO_CASE;
}
}
@ -2049,7 +2046,6 @@ public:
case OmpLoopDirective::Directive::TeamsDistributeSimd:
Word("TEAMS DISTRIBUTE SIMD ");
break;
default: CRASH_NO_CASE;
}
}
void Unparse(const OmpObjectList &x) { Walk(x.v, ","); }

View File

@ -442,10 +442,10 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
OmpClause::NUM_TEAMS, OmpClause::THREAD_LIMIT, OmpClause::DEFAULT};
SetContextAllowedOnce(allowedOnce);
} break;
// 2.10.1 target-data-clause -> if-clause |
// device-clause |
// map-clause |
// use-device-ptr-clause
// 2.10.1 target-data-clause -> if-clause |
// device-clause |
// map-clause |
// use-device-ptr-clause
case parser::OmpBlockDirective::Directive::TargetData: {
PushContext(beginDir.source, OmpDirective::TARGET_DATA);
OmpClauseSet allowed{
@ -599,9 +599,6 @@ void OmpStructureChecker::Enter(
OmpClauseSet allowed{OmpClause::DEPEND};
SetContextAllowed(allowed);
} break;
default:
// TODO others
break;
}
}

View File

@ -128,7 +128,6 @@ common::IfNoLvalue<MaybeExpr, WRAPPED> TypedWrapper(
dyType.kind(), std::move(x));
case TypeCategory::Derived:
return AsGenericExpr(Expr<SomeDerived>{WRAPPER<SomeDerived>{std::move(x)}});
default: CRASH_NO_CASE;
}
}
@ -203,7 +202,7 @@ MaybeExpr ExpressionAnalyzer::ApplySubscripts(
ArrayRef{std::move(c), std::move(subscripts)});
},
[&](auto &&) -> MaybeExpr {
CHECK(!"bad base for ArrayRef");
DIE("bad base for ArrayRef");
return std::nullopt;
},
},
@ -902,7 +901,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::StructureComponent &sc) {
return MakeFunctionRef(
name, ActualArguments{ActualArgument{std::move(*base)}});
} else {
common::die("unexpected MiscDetails::Kind");
DIE("unexpected MiscDetails::Kind");
}
} else {
Say(name, "derived type required before component reference"_err_en_US);

View File

@ -194,7 +194,6 @@ static GenericKind MapIntrinsicOperator(IntrinsicOperator op) {
case IntrinsicOperator::XOR: return GenericKind::OpXOR;
case IntrinsicOperator::EQV: return GenericKind::OpEQV;
case IntrinsicOperator::NEQV: return GenericKind::OpNEQV;
default: CRASH_NO_CASE;
}
}

View File

@ -910,7 +910,7 @@ private:
"Declaration of '%s' conflicts with its use as internal procedure"_err_en_US,
symbol, "Internal procedure definition"_en_US);
} else {
CHECK(!"unexpected kind");
DIE("unexpected kind");
}
} else if (std::is_same_v<ObjectEntityDetails, T> &&
symbol.has<ProcEntityDetails>()) {
@ -4824,8 +4824,7 @@ const DeclTypeSpec &ConstructVisitor::ToDeclTypeSpec(
);
}
case common::TypeCategory::Character:
default: CRASH_NO_CASE;
case common::TypeCategory::Character: CRASH_NO_CASE;
}
}
@ -5272,7 +5271,7 @@ void ResolveNamesVisitor::HandleProcedureName(
ConvertToProcEntity(*symbol);
SetProcFlag(name, *symbol, flag);
} else if (symbol->has<UnknownDetails>()) {
CHECK(!"unexpected UnknownDetails");
DIE("unexpected UnknownDetails");
} else if (CheckUseError(name)) {
// error was reported
} else {
@ -5731,7 +5730,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());
default: CRASH_NO_CASE;
}
}

View File

@ -216,7 +216,6 @@ bool Scope::CanImport(const SourceName &name) const {
case ImportKind::All:
case ImportKind::Default: return true;
case ImportKind::Only: return importNames_.count(name) > 0;
default: CRASH_NO_CASE;
}
}

View File

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