[flang-commits] [flang] [flang][preprocessing] Mix preprocessing directives with free form li… (PR #96244)

via flang-commits flang-commits at lists.llvm.org
Fri Jun 21 14:10:08 PDT 2024


foxtran wrote:

One more funny example with Fortran include statement:
test.f90:
```fortran
      program main
#define ERROR 1
      include "inc.f"
     &.44
      end program main
```
inc.f:
```fortran
#ifndef ERROR
print 5.&
#else
#error "Hi from LLVM"
#endif
```

`gfortran -cpp -E` produces:
```
# 1 "test.f90"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.f90"
      program main

      include "inc.f"
     &.44
      end program main
```
`ifx -cpp -E` produces (but, in general, it fails):
```
# 1 "test.f90"
      program main

      include "inc.f"
     &.44
      end program main
```

However, flang passes ERROR into Fortran-include statement that gives:
```
error: Could not scan test.f90
./inc.f:4:2: error: #error "Hi from LLVM"
  #error "Hi from LLVM"
   ^^^^^^^^^^^^^^^^^^^^
./test.f90:3:1: error: included here
        include "inc.f"
  ^^^^^^^^^^^^^^^^^^^^^
```

https://github.com/llvm/llvm-project/pull/96244


More information about the flang-commits mailing list