Skip to content

Commit 93f8179

Browse files
Fix Klausler reported review comments
Also rebase, as the branch was quite a way behind. Small conflict was resolved.
1 parent 17a400b commit 93f8179

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

flang/include/flang/Semantics/symbol.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,11 @@ class UserReductionDetails {
715715

716716
UserReductionDetails() = default;
717717

718-
void AddType(const DeclTypeSpec *type) { typeList_.push_back(type); }
718+
void AddType(const DeclTypeSpec &type) { typeList_.push_back(&type); }
719719
const TypeVector &GetTypeList() const { return typeList_; }
720720

721-
bool SupportsType(const DeclTypeSpec *type) const {
722-
return llvm::is_contained(typeList_, type);
721+
bool SupportsType(const DeclTypeSpec &type) const {
722+
return llvm::is_contained(typeList_, &type);
723723
}
724724

725725
void AddDecl(const DeclInfo &decl) { declList_.push_back(decl); }

flang/lib/Semantics/check-omp-structure.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -3404,8 +3404,7 @@ bool OmpStructureChecker::CheckReductionOperator(
34043404
valid =
34053405
llvm::is_contained({"max", "min", "iand", "ior", "ieor"}, realName);
34063406
if (!valid) {
3407-
auto *reductionDetails{name->symbol->detailsIf<UserReductionDetails>()};
3408-
valid = reductionDetails != nullptr;
3407+
valid = name->symbol->detailsIf<UserReductionDetails>();
34093408
}
34103409
}
34113410
if (!valid) {
@@ -3534,7 +3533,7 @@ static bool IsReductionAllowedForType(
35343533
const auto *reductionDetails{symbol->detailsIf<UserReductionDetails>()};
35353534
assert(reductionDetails && "Expected to find reductiondetails");
35363535

3537-
return reductionDetails->SupportsType(&type);
3536+
return reductionDetails->SupportsType(type);
35383537
}
35393538
return false;
35403539
}
@@ -3571,7 +3570,7 @@ static bool IsReductionAllowedForType(
35713570
// supported.
35723571
if (const auto *reductionDetails{
35733572
name->symbol->detailsIf<UserReductionDetails>()}) {
3574-
return reductionDetails->SupportsType(&type);
3573+
return reductionDetails->SupportsType(type);
35753574
}
35763575

35773576
// We also need to check for mangled names (max, min, iand, ieor and ior)
@@ -3580,7 +3579,7 @@ static bool IsReductionAllowedForType(
35803579
if (const auto &symbol{scope.FindSymbol(mangledName)}) {
35813580
if (const auto *reductionDetails{
35823581
symbol->detailsIf<UserReductionDetails>()}) {
3583-
return reductionDetails->SupportsType(&type);
3582+
return reductionDetails->SupportsType(type);
35843583
}
35853584
}
35863585
}

flang/lib/Semantics/mod-file.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -1039,20 +1039,23 @@ void ModFileWriter::PutTypeParam(llvm::raw_ostream &os, const Symbol &symbol) {
10391039

10401040
void ModFileWriter::PutUserReduction(
10411041
llvm::raw_ostream &os, const Symbol &symbol) {
1042-
auto &details{symbol.get<UserReductionDetails>()};
1042+
const auto &details{symbol.get<UserReductionDetails>()};
10431043
// The module content for a OpenMP Declare Reduction is the OpenMP
10441044
// declaration. There may be multiple declarations.
10451045
// Decls are pointers, so do not use a referene.
10461046
for (const auto decl : details.GetDeclList()) {
1047-
if (auto d = std::get_if<const parser::OpenMPDeclareReductionConstruct *>(
1048-
&decl)) {
1049-
Unparse(os, **d);
1050-
} else if (auto s = std::get_if<const parser::OmpMetadirectiveDirective *>(
1051-
&decl)) {
1052-
Unparse(os, **s);
1053-
} else {
1054-
DIE("Unknown OpenMP DECLARE REDUCTION content");
1055-
}
1047+
common::visit( //
1048+
common::visitors{//
1049+
[&](const parser::OpenMPDeclareReductionConstruct *d) {
1050+
Unparse(os, *d);
1051+
},
1052+
[&](const parser::OmpMetadirectiveDirective *m) {
1053+
Unparse(os, *m);
1054+
},
1055+
[&](const auto &) {
1056+
DIE("Unknown OpenMP DECLARE REDUCTION content");
1057+
}},
1058+
decl);
10561059
}
10571060
}
10581061

flang/lib/Semantics/resolve-names-utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void MapSubprogramToNewSymbols(const Symbol &oldSymbol, Symbol &newSymbol,
149149
parser::CharBlock MakeNameFromOperator(
150150
const parser::DefinedOperator::IntrinsicOperator &op,
151151
SemanticsContext &context);
152-
parser::CharBlock MangleSpecialFunctions(const parser::CharBlock name);
152+
parser::CharBlock MangleSpecialFunctions(const parser::CharBlock &name);
153153

154154
} // namespace Fortran::semantics
155155
#endif // FORTRAN_SEMANTICS_RESOLVE_NAMES_H_

flang/lib/Semantics/resolve-names.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -1442,11 +1442,15 @@ class OmpVisitor : public virtual DeclarationVisitor {
14421442
static bool NeedsScope(const parser::OpenMPBlockConstruct &);
14431443
static bool NeedsScope(const parser::OmpClause &);
14441444

1445-
bool Pre(const parser::OmpMetadirectiveDirective &) {
1445+
bool Pre(const parser::OmpMetadirectiveDirective &x) { //
1446+
metaDirective_ = &x;
14461447
++metaLevel_;
14471448
return true;
14481449
}
1449-
void Post(const parser::OmpMetadirectiveDirective &) { --metaLevel_; }
1450+
void Post(const parser::OmpMetadirectiveDirective &) { //
1451+
metaDirective_ = nullptr;
1452+
--metaLevel_;
1453+
}
14501454

14511455
bool Pre(const parser::OpenMPRequiresConstruct &x) {
14521456
AddOmpSourceRange(x.source);
@@ -1655,14 +1659,6 @@ class OmpVisitor : public virtual DeclarationVisitor {
16551659
EndDeclTypeSpec();
16561660
}
16571661

1658-
bool Pre(const parser::OmpMetadirectiveDirective &x) { //
1659-
metaDirective_ = &x;
1660-
return true;
1661-
}
1662-
void Post(const parser::OmpMetadirectiveDirective &) { //
1663-
metaDirective_ = nullptr;
1664-
}
1665-
16661662
private:
16671663
void ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
16681664
const parser::OmpClauseList &clauses);
@@ -1793,7 +1789,7 @@ parser::CharBlock MakeNameFromOperator(
17931789
}
17941790
}
17951791

1796-
parser::CharBlock MangleSpecialFunctions(const parser::CharBlock name) {
1792+
parser::CharBlock MangleSpecialFunctions(const parser::CharBlock &name) {
17971793
return llvm::StringSwitch<parser::CharBlock>(name.ToString())
17981794
.Case("max", {"op.max", 6})
17991795
.Case("min", {"op.min", 6})
@@ -1888,7 +1884,7 @@ void OmpVisitor::ProcessReductionSpecifier(
18881884
// Only process types we can find. There will be an error later on when
18891885
// a type isn't found.
18901886
if (const DeclTypeSpec * typeSpec{GetDeclTypeSpec()}) {
1891-
reductionDetails->AddType(typeSpec);
1887+
reductionDetails->AddType(*typeSpec);
18921888

18931889
for (auto &nm : ompVarNames) {
18941890
ObjectEntityDetails details{};

0 commit comments

Comments
 (0)