This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle @PROCESS directive
ClosedPublic

Authored by kkwli0 on May 18 2023, 9:42 AM.

Details

Summary

The legacy @PROCESS directive is supported in the IBM XLF compiler to allow specifying compiler option at the source level. This patch is to treat any line that starts with @process as a comment line. This allows code with the directive to be compiled without having syntax errors complaining it.

Diff Detail

Event Timeline

kkwli0 created this revision.May 18 2023, 9:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 9:42 AM
Herald added a subscriber: sunshaoce. · View Herald Transcript
kkwli0 requested review of this revision.May 18 2023, 9:42 AM
klausler added inline comments.May 18 2023, 9:53 AM
flang/docs/Extensions.md
366

Please note here that the directive is accepted but ignored.

flang/lib/Parser/prescan.cpp
780

Capitalize, please.

781

This should be static and it can be a char array, As coded, this will be a string potentially requiring dynamic allocation and deallocation on every call.

static const char pAtProc[]{"process"};

784

You really need to have a loop limit here to make sure that you don't run off the end of the string. As coded, this loop can index past the end of the string. Use sizeof pAtProcess as the string size.

790

Just return false; here.

829–833

return IsAtProcess(p) ? p : nullptr;

kkwli0 updated this revision to Diff 523548.May 18 2023, 2:07 PM
kkwli0 marked 6 inline comments as done.

Addressed review comments

klausler added inline comments.May 18 2023, 2:24 PM
flang/lib/Parser/prescan.cpp
782

std::size_t or auto

783

You can now write a more idiomatic for loop here.

for (std::size_t j{0}; j < len; ++j) {
  if (ToLowerCaseLetter(*++p) != pAtProc[j]) {
    return false;
  }
}
794

q is unnecessary.

if (*p == '@' && IsAtProcess(p)) {
  return true;
}
829

q is unnecessary.

kkwli0 marked 3 inline comments as done.May 18 2023, 3:04 PM
kkwli0 updated this revision to Diff 523577.May 18 2023, 3:11 PM

Address more comments. Thanks.

klausler accepted this revision.May 18 2023, 3:19 PM
klausler added inline comments.
flang/lib/Parser/prescan.cpp
783

The needless parentheses around ++p are more likely to confuse the reader of the code ("why is this parenthesized? what am I missing?") than to clarify matters.

This revision is now accepted and ready to land.May 18 2023, 3:19 PM
kkwli0 added inline comments.May 18 2023, 3:24 PM
flang/lib/Parser/prescan.cpp
783

I find it easier to read. Anyway, I will remove it. Thanks.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2023, 7:41 PM