[flang-commits] [PATCH] D155499: [flang] Stricter "implicit continuation" in preprocessing

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 17 10:33:37 PDT 2023


klausler created this revision.
klausler added a reviewer: rogfer01.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

The prescanner performs implicit line continuation when it looks   
like the parenthesized arguments of a call to a function-like macro
may span multiple lines.  In an attempt to work more like a
Fortran-oblivious C preprocessor, the prescanner will act as if
the following lines had been continuations so that the function-like
macro could be invoked.

This still seems like a good idea, but a recent bug report on
LLVM's GitHub issue tracker shows one way in which it could trigger
inadvertently and mess up a program.  So this patch makes the
conditions for implicit line continuation much more strict.

First, the leading parenthesis has to have been preceded by an  
identifier that's known to be a macro name.  (It doesn't have to
be a function-like macro, since it's possible for a keyword-like
macro to expand to the name of a function-like macro.)  Second,
no macro definition can ever have had unbalanced parentheses in
its replacement text.

Also cleans up some parenthesis recognition code to fix some
issues found in testing, so that a token with leading or trailing
spaces can still be recognized as a parenthesis or comma.

Fixes https://github.com/llvm/llvm-project/issues/63844.


https://reviews.llvm.org/D155499

Files:
  flang/docs/Preprocessing.md
  flang/include/flang/Parser/char-block.h
  flang/lib/Parser/preprocessor.cpp
  flang/lib/Parser/preprocessor.h
  flang/lib/Parser/prescan.cpp
  flang/lib/Parser/prescan.h
  flang/lib/Parser/token-sequence.cpp
  flang/test/Lower/array-elemental-calls-3.f90
  flang/test/Preprocessing/implicit-contin1.F90
  flang/test/Preprocessing/implicit-contin2.F90
  flang/test/Preprocessing/implicit-contin3.F90
  flang/test/Preprocessing/pp127.F90
  flang/test/Semantics/array-constr-big.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155499.541128.patch
Type: text/x-patch
Size: 14772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230717/f869d8ba/attachment-0001.bin>


More information about the flang-commits mailing list