Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang] Preprocessor error when the name to be replaced contains trailing blank in a continuation line #106931

Closed
ohno-fj opened this issue Sep 1, 2024 · 2 comments · Fixed by #107010
Assignees

Comments

@ohno-fj
Copy link

ohno-fj commented Sep 1, 2024

Version of flang-new : 20.0.0(675c748bb606d75a959481e6014299849cf3094c)/AArch64

When building elpa, the preprocessor does not work correctly.
When the name to be replaced contains trailing blank in a continuation line, the preprocessor does not replace that name correctly.
When it does not contain blank, the name is replaced correctly.

The following are the test program, Flang-new compilation result.

test.F90:

#define PRECISION 8
subroutine foo_&
&PRECISION &
&(a,b)
  real(kind=8) :: a, b
  a = a + b
end subroutine foo_&
&PRECISION
$ flang-new -c -cpp test.F90
error: Semantic errors in test.F90
./test.F90:7:16: error: SUBROUTINE name mismatch
  end subroutine foo_&
                 ^
./test.F90:2:12: should be
  subroutine foo_&
             ^
$
$ flang-new -c -cpp -save-temps test.F90
error: Semantic errors in test.i
./test.F90:7:22: error: SUBROUTINE name mismatch
        end subroutine foo_8
                       ^^^^^
./test.F90:2:18: should be
        subroutine foo_PRECISION(a,b)
                   ^^^^^^^^^^^^^
$
$ cat test.i
#line "./test.F90" 2
      subroutine foo_PRECISION(a,b)


      real(kind=8) :: a, b
      a = a + b
      end subroutine foo_8
$

test2.F90:

#define PRECISION 8
subroutine foo_&
&PRECISION&
&(a,b)
!&PRECISION &
!&(a,b)
  real(kind=8) :: a, b
  a = a + b
end subroutine foo_&
&PRECISION
$ flang-new -c -cpp test2.F90
$
@ohno-fj ohno-fj added the flang Flang issues not falling into any other category label Sep 1, 2024
@EugeneZelenko EugeneZelenko added flang:frontend and removed flang Flang issues not falling into any other category labels Sep 1, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 1, 2024

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 20.0.0(675c748)/AArch64 ```

When building elpa, the preprocessor does not work correctly.
When the name to be replaced contains trailing blank in a continuation line, the preprocessor does not replace that name correctly.
When it does not contain blank, the name is replaced correctly.

The following are the test program, Flang-new compilation result.

test.F90:

#define PRECISION 8
subroutine foo_&
&PRECISION &
&(a,b)
  real(kind=8) :: a, b
  a = a + b
end subroutine foo_&
&PRECISION
$ flang-new -c -cpp test.F90
error: Semantic errors in test.F90
./test.F90:7:16: error: SUBROUTINE name mismatch
  end subroutine foo_&
                 ^
./test.F90:2:12: should be
  subroutine foo_&
             ^
$
$ flang-new -c -cpp -save-temps test.F90
error: Semantic errors in test.i
./test.F90:7:22: error: SUBROUTINE name mismatch
        end subroutine foo_8
                       ^^^^^
./test.F90:2:18: should be
        subroutine foo_PRECISION(a,b)
                   ^^^^^^^^^^^^^
$
$ cat test.i
#line "./test.F90" 2
      subroutine foo_PRECISION(a,b)


      real(kind=8) :: a, b
      a = a + b
      end subroutine foo_8
$

test2.F90:

#define PRECISION 8
subroutine foo_&
&PRECISION&
&(a,b)
!&PRECISION &
!&(a,b)
  real(kind=8) :: a, b
  a = a + b
end subroutine foo_&
&PRECISION
$ flang-new -c -cpp test2.F90
$

@klausler klausler self-assigned this Sep 2, 2024
klausler added a commit to klausler/llvm-project that referenced this issue Sep 2, 2024
Codes using traditional C preprocessors will sometimes put a keyword
macro name in a free form continuation line in order to get macro
replacement of part of an identifier, as in

  call subr_&
    &N&
    &(1.)

where N is a keyword macro.  f18 already handles this case, but not
when there is white space between the macro name and the following
continuation marker character '&'.  Allow white space to appear.

Fixes llvm#106931.
@klausler
Copy link
Contributor

klausler commented Sep 2, 2024

#107010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants