Peter Klausler 4dceb25dd1
[flang] Don't create bogus tokens from token pasting (##) (#147596)
When blank tokens arise from macro replacement in token sequences with
token pasting (##), the preprocessor is producing some bogus tokens
(e.g., "name(") that can lead to subtle bugs later when macro names are
not recognized as such.

The fix is to not paste tokens together when the result would not be a
valid Fortran or C token in the preprocessing context.
2025-07-14 11:11:43 -07:00

21 lines
603 B
Fortran

! RUN: %flang -E %s 2>&1 | FileCheck %s
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define PREFIX(x) prefix ## x
#define NAME(x) PREFIX(foo ## x)
#define AUGMENT(x) NAME(x ## suffix)
! CHECK: subroutine prefixfoosuffix()
! CHECK: print *, "prefixfoosuffix"
! CHECK: end subroutine prefixfoosuffix
subroutine AUGMENT()()
print *, TOSTRING(AUGMENT())
end subroutine AUGMENT()
! CHECK: subroutine prefixfoobarsuffix()
! CHECK: print *, "prefixfoobarsuffix"
! CHECK: end subroutine prefixfoobarsuffix
subroutine AUGMENT(bar)()
print *, TOSTRING(AUGMENT(bar))
end subroutine AUGMENT(bar)