Skip to content

[flang] Flang fails to scan a Fortran file with preprocessor macros #114064

@inaki-amatria

Description

@inaki-amatria
  • flang version is: flang version 20.0.0git (https://github.com/llvm/llvm-project.git 6233346895abfb57782511cddc263d439fdd537b)
  • Reduced test case:
! foo.F
#define BAR(A, B) ((A) * 10000 + (B) * 100)
#define FOO(A, B, C, AA, BB) ( \
  (defined(AA) && defined(BB)) && \
  (BAR(A, B) C BAR(AA, BB)))

#if FOO(9, 5, >, BAZ, FUX)
#endif
  • flang invocation is: flang -c foo.F
  • Expected behavior is: The code compiles successfully.
  • Actual behavior: Compilation aborts with the following error:
error: Could not scan foo.F
foo.F:6:5: error: expected ')'
  #if FOO(9, 5, >, BAZ, FUX)
      ^^^^^^
foo.F:2:30: in a macro defined here
  #define FOO(A, B, C, AA, BB) ( \
                               ^^
that expanded to:
  ( (defined(BAZ) && defined(FUX)) && (((9) * 10000 + ( 5) * 100) > ((BAZ) * 10000 + ( FUX) * 100)))
            ^
  • Additional info: The following, further reduced, test case also reproduces the issue:
#define FOO() (defined(BAR))

#if FOO()
#endif

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions