This is an archive of the discontinued LLVM Phabricator instance.

[PoC][Flang] Process "line" Flang preprocessor directive
AbandonedPublic

Authored by domada on Jun 20 2023, 3:56 AM.

Details

Summary

Flang "line" preprocessor directive contains information about original source file. Currently this information is missed when user compiles code with -save-temps flag. In consequence we observe:

  1. Different location of the syntax error. If -save-temps flag is attached then Flang reports error in the preprocessed file
  2. Different debug info. If -save-temps flag is attached then debug info points to preprocessed code (not to the original source file)
  3. Mismatch of OpenMP offloading functions names when -save-temps flag is attached because OpenMP offloading function names depend on the name of the source file. For target offloading Flang generates two preprocessed files (for host and the device).

This patch aims to solve these issues by adding support of Flang "line" directive. "line" directive holds information about original source file. If we process "line" directive then we can be sure that the location of the tokens is independent from the status of -save-temps flag.

Detailed discussion about Flang preprocessor and the issues related to token location for Flang and -save-temps file can be found here: https://discourse.llvm.org/t/rfc-flang-improve-debug-information-user-error-messages-and-fix-openmp-function-mismatch-for-save-temps-flag/71417

Diff Detail

Event Timeline

domada created this revision.Jun 20 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald Transcript
domada requested review of this revision.Jun 20 2023, 3:56 AM
flang/lib/Parser/preprocessor.cpp
421–422

Nit: Use braced initialization in the frontend here and elsewhere where it is applicable.

flang/test/Driver/save-temps-token-localization.f90
1

We need a test to show that this works as well.

domada retitled this revision from [PoC][Flang] Use preprocessor line directive to add more accurate token localization for -save-temps flag to [PoC][Flang] Process "line" Flang preprocessor directive.Jun 20 2023, 6:07 AM
domada edited the summary of this revision. (Show Details)
klausler added inline comments.Jun 20 2023, 6:37 AM
flang/lib/Parser/preprocessor.cpp
467

Please check my understanding. Are you in fact trying to implement the '#line' preprocessing directive by actually *reading* the original file and prescanning it again to replace the content of the '*.I' file? And doing so without any of the original search path or predefined macro or line length or source format options?

domada added inline comments.Jun 20 2023, 7:55 AM
flang/lib/Parser/preprocessor.cpp
467

Hi,
thank you for your feedback. Could you provide some links to the resources/documentation/discussion about Flang preprocessor which will be helpful for implementation of the "line" directive? Could we modify the "line" directive in similar way to the linenum for GCC : https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_9.html ?

I called this patch as PoC just to get feedback if my approach is feasible. My goal is to force Flang to use original location of the tokens for -save-temps flag. Currently Flang use tokens from the preprocessor if the -save-temps flag is set. It causes several issues which does not appear in Clang. Please read the discussion: https://discourse.llvm.org/t/rfc-flang-improve-debug-information-user-error-messages-and-fix-openmp-function-mismatch-for-save-temps-flag/71417 to get more details about the issues connected with -save-temps flag.

klausler added inline comments.Jun 20 2023, 8:54 AM
flang/lib/Parser/preprocessor.cpp
467

My comment was a question, not "feedback", but I suppose the answer is a "yes". If so, this is not the right approach.

See https://reviews.llvm.org/D153910 for an implementation of #line.

domada abandoned this revision.Jul 6 2023, 1:26 AM

Patch not needed. Feature already implemented by https://reviews.llvm.org/D153910