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 error parsing fixed form fortran source with -save-temps #117712

Open
macurtis-amd opened this issue Nov 26, 2024 · 2 comments
Open

Flang error parsing fixed form fortran source with -save-temps #117712

macurtis-amd opened this issue Nov 26, 2024 · 2 comments
Assignees
Labels
flang Flang issues not falling into any other category

Comments

@macurtis-amd
Copy link
Contributor

macurtis-amd commented Nov 26, 2024

Here is the problematic fixed form fortran source reduced.f:

      subroutine foo(a, b)
      if ( (a  .eq. 0) .and.
     >     (b . eq. 1) ) then
         print *, "foo"
      end if
      end subroutine

Prior to 9fb2db1 flang -save-temps -c produced reduced.i:

      subroutine foo(a, b)
      if ( (a  .eq. 0) .and.(b.eq.1))then

         print *, "foo"
      end if
      end subroutine

With 9fb2db1, flang -save-temps -c produces reduced.i:

      subroutine foo(a, b)
      if ( (a  .eq. 0) .and.(b. eq. 1)) then

         print *, "foo"
      end if
      end subroutine

Which produces:

error: Could not parse reduced.i
./reduced.f:2:31: error: expected ')'
        if ( (a  .eq. 0) .and.(b. eq. 1)) then
                                ^
...

In either case the commands produced by the driver look like:

flang-new -fc1 -E -o reduced.i -x f95-cpp-input reduced.f
flang-new -fc1 -emit-llvm-bc ... -o reduced.bc -x f95 reduced.i
...
@github-actions github-actions bot added the flang Flang issues not falling into any other category label Nov 26, 2024
@macurtis-amd macurtis-amd self-assigned this Nov 26, 2024
@klausler
Copy link
Contributor

The -x f95-cpp-input option doesn't seem appropriate for a .f source file.

@DavidTruby
Copy link
Member

Conceptually we don't need the existing -x f95... distinction anyway, I believe it's just there for gfortran compatibility. As far as we're concerned it really means -x fortran because we decide on fixed vs free form elsewhere, and we don't care about preprocessed vs non-preprocessed input as the flang preprocessor always runs as part of parsing regardless.

I posted the following on the PR, cross-posting here for visibility:
It feels wrong that -save-temps runs the preprocessor separately anyway for flang. There's no "temp" generated by the flang preprocessor as preprocessing is not a separate step to parsing. We don't appear to need to do this for compatibility with gfortran either because gfortran doesn't appear to save a preprocessed file with -save-temps (at least on my system). Even if we do chose to have -save-temps save a preprocessed file for some reason, I think .i is the wrong extension as that's usually used for C/C++ preprocessed files.
Does your use case specifically require -save-temps to save a preprocessed file, and if so does it have to have the .i extension? If not, I'd propose we modify -save-temps to not preprocess separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants