This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Allow compile *.f03, *.f08 file
ClosedPublic

Authored by sunshaoce on Mar 11 2023, 6:10 AM.

Diff Detail

Event Timeline

sunshaoce created this revision.Mar 11 2023, 6:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2023, 6:10 AM
sunshaoce requested review of this revision.Mar 11 2023, 6:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2023, 6:10 AM
sunshaoce edited the summary of this revision. (Show Details)Mar 11 2023, 6:11 AM

Thanks. Can you add tests in flang/test/Driver?

clementval added a project: Restricted Project.Mar 11 2023, 6:21 AM

Thanks!

Thanks. Can you add tests in flang/test/Driver?

Hm, this is a clangDriver change rather than anything Flang specific 🤔 . Btw, how does https://github.com/llvm/llvm-project/issues/61260 manifest to you? I'm trying to figure out how to best test it (I couldn't find any other tests for this specifically).

Thanks!

Thanks. Can you add tests in flang/test/Driver?

Hm, this is a clangDriver change rather than anything Flang specific 🤔 . Btw, how does https://github.com/llvm/llvm-project/issues/61260 manifest to you? I'm trying to figure out how to best test it (I couldn't find any other tests for this specifically).

Cannot we just have a a .f03 file and compile it and see if we have an executable?

Before

$ /home/sunshaoce/dev/llvm-project/build/bin/flang-new /home/sunshaoce/dev/llvm-project/build/temp.f03 -flang-experimental-exec -o temp.out -###
flang-new version 17.0.0 (https://github.com/llvm/llvm-project.git 890e6c871d31dca9e461c01118cf25fb303b9cad)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sunshaoce/dev/llvm-project/build/bin
 "/usr/bin/ld" "-pie" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "temp.out" "/lib/x86_64-linux-gnu/Scrt1.o" "/lib/x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o" "-L/usr/lib/gcc/x86_64-linux-gnu/9" "-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/../lib64" "-L/lib" "-L/usr/lib" "/home/sunshaoce/dev/llvm-project/build/temp.f03" "-L/home/sunshaoce/dev/llvm-project/build/lib" "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o" "/lib/x86_64-linux-gnu/crtn.o"

after

$ /home/sunshaoce/dev/llvm-project/build/bin/flang-new /home/sunshaoce/dev/llvm-project/build/temp.f03 -flang-experimental-exec -o temp.out -###
flang-new version 17.0.0 (https://github.com/llvm/llvm-project.git 890e6c871d31dca9e461c01118cf25fb303b9cad)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sunshaoce/dev/llvm-project/build/bin
 "/home/sunshaoce/dev/llvm-project/build/bin/flang-new" "-fc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-fcolor-diagnostics" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "x86-64" "-o" "/tmp/temp-72c5c0.o" "-x" "f95-cpp-input" "/home/sunshaoce/dev/llvm-project/build/temp.f03"
 "/usr/bin/ld" "-pie" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "temp.out" "/lib/x86_64-linux-gnu/Scrt1.o" "/lib/x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o" "-L/usr/lib/gcc/x86_64-linux-gnu/9" "-L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib64" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/../lib64" "-L/lib" "-L/usr/lib" "/tmp/temp-72c5c0.o" "-L/home/sunshaoce/dev/llvm-project/build/lib" "-lFortran_main" "-lFortranRuntime" "-lFortranDecimal" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o" "/lib/x86_64-linux-gnu/crtn.o"

So, I tested it by checking whether flang was called.

awarzynski added a comment.EditedMar 11 2023, 7:01 AM

Thanks!

Thanks. Can you add tests in flang/test/Driver?

Hm, this is a clangDriver change rather than anything Flang specific 🤔 . Btw, how does https://github.com/llvm/llvm-project/issues/61260 manifest to you? I'm trying to figure out how to best test it (I couldn't find any other tests for this specifically).

Cannot we just have a a .f03 file and compile it and see if we have an executable?

We don't really build executable for testing the Driver. Also, building an executable involves many steps:

  1. The driver (flang-new) identifies the file as a valid Fortran file. Delegates to "Flang" for the next step.
  2. "Flang" parses the input, runs semantic checks and lowers to LLVM IR. This is driven by the frontend driver, flang-new -fc1.
  3. LLVM IR is compiled into machine code (via LLVM) (also driven by flang-new -fc1).
  4. Machine code generated in 3 is then linked by the driver to generate an executable (this step is driven by flang-new).

    It would be good to understand what exactly this change unblocks and then test that specifically. To me it sounds like this change is only really needed for 1. and hence we should only be testing 1 and avoid doing extra work that's not needed.

I suspect that without this change, .*.f03 files are recognized as object rather than Fortran files and hence step 1. is followed by step 4. rather than step 2. So, try flang-new -### file.f03 with and without your change. You should see that with this change you do see the frontend driver invocation (flang-new -fc1 <some args>) that would run steps 2 and 3.. IMO that's the only thing that requires verifying here.

Does this make sense?

EDIT
Ah, I've missed your reply, sorry! My suspicion was correct, cool :) Now we know what kind of test is needed here.

I'd move these tests to flang/test/Driver/supported-suffices. That would help documenting what these tests actual check for. Also, one could be tempted to test for other suffices and then it would be nice to keep them in one place. Ta!

flang/test/Driver/f03-suffix.f03
1 ↗(On Diff #504359)

You can safely drop -flang-experimental-exec here.

4 ↗(On Diff #504359)

The linker invocation is unrelated to this change. Also, it will very likely look differently on other operating systems. Best to skip it.

sunshaoce updated this revision to Diff 504360.Mar 11 2023, 7:11 AM

Remove -flang-experimental-exec

sunshaoce updated this revision to Diff 504362.Mar 11 2023, 7:14 AM

Address @awarzynski's comment

awarzynski added inline comments.Mar 11 2023, 7:17 AM
flang/test/Driver/supported-suffices/f08-suffix.f08
5

This line will not appear without -flang-experimental-exec - you need to delete it. Same for the other test.

sunshaoce updated this revision to Diff 504363.Mar 11 2023, 7:18 AM
sunshaoce marked 2 inline comments as done.

Sorry, I just missed a comment.

awarzynski accepted this revision.Mar 11 2023, 7:21 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mar 11 2023, 7:21 AM
This revision was landed with ongoing or failed builds.Mar 11 2023, 7:23 AM
This revision was automatically updated to reflect the committed changes.
sunshaoce marked an inline comment as done.
sunshaoce reopened this revision.Mar 11 2023, 8:10 AM

Sorry! My previous tests were not comprehensive enough, which resulted in failures in the MSVC environment.

This revision is now accepted and ready to land.Mar 11 2023, 8:10 AM
sunshaoce updated this revision to Diff 504372.Mar 11 2023, 8:19 AM

Fix the issue of failing in the MSVC environment.

This revision was automatically updated to reflect the committed changes.