Skip to content

Commit

Permalink
[flang] Fix non-deterministic line output function
Browse files Browse the repository at this point in the history
The evaluation order for the `|` operator is undefined
(in contrast to the short-circuiting `||` operator). The arguments are
stored in variables to force a specific evaluation order.

A test in D107575 relies on this change.

Reviewed By: kiranchandramohan, klausler

Differential Revision: https://reviews.llvm.org/D108623
  • Loading branch information
Ivan Zhechev committed Sep 2, 2021
1 parent 14e1a4a commit e962718
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions flang/lib/Semantics/check-declarations.cpp
Expand Up @@ -1152,6 +1152,12 @@ bool CheckHelper::CheckDefinedOperator(SourceName opName, GenericKind kind,
return false;
}
std::optional<parser::MessageFixedText> msg;
auto checkDefinedOperatorArgs{
[&](SourceName opName, const Symbol &specific, const Procedure &proc) {
bool arg0Defined{CheckDefinedOperatorArg(opName, specific, proc, 0)};
bool arg1Defined{CheckDefinedOperatorArg(opName, specific, proc, 1)};
return arg0Defined && arg1Defined;
}};
if (specific.attrs().test(Attr::NOPASS)) { // C774
msg = "%s procedure '%s' may not have NOPASS attribute"_err_en_US;
} else if (!proc.functionResult.has_value()) {
Expand All @@ -1161,8 +1167,7 @@ bool CheckHelper::CheckDefinedOperator(SourceName opName, GenericKind kind,
" result"_err_en_US;
} else if (auto m{CheckNumberOfArgs(kind, proc.dummyArguments.size())}) {
msg = std::move(m);
} else if (!CheckDefinedOperatorArg(opName, specific, proc, 0) |
!CheckDefinedOperatorArg(opName, specific, proc, 1)) {
} else if (!checkDefinedOperatorArgs(opName, specific, proc)) {
return false; // error was reported
} else if (ConflictsWithIntrinsicOperator(kind, proc)) {
msg = "%s function '%s' conflicts with intrinsic operator"_err_en_US;
Expand Down

0 comments on commit e962718

Please sign in to comment.