This is an archive of the discontinued LLVM Phabricator instance.

[flang] Honor #line and related preprocessing directives
ClosedPublic

Authored by klausler on Jun 27 2023, 12:40 PM.

Details

Summary

Extend the SourceFile class to take account of #line directives
when computing source file positions for error messages.
Adjust the output of #line directives to -E output so that they
reflect any #line directives that were in the input.

Diff Detail

Event Timeline

klausler created this revision.Jun 27 2023, 12:40 PM
tschuett added inline comments.
flang/include/flang/Parser/source.h
89

llvm::StringSet?

flang/lib/Parser/provenance.cpp
533

llvm::SmallPtrSet?

klausler updated this revision to Diff 535158.Jun 27 2023, 3:28 PM

Update FlangOmpReportVisitor.cpp.

LGTM.
Thank you for your patch.
I tested it, and it solves all issues connected with -save-temps flag, which were mentioned on LLVM discourse.
Could you fix one check statement in flang/test/Parser/line-directive.f90 which fails on Windows?

flang/include/flang/Parser/source.h
75

nit: llvm::StringRef?

flang/test/Parser/line-directive.f90
3

This check fails on Windows.

Input was:
<<<<<<
           1: #line "C:\ws\w3\llvm-project\premerge-checks\flang\test\Parser\line-directive.f90" 3
check:2'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:2'1                                                             ?                             possible intended match
           2:  subroutine s
check:2'0     ~~~~~~~~~~~~~~
           3:  implicit none
check:2'0     ~~~~~~~~~~~~~~~
           4:  a = 1.
check:2'0     ~~~~~~~~
           5: #line 101
check:2'0     ~~~~~~~~~~
           6:  b = 2.
check:2'0     ~~~~~~~~
           .
           .
           .
>>>>>>

Source: https://buildkite.com/llvm-project/premerge-checks/builds/160946#0188fefb-5134-482b-bece-1e8c7632b903 log line: 6653

flang/lib/Parser/preprocessor.cpp
1131

Nit: thisTrueLineNumber is unused.

klausler added inline comments.Jun 28 2023, 8:03 AM
flang/include/flang/Parser/source.h
75

I use only standard C++ library features in parts of the compiler that people may want to use to build tooling outside the LLVM ecosystem, when those features are universally portable.

flang/lib/Parser/preprocessor.cpp
1131

It is now indeed superfluous; thanks for noticing.

flang/test/Parser/line-directive.f90
3

DOS backslashes strike again. Will fix.

klausler updated this revision to Diff 535416.Jun 28 2023, 8:06 AM

Address review comments.

Why? Nobody stops you from building flang-tools-extras with LSP-servers, refactoring, Flang-tidy you name it. Flang is in the LLVM monorepo. Why do you refuse to use LLVM data structures?

LGTM.
Thank you for your patch.
I tested it, and it solves all issues connected with -save-temps flag, which were mentioned on LLVM discourse.

This kind of testing is the most useful kind of code review; thanks for confirming that your problem will be solved. I've updated the patch and it should now clear the pre-merge testing.

klausler updated this revision to Diff 535448.Jun 28 2023, 9:51 AM

Fix FileCheck regular expression for real this time; sorry for the distraction.

The pre-merge testing bug has been resolved. Please approve when convenient; thanks!

LG. Thanks, this helps unblock engineers working on OpenMP target offloading.

This revision is now accepted and ready to land.Jun 29 2023, 2:19 AM
domada accepted this revision.Jun 29 2023, 4:12 AM

LGTM

This revision was automatically updated to reflect the committed changes.