98 changes: 48 additions & 50 deletions flang/lib/semantics/resolve-names.cc

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions flang/lib/semantics/rewrite-parse-tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class RewriteMutator {

// Check that name has been resolved to a symbol
void RewriteMutator::Post(parser::Name &name) {
if (name.symbol == nullptr && errorOnUnresolvedName_) {
if (!name.symbol && errorOnUnresolvedName_) {
messages_.Say(name.source, "Internal: no symbol found for '%s'"_err_en_US,
name.source);
}
Expand Down Expand Up @@ -116,7 +116,7 @@ void RewriteMutator::Post(parser::IoUnit &x) {
if (auto *var{std::get_if<parser::Variable>(&x.u)}) {
const parser::Name &last{parser::GetLastName(*var)};
DeclTypeSpec *type{last.symbol ? last.symbol->GetType() : nullptr};
if (type == nullptr || type->category() != DeclTypeSpec::Character) {
if (!type || type->category() != DeclTypeSpec::Character) {
// If the Variable is not known to be character (any kind), transform
// the I/O unit in situ to a FileUnitNumber so that automatic expression
// constraint checking will be applied.
Expand All @@ -137,10 +137,10 @@ void RewriteMutator::Post(parser::IoUnit &x) {
// name had appeared with NML=.
template<typename READ_OR_WRITE>
void FixMisparsedUntaggedNamelistName(READ_OR_WRITE &x) {
if (x.iounit.has_value() && x.format.has_value() &&
if (x.iounit && x.format &&
std::holds_alternative<parser::DefaultCharExpr>(x.format->u)) {
if (const parser::Name * name{parser::Unwrap<parser::Name>(x.format)}) {
if (name->symbol != nullptr && name->symbol->has<NamelistDetails>()) {
if (name->symbol && name->symbol->has<NamelistDetails>()) {
x.controls.emplace_front(parser::IoControlSpec{std::move(*name)});
x.format.reset();
}
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/semantics/scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Scope::ImportKind Scope::GetImportKind() const {
}

std::optional<parser::MessageFixedText> Scope::SetImportKind(ImportKind kind) {
if (!importKind_.has_value()) {
if (!importKind_) {
importKind_ = kind;
return std::nullopt;
}
Expand Down Expand Up @@ -298,10 +298,10 @@ const DeclTypeSpec *Scope::FindInstantiatedDerivedType(
}

const Symbol *Scope::GetSymbol() const {
if (symbol_ != nullptr) {
if (symbol_) {
return symbol_;
}
if (derivedTypeSpec_ != nullptr) {
if (derivedTypeSpec_) {
return &derivedTypeSpec_->typeSymbol();
}
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/semantics/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Scope {
DeclTypeSpec::Category = DeclTypeSpec::TypeDerived) const;

bool IsModuleFile() const {
return kind_ == Kind::Module && symbol_ != nullptr &&
return kind_ == Kind::Module && symbol_ &&
symbol_->test(Symbol::Flag::ModFile);
}

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/semantics/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SemanticsContext {
void SetError(Symbol &, bool = true);

template<typename... A> parser::Message &Say(A &&... args) {
CHECK(location_.has_value());
CHECK(location_);
return messages_.Say(*location_, std::forward<A>(args)...);
}
template<typename... A>
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/semantics/symbol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ const DerivedTypeSpec *Symbol::GetParentTypeSpec(const Scope *scope) const {

const Symbol *Symbol::GetParentComponent(const Scope *scope) const {
if (const auto *dtDetails{detailsIf<DerivedTypeDetails>()}) {
if (scope == nullptr) {
CHECK(scope_ != nullptr);
if (!scope) {
CHECK(scope_);
scope = scope_;
}
return dtDetails->GetParentComponent(*scope);
Expand Down Expand Up @@ -582,7 +582,7 @@ const Symbol *DerivedTypeDetails::GetParentComponent(const Scope &scope) const {
}

void TypeParamDetails::set_type(const DeclTypeSpec &type) {
CHECK(type_ == nullptr);
CHECK(!type_);
type_ = &type;
}

Expand Down
4 changes: 2 additions & 2 deletions flang/lib/semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SubprogramDetails {
return *result_;
}
void set_result(Symbol &result) {
CHECK(result_ == nullptr);
CHECK(!result_);
result_ = &result;
}
const std::vector<Symbol *> &dummyArgs() const { return dummyArgs_; }
Expand Down Expand Up @@ -495,7 +495,7 @@ class Symbol {
}
template<typename D> const D &get() const {
const auto *p{detailsIf<D>()};
CHECK(p != nullptr);
CHECK(p);
return *p;
}

Expand Down
32 changes: 16 additions & 16 deletions flang/lib/semantics/tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Symbol *FindCommonBlockContaining(const Symbol &object) {

const Scope *FindProgramUnitContaining(const Scope &start) {
const Scope *scope{&start};
while (scope != nullptr) {
while (scope) {
switch (scope->kind()) {
case Scope::Kind::Module:
case Scope::Kind::MainProgram:
Expand All @@ -72,7 +72,7 @@ const Scope *FindProgramUnitContaining(const Symbol &symbol) {

const Scope *FindPureProcedureContaining(const Scope *scope) {
scope = FindProgramUnitContaining(*scope);
while (scope != nullptr) {
while (scope) {
if (IsPureProcedure(*scope)) {
return scope;
}
Expand All @@ -94,13 +94,13 @@ bool IsCommonBlockContaining(const Symbol &block, const Symbol &object) {

bool IsUseAssociated(const Symbol &symbol, const Scope &scope) {
const Scope *owner{FindProgramUnitContaining(symbol.GetUltimate().owner())};
return owner != nullptr && owner->kind() == Scope::Kind::Module &&
return owner && owner->kind() == Scope::Kind::Module &&
owner != FindProgramUnitContaining(scope);
}

bool DoesScopeContain(
const Scope *maybeAncestor, const Scope &maybeDescendent) {
if (maybeAncestor != nullptr) {
if (maybeAncestor) {
const Scope *scope{&maybeDescendent};
while (!scope->IsGlobal()) {
scope = &scope->parent();
Expand Down Expand Up @@ -302,13 +302,13 @@ const Symbol *FindExternallyVisibleObject(
bool ExprHasTypeCategory(
const SomeExpr &expr, const common::TypeCategory &type) {
auto dynamicType{expr.GetType()};
return dynamicType.has_value() && dynamicType->category() == type;
return dynamicType && dynamicType->category() == type;
}

bool ExprTypeKindIsDefault(
const SomeExpr &expr, const SemanticsContext &context) {
auto dynamicType{expr.GetType()};
return dynamicType.has_value() &&
return dynamicType &&
dynamicType->category() != common::TypeCategory::Derived &&
dynamicType->kind() == context.GetDefaultKind(dynamicType->category());
}
Expand Down Expand Up @@ -454,7 +454,7 @@ bool IsSaved(const Symbol &symbol) {

// Check this symbol suitable as a type-bound procedure - C769
bool CanBeTypeBoundProc(const Symbol *symbol) {
if (symbol == nullptr || IsDummy(*symbol) || IsProcedurePointer(*symbol)) {
if (!symbol || IsDummy(*symbol) || IsProcedurePointer(*symbol)) {
return false;
} else if (symbol->has<SubprogramNameDetails>()) {
return symbol->owner().kind() == Scope::Kind::Module;
Expand Down Expand Up @@ -701,8 +701,8 @@ bool HasCoarray(const parser::Expr &expression) {
static const DeclTypeSpec &InstantiateIntrinsicType(Scope &scope,
const DeclTypeSpec &spec, SemanticsContext &semanticsContext) {
const IntrinsicTypeSpec *intrinsic{spec.AsIntrinsic()};
CHECK(intrinsic != nullptr);
if (evaluate::ToInt64(intrinsic->kind()).has_value()) {
CHECK(intrinsic);
if (evaluate::ToInt64(intrinsic->kind())) {
return spec; // KIND is already a known constant
}
// The expression was not originally constant, but now it must be so
Expand Down Expand Up @@ -776,7 +776,7 @@ void InstantiateDerivedType(DerivedTypeSpec &spec, Scope &containingScope,
spec.ReplaceScope(newScope);
const Symbol &typeSymbol{spec.typeSymbol()};
const Scope *typeScope{typeSymbol.scope()};
CHECK(typeScope != nullptr);
CHECK(typeScope);
for (const Symbol &symbol : OrderParameterDeclarations(typeSymbol)) {
const SourceName &name{symbol.name()};
if (typeScope->find(symbol.name()) != typeScope->end()) {
Expand All @@ -795,7 +795,7 @@ void InstantiateDerivedType(DerivedTypeSpec &spec, Scope &containingScope,
if (auto maybeDynamicType{expr->GetType()}) {
if (expr->Rank() == 0 &&
maybeDynamicType->category() == TypeCategory::Integer) {
if (!evaluate::ToInt64(*expr).has_value()) {
if (!evaluate::ToInt64(*expr)) {
std::stringstream fortran;
fortran << *expr;
if (auto *msg{
Expand Down Expand Up @@ -869,13 +869,13 @@ void ProcessParameterExpressions(
const TypeParamDetails &details{symbol.get<TypeParamDetails>()};
MaybeIntExpr expr;
ParamValue *paramValue{spec.FindParameter(name)};
if (paramValue == nullptr) {
if (!paramValue) {
expr = evaluate::Fold(foldingContext, common::Clone(details.init()));
} else if (paramValue->isExplicit()) {
expr = paramValue->GetExplicit();
}
if (expr.has_value()) {
if (paramValue != nullptr) {
if (expr) {
if (paramValue) {
paramValue->SetExplicit(std::move(*expr));
} else {
spec.AddParamValue(
Expand Down Expand Up @@ -933,7 +933,7 @@ static Symbol &InstantiateSymbol(
}
details->ReplaceType(FindOrInstantiateDerivedType(
scope, std::move(newSpec), semanticsContext, origType->category()));
} else if (origType->AsIntrinsic() != nullptr) {
} else if (origType->AsIntrinsic()) {
details->ReplaceType(
InstantiateIntrinsicType(scope, *origType, semanticsContext));
} else if (origType->category() != DeclTypeSpec::ClassStar) {
Expand Down Expand Up @@ -1160,7 +1160,7 @@ const Symbol *FindImmediateComponent(const DerivedTypeSpec &type,
parent = symbol;
}
}
if (parent != nullptr) {
if (parent) {
if (const auto *object{parent->detailsIf<ObjectEntityDetails>()}) {
if (const auto *type{object->type()}) {
if (const auto *derived{type->AsDerived()}) {
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/semantics/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct GetExprHelper {
return Get(x.value());
}
template<typename T> const SomeExpr *Get(const std::optional<T> &x) {
return x.has_value() ? Get(x.value()) : nullptr;
return x ? Get(*x) : nullptr;
}
template<typename T> const SomeExpr *Get(const T &x) {
if constexpr (ConstraintTrait<T>) {
Expand Down
47 changes: 23 additions & 24 deletions flang/runtime/ISO_Fortran_binding.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,7 +41,7 @@ void *CFI_address(

int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
const CFI_index_t upper_bounds[], std::size_t elem_len) {
if (descriptor == nullptr) {
if (!descriptor) {
return CFI_INVALID_DESCRIPTOR;
}
if (descriptor->version != CFI_VERSION) {
Expand All @@ -53,7 +53,7 @@ int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
return CFI_INVALID_ATTRIBUTE;
}
if (descriptor->attribute == CFI_attribute_allocatable &&
descriptor->base_addr != nullptr) {
descriptor->base_addr) {
return CFI_ERROR_BASE_ADDR_NOT_NULL;
}
if (descriptor->rank > CFI_MAX_RANK) {
Expand Down Expand Up @@ -82,7 +82,7 @@ int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
byteSize *= extent;
}
void *p{new char[byteSize]};
if (p == nullptr) {
if (!p) {
return CFI_ERROR_MEM_ALLOCATION;
}
descriptor->base_addr = p;
Expand All @@ -91,7 +91,7 @@ int CFI_allocate(CFI_cdesc_t *descriptor, const CFI_index_t lower_bounds[],
}

int CFI_deallocate(CFI_cdesc_t *descriptor) {
if (descriptor == nullptr) {
if (!descriptor) {
return CFI_INVALID_DESCRIPTOR;
}
if (descriptor->version != CFI_VERSION) {
Expand All @@ -102,7 +102,7 @@ int CFI_deallocate(CFI_cdesc_t *descriptor) {
// Non-interoperable object
return CFI_INVALID_DESCRIPTOR;
}
if (descriptor->base_addr == nullptr) {
if (!descriptor->base_addr) {
return CFI_ERROR_BASE_ADDR_NULL;
}
delete[] static_cast<char *>(descriptor->base_addr);
Expand Down Expand Up @@ -162,16 +162,16 @@ int CFI_establish(CFI_cdesc_t *descriptor, void *base_addr,
if (rank > CFI_MAX_RANK) {
return CFI_INVALID_RANK;
}
if (base_addr != nullptr && attribute == CFI_attribute_allocatable) {
if (base_addr && attribute == CFI_attribute_allocatable) {
return CFI_ERROR_BASE_ADDR_NOT_NULL;
}
if (rank > 0 && base_addr != nullptr && extents == nullptr) {
if (rank > 0 && base_addr && !extents) {
return CFI_INVALID_EXTENT;
}
if (type < CFI_type_signed_char || type > CFI_type_struct) {
return CFI_INVALID_TYPE;
}
if (descriptor == nullptr) {
if (!descriptor) {
return CFI_INVALID_DESCRIPTOR;
}
std::size_t minElemLen{MinElemLen(type)};
Expand All @@ -189,7 +189,7 @@ int CFI_establish(CFI_cdesc_t *descriptor, void *base_addr,
descriptor->f18Addendum = 0;
std::size_t byteSize{elem_len};
constexpr std::size_t lower_bound{0};
if (base_addr != nullptr) {
if (base_addr) {
for (std::size_t j{0}; j < rank; ++j) {
descriptor->dim[j].lower_bound = lower_bound;
descriptor->dim[j].extent = extents[j];
Expand Down Expand Up @@ -218,13 +218,13 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
CFI_index_t actualStride[CFI_MAX_RANK];
CFI_rank_t resRank{0};

if (result == nullptr || source == nullptr) {
if (!result || !source) {
return CFI_INVALID_DESCRIPTOR;
}
if (source->rank == 0) {
return CFI_INVALID_RANK;
}
if (IsAssumedSize(source) && upper_bounds == nullptr) {
if (IsAssumedSize(source) && !upper_bounds) {
return CFI_INVALID_DESCRIPTOR;
}
if ((result->type != source->type) ||
Expand All @@ -234,7 +234,7 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
if (result->attribute == CFI_attribute_allocatable) {
return CFI_INVALID_ATTRIBUTE;
}
if (source->base_addr == nullptr) {
if (!source->base_addr) {
return CFI_ERROR_BASE_ADDR_NULL;
}

Expand All @@ -244,9 +244,9 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,
const CFI_dim_t &dim{source->dim[j]};
const CFI_index_t srcLB{dim.lower_bound};
const CFI_index_t srcUB{srcLB + dim.extent - 1};
const CFI_index_t lb{lower_bounds != nullptr ? lower_bounds[j] : srcLB};
const CFI_index_t ub{upper_bounds != nullptr ? upper_bounds[j] : srcUB};
const CFI_index_t stride{strides != nullptr ? strides[j] : 1};
const CFI_index_t lb{lower_bounds ? lower_bounds[j] : srcLB};
const CFI_index_t ub{upper_bounds ? upper_bounds[j] : srcUB};
const CFI_index_t stride{strides ? strides[j] : 1};

if (stride == 0 && lb != ub) {
return CFI_ERROR_OUT_OF_BOUNDS;
Expand Down Expand Up @@ -285,7 +285,7 @@ int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,

int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
std::size_t displacement, std::size_t elem_len) {
if (result == nullptr || source == nullptr) {
if (!result || !source) {
return CFI_INVALID_DESCRIPTOR;
}
if (result->rank != source->rank) {
Expand All @@ -294,7 +294,7 @@ int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,
if (result->attribute == CFI_attribute_allocatable) {
return CFI_INVALID_ATTRIBUTE;
}
if (source->base_addr == nullptr) {
if (!source->base_addr) {
return CFI_ERROR_BASE_ADDR_NULL;
}
if (IsAssumedSize(source)) {
Expand All @@ -320,13 +320,13 @@ int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source,

int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
const CFI_index_t lower_bounds[]) {
if (result == nullptr) {
if (!result) {
return CFI_INVALID_DESCRIPTOR;
}
if (result->attribute != CFI_attribute_pointer) {
return CFI_INVALID_ATTRIBUTE;
}
if (source == nullptr) {
if (!source) {
result->base_addr = nullptr;
return CFI_SUCCESS;
}
Expand All @@ -339,17 +339,16 @@ int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
if (source->elem_len != result->elem_len) {
return CFI_INVALID_ELEM_LEN;
}
if (source->base_addr == nullptr &&
source->attribute != CFI_attribute_pointer) {
if (!source->base_addr && source->attribute != CFI_attribute_pointer) {
return CFI_ERROR_BASE_ADDR_NULL;
}
if (IsAssumedSize(source)) {
return CFI_INVALID_DESCRIPTOR;
}

const bool copySrcLB{lower_bounds == nullptr};
const bool copySrcLB{!lower_bounds};
result->base_addr = source->base_addr;
if (source->base_addr != nullptr) {
if (source->base_addr) {
for (int j{0}; j < result->rank; ++j) {
result->dim[j].extent = source->dim[j].extent;
result->dim[j].sm = source->dim[j].sm;
Expand Down
4 changes: 2 additions & 2 deletions flang/runtime/derived-type.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -86,7 +86,7 @@ class Component {
}

const Descriptor *GetDescriptor(const char *dtInstance) const {
if (staticDescriptor_ != nullptr) {
if (staticDescriptor_) {
return staticDescriptor_;
} else if (IsDescriptor()) {
return Locate<const Descriptor>(dtInstance);
Expand Down
14 changes: 7 additions & 7 deletions flang/runtime/descriptor.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -61,7 +61,7 @@ void Descriptor::Establish(const DerivedType &dt, void *p, int rank,
dt.SizeInBytes(), rank, extent) == CFI_SUCCESS);
raw_.f18Addendum = true;
DescriptorAddendum *a{Addendum()};
CHECK(a != nullptr);
CHECK(a);
new (a) DescriptorAddendum{&dt};
}

Expand All @@ -70,7 +70,7 @@ std::unique_ptr<Descriptor> Descriptor::Create(TypeCode t,
ISO::CFI_attribute_t attribute) {
std::size_t bytes{SizeInBytes(rank, true)};
Descriptor *result{reinterpret_cast<Descriptor *>(new char[bytes])};
CHECK(result != nullptr);
CHECK(result);
result->Establish(t, elementBytes, p, rank, extent, attribute, true);
return std::unique_ptr<Descriptor>{result};
}
Expand All @@ -80,7 +80,7 @@ std::unique_ptr<Descriptor> Descriptor::Create(TypeCategory c, int kind,
ISO::CFI_attribute_t attribute) {
std::size_t bytes{SizeInBytes(rank, true)};
Descriptor *result{reinterpret_cast<Descriptor *>(new char[bytes])};
CHECK(result != nullptr);
CHECK(result);
result->Establish(c, kind, p, rank, extent, attribute, true);
return std::unique_ptr<Descriptor>{result};
}
Expand All @@ -89,7 +89,7 @@ std::unique_ptr<Descriptor> Descriptor::Create(const DerivedType &dt, void *p,
int rank, const SubscriptValue *extent, ISO::CFI_attribute_t attribute) {
std::size_t bytes{SizeInBytes(rank, true, dt.lenParameters())};
Descriptor *result{reinterpret_cast<Descriptor *>(new char[bytes])};
CHECK(result != nullptr);
CHECK(result);
result->Establish(dt, p, rank, extent, attribute);
return std::unique_ptr<Descriptor>{result};
}
Expand Down Expand Up @@ -119,14 +119,14 @@ int Descriptor::Allocate(
}

int Descriptor::Deallocate(bool finalize) {
if (raw_.base_addr != nullptr) {
if (raw_.base_addr) {
Destroy(static_cast<char *>(raw_.base_addr), finalize);
}
return ISO::CFI_deallocate(&raw_);
}

void Descriptor::Destroy(char *data, bool finalize) const {
if (data != nullptr) {
if (data) {
if (const DescriptorAddendum * addendum{Addendum()}) {
if (addendum->flags() & DescriptorAddendum::DoNotFinalize) {
finalize = false;
Expand Down
4 changes: 2 additions & 2 deletions flang/runtime/descriptor.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -82,7 +82,7 @@ class DescriptorAddendum {
const std::uint64_t &flags() const { return flags_; }

std::size_t LenParameters() const {
if (derivedType_ != nullptr) {
if (derivedType_) {
return derivedType_->lenParameters();
}
return 0;
Expand Down
10 changes: 5 additions & 5 deletions flang/runtime/transformational.cc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -74,7 +74,7 @@ std::unique_ptr<Descriptor> RESHAPE(const Descriptor &source,
// Extract and check the optional ORDER= argument, which must be a
// permutation of [1..resultRank].
int dimOrder[maxRank];
if (order != nullptr) {
if (order) {
CHECK(order->rank() == 1);
CHECK(order->type().IsInteger());
CHECK(order->GetDimension(0).Extent() == resultRank);
Expand All @@ -97,7 +97,7 @@ std::unique_ptr<Descriptor> RESHAPE(const Descriptor &source,
const DerivedType *sourceDerivedType{
sourceAddendum ? sourceAddendum->derivedType() : nullptr};
std::unique_ptr<Descriptor> result;
if (sourceDerivedType != nullptr) {
if (sourceDerivedType) {
result = Descriptor::Create(*sourceDerivedType, nullptr, resultRank,
resultExtent, CFI_attribute_allocatable);
} else {
Expand All @@ -106,9 +106,9 @@ std::unique_ptr<Descriptor> RESHAPE(const Descriptor &source,
CFI_attribute_allocatable); // TODO rearrange these arguments
}
DescriptorAddendum *resultAddendum{result->Addendum()};
CHECK(resultAddendum != nullptr);
CHECK(resultAddendum);
resultAddendum->flags() |= DescriptorAddendum::DoNotFinalize;
if (sourceDerivedType != nullptr) {
if (sourceDerivedType) {
std::size_t lenParameters{sourceDerivedType->lenParameters()};
for (std::size_t j{0}; j < lenParameters; ++j) {
resultAddendum->SetLenParameterValue(
Expand Down
2 changes: 1 addition & 1 deletion flang/tools/f18/f18-parse-demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ std::string CompileFortran(
}
if ((!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) ||
!parsing.parseTree().has_value()) {
!parsing.parseTree()) {
std::cerr << driver.prefix << "could not parse " << path << '\n';
exitStatus = EXIT_FAILURE;
return {};
Expand Down
4 changes: 2 additions & 2 deletions flang/tools/f18/f18.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
}
if ((!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) ||
!parsing.parseTree().has_value()) {
!parsing.parseTree()) {
std::cerr << driver.prefix << "could not parse " << path << '\n';
exitStatus = EXIT_FAILURE;
return {};
Expand Down Expand Up @@ -291,7 +291,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,

Fortran::parser::TypedExprAsFortran unparseExpression{
[](std::ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
if (x.v.has_value()) {
if (x.v) {
o << *x.v;
} else {
o << "(bad expression)";
Expand Down