This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix an assertion error when a BOZ literal is used as a relational operator
ClosedPublic

Authored by PeteSteinfeld on Jul 15 2020, 4:04 PM.

Details

Summary

Expressions like iVar==z'fe' were causing an assertion error because the Relate()
function in Evaluate/tools.cpp that processes relational operators didn't
deal with BOZ literals, which are typeless. I fixed this by checking to see if
the operands are BOZ literals. If so, I convert them to integers with default
kind. To get the default kind, I needed to pass a new parameter to Relate().

I also added a test to resolve63.f90 that triggers the problem.

Also, when I ran the latest clang-format on Evaluate/tools.cpp, it
reformatted a comment which was coincidentally related to BOZ literals. This
change is unrelated to the rest of the code.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.Jul 15 2020, 4:04 PM
Herald added a project: Restricted Project. · View Herald Transcript
PeteSteinfeld added a project: Restricted Project.Jul 15 2020, 4:04 PM
tskeith added inline comments.Jul 15 2020, 4:43 PM
flang/lib/Evaluate/tools.cpp
486 ↗(On Diff #278333)

Evaluate is not supposed to have link-time dependencies on Semantics (I think) so calling GetDefaultKind is bad here. Instead of passing in SemanticsContext, I think you could pass in (a reference to) the common::IntrinsicTypeDefaultKinds that is stored in SemanticsContext.

492 ↗(On Diff #278333)

I get a warning from clang 9 that this call to std::move and the one on line 485 are not needed.

DavidTruby resigned from this revision.Jul 16 2020, 8:08 AM

I discovered that there was another dereference of the nullopt type of a BOZ
literal. In order to catch both dereferences, I convert all BOZ literals that
are operands in a relational expression to INTEGERs. In practice, this means
that comparisons to numeric types do not produce errors while a comparison to a
CHARACTER or LOGICAL operand does produce an error. This behavior matches most
of the other compilers I tested. The exception is IBM's compiler, which allows
comparisons between BOZ literals and CHARACTER operands.

PeteSteinfeld retitled this revision from [flang] Fix a crash when a BOZ literal is used as a relational operator to [flang] Fix an assertion error when a BOZ literal is used as a relational operator.Jul 20 2020, 11:04 AM
PeteSteinfeld edited the summary of this revision. (Show Details)

I handled comparing BOZ literals to REAL operands in the same way as the rest
of the compiler. I also now handle comparing a BOZ literal to another BOZ
literal.

tskeith accepted this revision.Jul 23 2020, 7:39 AM
This revision is now accepted and ready to land.Jul 23 2020, 7:39 AM
This revision was automatically updated to reflect the committed changes.
This comment was removed by klausler.