# LLVM 13.0 released with Flang

**URL:** <https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039>\
**Category:** Uncategorized\
**Created:** [October 9, 2021, 11:01am UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039 "2021-10-09T11:01:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [October 9, 2021, 11:01am UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/1 "2021-10-09T11:01:24Z")

</div>

The official release notes say: _Flang is now included in the binary packages released by LLVM._

[https://releases.llvm.org/13.0.0/docs/ReleaseNotes.html](https://releases.llvm.org/13.0.0/docs/ReleaseNotes.html)

Does it mean LLVM Flang can now produce an executable without calling an external compiler?

> **[LLVM 13.0 Released With Official Flang Binary Packages, Improved OpenCL Clang...](https://www.phoronix.com/news/LLVM-13.0-Released)**
>
> LLVM 13.0 was tagged overnight as the latest half-year update to this widely-used, very powerful open-source compiler stack.

> Flang as the Fortran front-end is now included in the official LLVM binary packages.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [October 9, 2021, 3:51pm UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/2 "2021-10-09T15:51:22Z")

</div>

LLVM 13.0 is available in Fedora 35. I have made some tests in a Fedora Rawhide virtual machine. There is `flang-new`, which can’t produce yet an executable:

```bash
$ flang-new --version
flang-new version 13.0.0 (Fedora 13.0.0~rc1-1.fc35)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ flang-new hello.f90
error: code-generation is not available yet

```

and the flang script:

```bash
$ flang --version
flang version 13.0.0
$ flang hello.f90
$ ./a.out
 Hello World!

```

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [October 9, 2021, 4:59pm UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/3 "2021-10-09T16:59:38Z")

</div>

Trying to add a `use iso_c_binding` statement in an hello world example, I am quite confused:

```bash
$ flang hello.f90
./hello.f90:2:9: error: Cannot read module file for module 'iso_c_binding': Source file 'iso_c_binding.f18.mod' was not found
      use iso_c_binding
          ^^^^^^^^^^^^^
error: Semantic errors in hello.f90
flang: in /home/osboxes, flang-new failed with exit status 1: /usr/bin/flang-new -fc1 -module-suffix .f18.mod -fdebug-unparse -fno-analyzed-objects-for-unparse hello.f90

```

I used `flang` but the error message says `flang-new failed`. And why the iso\_c\_binding module is not available?

---

<div class="post-metadata">

**Author:** ![kiranchandramohan](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@kiranchandramohan](https://fortran-lang.discourse.group/u/kiranchandramohan)\
**Post date:** [October 10, 2021, 9:32pm UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/4 "2021-10-10T21:32:18Z")

</div>

Classic Flang ([GitHub - flang-compiler/flang: Flang is a Fortran language front-end designed for integration with LLVM.](https://github.com/flang-compiler/flang)) is a separate compiler and not shipped along with llvm.

flang-new is the driver of the Fortran frontend shipped along with llvm. flang is a shell script that can parse, perform semantics, and unparse and call an external compiler to do the codegen. flang basically calls flang-new internally. When codegen becomes available then the flang script will be removed/renamed and flang-new will be renamed as flang.

I don’t know why the iso\_c\_binding usage is not working. I expected it to work. Maybe you can file a bug ([Bug List](https://bugs.llvm.org/buglist.cgi?component=Driver&list_id=224353&product=flang&resolution=---)).

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [October 11, 2021, 6:28am UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/5 "2021-10-11T06:28:02Z")

</div>

Thanks for clarifying things about flang / flang-new.  
I will make more tests about iso\_c\_binding and see if everything is correctly installed in my Fedora Rawhide.

---

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [July 8, 2022, 7:26am UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/6 "2022-07-08T07:26:22Z")

</div>

EnzymeAD seems to be a good plugin for Flang.

> **[Enzyme Automatic Differentiation Compiler](https://github.com/EnzymeAD)**
>
> Enzyme Automatic Differentiation Compiler has 12 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![lpaehler](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lpaehler/32/1026_2.png) [@lpaehler](https://fortran-lang.discourse.group/u/lpaehler)\
**Post date:** [July 9, 2022, 3:06pm UTC](https://fortran-lang.discourse.group/t/llvm-13-0-released-with-flang/2039/7 "2022-07-09T15:06:47Z")

</div>

I fully agree, and we are actively working on making it work (and work nicer at that), but the actual plugin interface for `flang-new` is only just landing right now[1], so I would deem it too early to use for now.

An alternative way to use Enzyme with Fortran is by writing the compilation pipeline out manually in the Makefile:

1. Obtain `.fir` with the bbc compiler
2. Run first round of optimizations with `opt`
3. Combine the IR with `llvm-link`
4. Apply Enzyme with `opt`
5. 2nd optimization pass, and compile executable with `clang++`

Let me know if I can be of any help!

[1] [⚙ D129156 Add -fpass-plugin option to Flang](https://reviews.llvm.org/D129156)
