Issue |
127426
|
Summary |
[Flang] Flang does not work correctly in file containing /* Old style C comments*/ in fixed source form
|
Labels |
flang:frontend
|
Assignees |
|
Reporter |
ohno-fj
|
```
Version of flang : 21.0.0(d2047242e6d0f0deb7634ff22ab164354c520c79)/AArch64
```
When building [Opium version 4.1](https://opium.sourceforge.net/), the preprocessor does not work correctly.
File containing `/* Old style C comments */` in `fixed source form` cannot be included.
According to [Fortran Extensions supported by Flang](https://flang.llvm.org/docs/Extensions.html#extensions-deletions-and-legacy-features-supported-by-default), the attached program is correct because:
- Classic C-style /*comments*/ are skipped, so multi-language header files are easier to write and use.
The above program is z001.F.
When `fixed source form` is changed to `free source form`, it is included correctly.
The above program is z002.F90.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
z001.F:
```fortran
subroutine foo ()
#include "inc.h"
integer :: i
i = VAL
print *,i
end subroutine foo
```
inc.h:
```fortran
/* Old style C comments
*comments
*/
#define VAL 1
```
```
$ flang z001.F -c
error: Could not parse z001.F
./inc.h:1:1: warning: Character in fixed-form label field must be a digit
/* Old style C comments
^
./z001.F:2:1: warning: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:2:2: warning: Character in fixed-form label field must be a digit
*comments
^
./z001.F:2:1: warning: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:3:2: warning: Character in fixed-form label field must be a digit
*/
^
./z001.F:2:1: warning: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:1:2: error: expected declaration construct
/* Old style C comments
^
./z001.F:2:1: error: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:1:1: in the context: specification part
/* Old style C comments
^
./z001.F:2:1: in the context: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./z001.F:1:7: in the context: SUBROUTINE subprogram
subroutine foo ()
^
./inc.h:2:3: error: expected declaration construct
*comments
^
./z001.F:2:1: error: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:1:1: in the context: specification part
/* Old style C comments
^
./z001.F:2:1: in the context: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./z001.F:1:7: in the context: SUBROUTINE subprogram
subroutine foo ()
^
./inc.h:3:3: error: expected declaration construct
*/
^
./z001.F:2:1: error: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./inc.h:1:1: in the context: specification part
/* Old style C comments
^
./z001.F:2:1: in the context: included here
#include "inc.h"
^^^^^^^^^^^^^^^^
./z001.F:1:7: in the context: SUBROUTINE subprogram
subroutine foo ()
^
$
```
```
$ gfortran z001.F -c -save-temps
$ cat z001.f90
# 1 "z001.F"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "z001.F"
subroutine foo ()
# 1 "inc.h" 1
# 3 "z001.F" 2
integer :: i
i = 1
print *,i
end subroutine foo
$
```
```
$ ifx z001.F -c -P
$ cat z001.i
# 1 "z001.F"
subroutine foo ()
# 1 "./inc.h" 1
# 3
# 3 "z001.F" 2
integer :: i
i = 1
print *,i
end subroutine foo
$
```
z002.F90:
```fortran
subroutine foo ()
#include "inc.h"
integer :: i
i = VAL
print *,i
end subroutine foo
```
```
$ flang z002.F90 -c
$
$ flang z002.F90 -c -save-temps
#line "./z002.F90" 1
subroutine foo ()
integer :: i
i = 1
print *,i
end subroutine foo
$
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs