This is an archive of the discontinued LLVM Phabricator instance.

[flang] Enforce a program not including more than one main program
ClosedPublic

Authored by peixin on May 8 2022, 7:11 AM.

Details

Summary

As Fortran 2018 5.2.2 states, a program shall consist of exactly one
main program. Add this semantic check.

Diff Detail

Event Timeline

peixin created this revision.May 8 2022, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2022, 7:11 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.May 8 2022, 7:11 AM
klausler added inline comments.May 8 2022, 7:41 AM
flang/lib/Semantics/resolve-names.cpp
7216

Don't use "unsigned" when "int" suffices.

Please use braced initialization, not "="; it's safer.

Please reference the applicable point in the Fortran standard that establishes this restriction (subclause 5.2.2)

There are probably better places for this check than resolve-names.cpp -- the file is already too large and this kind of error checking is not its purpose. You could put it in the program tree constructor, or (best) in check-declarations.cpp, which is where one would expect to find it.

The phrase "source file" would perhaps be more clear to the user than "program" in the error message.

peixin updated this revision to Diff 427942.May 8 2022, 9:04 AM

Thanks for @klausler 's comments. Doing this in check-declarations.cpp is better. Addressed the comments.

klausler accepted this revision.May 8 2022, 9:23 AM
klausler added inline comments.
flang/lib/Semantics/check-declarations.cpp
1719

In C++ it is best to use the prefix forms of ++ and --. It matters for many iterator types, so it's a good habit to get into. The postfix forms of ++ and -- should be used only in the context of an expression that really depends on using the "old" value of the variable.

1721

Please check that this message is associated with the right source code location.

This revision is now accepted and ready to land.May 8 2022, 9:23 AM
peixin updated this revision to Diff 427963.May 8 2022, 6:09 PM

Add the source code location for error message to make it more readable.

peixin added inline comments.May 8 2022, 6:11 PM
flang/lib/Semantics/check-declarations.cpp
1719

Thanks for the explanation. Fixed.

1721

Now, it is associated with the right source code location.

This revision was landed with ongoing or failed builds.May 8 2022, 7:50 PM
This revision was automatically updated to reflect the committed changes.