Skip to content

Commit e03b20e

Browse files
committed
[flang] Changes to get a clean build of f18 with latest clang
Prep for review Original-commit: flang-compiler/f18@111f490 Reviewed-on: flang-compiler/f18#1059
1 parent 330ca1e commit e03b20e

File tree

10 files changed

+112
-40
lines changed

10 files changed

+112
-40
lines changed

flang/include/flang/Common/reference.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ template<typename A> class Reference {
4545
type &get() const noexcept { return *p_; }
4646
type *operator->() const { return p_; }
4747
type &operator*() const { return *p_; }
48-
bool operator==(Reference that) const { return *p_ == *that.p_; }
49-
bool operator!=(Reference that) const { return *p_ != *that.p_; }
48+
49+
bool operator==(std::add_const_t<A> &that) const {
50+
return p_ == &that || *p_ == that;
51+
}
52+
bool operator!=(std::add_const_t<A> &that) const { return !(*this == that); }
53+
bool operator==(const Reference &that) const {
54+
return p_ == that.p_ || *this == *that.p_;
55+
}
56+
bool operator!=(const Reference &that) const { return !(*this == that); }
5057

5158
private:
5259
type *p_; // never null

flang/include/flang/Common/uint128.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ namespace Fortran::common {
2525
class UnsignedInt128 {
2626
public:
2727
constexpr UnsignedInt128() {}
28-
constexpr UnsignedInt128(std::uint64_t n) : low_{n} {}
29-
constexpr UnsignedInt128(std::int64_t n)
28+
// This means of definition provides some portability for
29+
// "size_t" operands.
30+
constexpr UnsignedInt128(unsigned n) : low_{n} {}
31+
constexpr UnsignedInt128(unsigned long n) : low_{n} {}
32+
constexpr UnsignedInt128(unsigned long long n) : low_{n} {}
33+
constexpr UnsignedInt128(int n)
3034
: low_{static_cast<std::uint64_t>(n)}, high_{-static_cast<std::uint64_t>(
3135
n < 0)} {}
32-
constexpr UnsignedInt128(int n)
36+
constexpr UnsignedInt128(long n)
37+
: low_{static_cast<std::uint64_t>(n)}, high_{-static_cast<std::uint64_t>(
38+
n < 0)} {}
39+
constexpr UnsignedInt128(long long n)
3340
: low_{static_cast<std::uint64_t>(n)}, high_{-static_cast<std::uint64_t>(
3441
n < 0)} {}
3542
constexpr UnsignedInt128(const UnsignedInt128 &) = default;

flang/include/flang/Evaluate/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ using HostUnsignedInt =
195195
#define EVALUATE_UNION_CLASS_BOILERPLATE(t) \
196196
CLASS_BOILERPLATE(t) \
197197
UNION_CONSTRUCTORS(t) \
198-
bool operator==(const t &that) const { return u == that.u; }
198+
bool operator==(const t &) const;
199199

200200
// Forward definition of Expr<> so that it can be indirectly used in its own
201201
// definition

flang/include/flang/Evaluate/expression.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ using TypelessExpression = std::variant<BOZLiteralConstant, NullPointer,
780780
template<> class Expr<SomeType> : public ExpressionBase<SomeType> {
781781
public:
782782
using Result = SomeType;
783-
784783
EVALUATE_UNION_CLASS_BOILERPLATE(Expr)
785784

786785
// Owning references to these generic expressions can appear in other

flang/include/flang/Evaluate/variable.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,12 @@ using SymbolVector = std::vector<SymbolRef>;
4343
struct DataRef;
4444
template<typename T> struct Variable;
4545

46-
bool AreSameSymbol(const Symbol &, const Symbol &);
47-
48-
// Implements operator==() for a union type, using special case handling
49-
// for Symbol references.
50-
template<typename A> bool TestVariableEquality(const A &x, const A &y) {
51-
const SymbolRef *xSymbol{std::get_if<SymbolRef>(&x.u)};
52-
if (const SymbolRef * ySymbol{std::get_if<SymbolRef>(&y.u)}) {
53-
return xSymbol && AreSameSymbol(*xSymbol, *ySymbol);
54-
} else {
55-
return x.u == y.u;
56-
}
57-
}
58-
5946
// Reference a base object in memory. This can be a Fortran symbol,
6047
// static data (e.g., CHARACTER literal), or compiler-created temporary.
6148
struct BaseObject {
62-
CLASS_BOILERPLATE(BaseObject)
63-
UNION_CONSTRUCTORS(BaseObject)
49+
EVALUATE_UNION_CLASS_BOILERPLATE(BaseObject)
6450
int Rank() const;
6551
std::optional<Expr<SubscriptInteger>> LEN() const;
66-
bool operator==(const BaseObject &) const;
6752
std::ostream &AsFortran(std::ostream &) const;
6853
const Symbol *symbol() const {
6954
if (const auto *result{std::get_if<SymbolRef>(&u)}) {
@@ -296,10 +281,7 @@ class CoarrayRef {
296281
// a terminal substring range or complex component designator; use
297282
// R901 designator for that.
298283
struct DataRef {
299-
CLASS_BOILERPLATE(DataRef)
300-
UNION_CONSTRUCTORS(DataRef)
301-
302-
bool operator==(const DataRef &) const;
284+
EVALUATE_UNION_CLASS_BOILERPLATE(DataRef)
303285
int Rank() const;
304286
const Symbol &GetFirstSymbol() const;
305287
const Symbol &GetLastSymbol() const;
@@ -395,15 +377,11 @@ template<typename T> class Designator {
395377
using Result = T;
396378
static_assert(
397379
IsSpecificIntrinsicType<Result> || std::is_same_v<Result, SomeDerived>);
398-
CLASS_BOILERPLATE(Designator)
399-
UNION_CONSTRUCTORS(Designator)
380+
EVALUATE_UNION_CLASS_BOILERPLATE(Designator)
400381
Designator(const DataRef &that) : u{common::CopyVariant<Variant>(that.u)} {}
401382
Designator(DataRef &&that)
402383
: u{common::MoveVariant<Variant>(std::move(that.u))} {}
403384

404-
bool operator==(const Designator &that) const {
405-
return TestVariableEquality(*this, that);
406-
}
407385
std::optional<DynamicType> GetType() const;
408386
int Rank() const;
409387
BaseObject GetBaseObject() const;

flang/lib/Evaluate/call.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ bool SpecificIntrinsic::operator==(const SpecificIntrinsic &that) const {
7979
ProcedureDesignator::ProcedureDesignator(Component &&c)
8080
: u{common::CopyableIndirection<Component>::Make(std::move(c))} {}
8181

82+
bool ProcedureDesignator::operator==(const ProcedureDesignator &that) const {
83+
return u == that.u;
84+
}
85+
8286
std::optional<DynamicType> ProcedureDesignator::GetType() const {
8387
if (const auto *intrinsic{std::get_if<SpecificIntrinsic>(&u)}) {
8488
if (const auto &result{intrinsic->characteristics.value().functionResult}) {

flang/lib/Evaluate/expression.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ template<typename A> int ExpressionBase<A>::Rank() const {
101101
derived().u);
102102
}
103103

104-
// Equality testing for classes without EVALUATE_UNION_CLASS_BOILERPLATE()
104+
// Equality testing
105105

106106
bool ImpliedDoIndex::operator==(const ImpliedDoIndex &that) const {
107107
return name == that.name;
@@ -114,6 +114,12 @@ bool ImpliedDo<T>::operator==(const ImpliedDo<T> &that) const {
114114
values_ == that.values_;
115115
}
116116

117+
template<typename T>
118+
bool ArrayConstructorValue<T>::operator==(
119+
const ArrayConstructorValue<T> &that) const {
120+
return u == that.u;
121+
}
122+
117123
template<typename R>
118124
bool ArrayConstructorValues<R>::operator==(
119125
const ArrayConstructorValues<R> &that) const {
@@ -146,6 +152,57 @@ bool StructureConstructor::operator==(const StructureConstructor &that) const {
146152
return result_ == that.result_ && values_ == that.values_;
147153
}
148154

155+
bool Relational<SomeType>::operator==(const Relational<SomeType> &that) const {
156+
return u == that.u;
157+
}
158+
159+
template<int KIND>
160+
bool Expr<Type<TypeCategory::Integer, KIND>>::operator==(
161+
const Expr<Type<TypeCategory::Integer, KIND>> &that) const {
162+
return u == that.u;
163+
}
164+
165+
template<int KIND>
166+
bool Expr<Type<TypeCategory::Real, KIND>>::operator==(
167+
const Expr<Type<TypeCategory::Real, KIND>> &that) const {
168+
return u == that.u;
169+
}
170+
171+
template<int KIND>
172+
bool Expr<Type<TypeCategory::Complex, KIND>>::operator==(
173+
const Expr<Type<TypeCategory::Complex, KIND>> &that) const {
174+
return u == that.u;
175+
}
176+
177+
template<int KIND>
178+
bool Expr<Type<TypeCategory::Logical, KIND>>::operator==(
179+
const Expr<Type<TypeCategory::Logical, KIND>> &that) const {
180+
return u == that.u;
181+
}
182+
183+
template<int KIND>
184+
bool Expr<Type<TypeCategory::Character, KIND>>::operator==(
185+
const Expr<Type<TypeCategory::Character, KIND>> &that) const {
186+
return u == that.u;
187+
}
188+
189+
template<TypeCategory CAT>
190+
bool Expr<SomeKind<CAT>>::operator==(const Expr<SomeKind<CAT>> &that) const {
191+
return u == that.u;
192+
}
193+
194+
bool Expr<SomeDerived>::operator==(const Expr<SomeDerived> &that) const {
195+
return u == that.u;
196+
}
197+
198+
bool Expr<SomeCharacter>::operator==(const Expr<SomeCharacter> &that) const {
199+
return u == that.u;
200+
}
201+
202+
bool Expr<SomeType>::operator==(const Expr<SomeType> &that) const {
203+
return u == that.u;
204+
}
205+
149206
DynamicType StructureConstructor::GetType() const { return result_.GetType(); }
150207

151208
const Expr<SomeType> *StructureConstructor::Find(

flang/lib/Evaluate/variable.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ NamedEntity CoarrayRef::GetBase() const { return AsNamedEntity(base_); }
601601
// For the purposes of comparing type parameter expressions while
602602
// testing the compatibility of procedure characteristics, two
603603
// object dummy arguments with the same name are considered equal.
604-
bool AreSameSymbol(const Symbol &x, const Symbol &y) {
604+
static bool AreSameSymbol(const Symbol &x, const Symbol &y) {
605605
if (&x == &y) {
606606
return true;
607607
}
@@ -615,6 +615,17 @@ bool AreSameSymbol(const Symbol &x, const Symbol &y) {
615615
return false;
616616
}
617617

618+
// Implements operator==() for a union type, using special case handling
619+
// for Symbol references.
620+
template<typename A> static bool TestVariableEquality(const A &x, const A &y) {
621+
const SymbolRef *xSymbol{std::get_if<SymbolRef>(&x.u)};
622+
if (const SymbolRef * ySymbol{std::get_if<SymbolRef>(&y.u)}) {
623+
return xSymbol && AreSameSymbol(*xSymbol, *ySymbol);
624+
} else {
625+
return x.u == y.u;
626+
}
627+
}
628+
618629
bool BaseObject::operator==(const BaseObject &that) const {
619630
return TestVariableEquality(*this, that);
620631
}
@@ -638,6 +649,7 @@ bool Triplet::operator==(const Triplet &that) const {
638649
return lower_ == that.lower_ && upper_ == that.upper_ &&
639650
stride_ == that.stride_;
640651
}
652+
bool Subscript::operator==(const Subscript &that) const { return u == that.u; }
641653
bool ArrayRef::operator==(const ArrayRef &that) const {
642654
return base_ == that.base_ && subscript_ == that.subscript_;
643655
}
@@ -659,6 +671,14 @@ bool ComplexPart::operator==(const ComplexPart &that) const {
659671
bool ProcedureRef::operator==(const ProcedureRef &that) const {
660672
return proc_ == that.proc_ && arguments_ == that.arguments_;
661673
}
674+
template<typename T>
675+
bool Designator<T>::operator==(const Designator<T> &that) const {
676+
return TestVariableEquality(*this, that);
677+
}
678+
template<typename T>
679+
bool Variable<T>::operator==(const Variable<T> &that) const {
680+
return u == that.u;
681+
}
662682
bool DescriptorInquiry::operator==(const DescriptorInquiry &that) const {
663683
return field_ == that.field_ && base_ == that.base_ &&
664684
dimension_ == that.dimension_;

flang/lib/Semantics/resolve-labels.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ LabeledStatementInfoTuplePOD GetLabel(
818818
void CheckBranchesIntoDoBody(const SourceStmtList &branches,
819819
const TargetStmtMap &labels, const IndexList &loopBodies,
820820
SemanticsContext &context) {
821-
for (const auto branch : branches) {
821+
for (const auto &branch : branches) {
822822
const auto &label{branch.parserLabel};
823823
auto branchTarget{GetLabel(labels, label)};
824824
if (HasScope(branchTarget.proxyForScope)) {
@@ -870,7 +870,7 @@ void CheckLabelDoConstraints(const SourceStmtList &dos,
870870
const SourceStmtList &branches, const TargetStmtMap &labels,
871871
const std::vector<ProxyForScope> &scopes, SemanticsContext &context) {
872872
IndexList loopBodies;
873-
for (const auto stmt : dos) {
873+
for (const auto &stmt : dos) {
874874
const auto &label{stmt.parserLabel};
875875
const auto &scope{stmt.proxyForScope};
876876
const auto &position{stmt.parserCharBlock};
@@ -924,7 +924,7 @@ void CheckLabelDoConstraints(const SourceStmtList &dos,
924924
void CheckScopeConstraints(const SourceStmtList &stmts,
925925
const TargetStmtMap &labels, const std::vector<ProxyForScope> &scopes,
926926
SemanticsContext &context) {
927-
for (const auto stmt : stmts) {
927+
for (const auto &stmt : stmts) {
928928
const auto &label{stmt.parserLabel};
929929
const auto &scope{stmt.proxyForScope};
930930
const auto &position{stmt.parserCharBlock};
@@ -943,7 +943,7 @@ void CheckScopeConstraints(const SourceStmtList &stmts,
943943

944944
void CheckBranchTargetConstraints(const SourceStmtList &stmts,
945945
const TargetStmtMap &labels, SemanticsContext &context) {
946-
for (const auto stmt : stmts) {
946+
for (const auto &stmt : stmts) {
947947
const auto &label{stmt.parserLabel};
948948
auto branchTarget{GetLabel(labels, label)};
949949
if (HasScope(branchTarget.proxyForScope)) {
@@ -981,7 +981,7 @@ void CheckBranchConstraints(const SourceStmtList &branches,
981981

982982
void CheckDataXferTargetConstraints(const SourceStmtList &stmts,
983983
const TargetStmtMap &labels, SemanticsContext &context) {
984-
for (const auto stmt : stmts) {
984+
for (const auto &stmt : stmts) {
985985
const auto &label{stmt.parserLabel};
986986
auto ioTarget{GetLabel(labels, label)};
987987
if (HasScope(ioTarget.proxyForScope)) {

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3618,7 +3618,7 @@ void DeclarationVisitor::Post(const parser::TypeBoundProcedurePart &) {
36183618
// track specifics seen for the current generic to detect duplicates:
36193619
const Symbol *currGeneric{nullptr};
36203620
std::set<SourceName> specifics;
3621-
for (const auto [generic, bindingName] : genericBindings_) {
3621+
for (const auto &[generic, bindingName] : genericBindings_) {
36223622
if (generic != currGeneric) {
36233623
currGeneric = generic;
36243624
specifics.clear();

0 commit comments

Comments
 (0)