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. Differential Revision: https://reviews.llvm.org/D155499
19 lines
446 B
Fortran
19 lines
446 B
Fortran
! RUN: %flang -E %s 2>&1 | FileCheck %s
|
|
! CHECK: res = ((666)+111)
|
|
! FLM call with closing ')' on next line (not a continuation)
|
|
integer function IFLM(x)
|
|
integer :: x
|
|
IFLM = x
|
|
end function IFLM
|
|
program main
|
|
#define IFLM(x) ((x)+111)
|
|
integer :: res
|
|
res = IFLM(666
|
|
)
|
|
if (res .eq. 777) then
|
|
print *, 'pp127.F90 yes'
|
|
else
|
|
print *, 'pp127.F90 no: ', res
|
|
end if
|
|
end
|