Skip to content

Commit e962718

Browse files
author
Ivan Zhechev
committed
[flang] Fix non-deterministic line output function
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
1 parent 14e1a4a commit e962718

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,12 @@ bool CheckHelper::CheckDefinedOperator(SourceName opName, GenericKind kind,
11521152
return false;
11531153
}
11541154
std::optional<parser::MessageFixedText> msg;
1155+
auto checkDefinedOperatorArgs{
1156+
[&](SourceName opName, const Symbol &specific, const Procedure &proc) {
1157+
bool arg0Defined{CheckDefinedOperatorArg(opName, specific, proc, 0)};
1158+
bool arg1Defined{CheckDefinedOperatorArg(opName, specific, proc, 1)};
1159+
return arg0Defined && arg1Defined;
1160+
}};
11551161
if (specific.attrs().test(Attr::NOPASS)) { // C774
11561162
msg = "%s procedure '%s' may not have NOPASS attribute"_err_en_US;
11571163
} else if (!proc.functionResult.has_value()) {
@@ -1161,8 +1167,7 @@ bool CheckHelper::CheckDefinedOperator(SourceName opName, GenericKind kind,
11611167
" result"_err_en_US;
11621168
} else if (auto m{CheckNumberOfArgs(kind, proc.dummyArguments.size())}) {
11631169
msg = std::move(m);
1164-
} else if (!CheckDefinedOperatorArg(opName, specific, proc, 0) |
1165-
!CheckDefinedOperatorArg(opName, specific, proc, 1)) {
1170+
} else if (!checkDefinedOperatorArgs(opName, specific, proc)) {
11661171
return false; // error was reported
11671172
} else if (ConflictsWithIntrinsicOperator(kind, proc)) {
11681173
msg = "%s function '%s' conflicts with intrinsic operator"_err_en_US;

0 commit comments

Comments
 (0)