<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/154960>154960</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] a dialect with namespace 'arith' has already been registered
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ELundby45
      </td>
    </tr>
</table>

<pre>
    While trying to build flang 20.1.8 on osx-arm64 I get the following error during build time:

`a dialect with namespace 'arith' has already been registered`

```
[380/451] Generating ../../include/flang/iso_fortran_env_impl.mod, iso_fortran_env_impl.o
FAILED: include/flang/iso_fortran_env_impl.mod tools/f18/iso_fortran_env_impl.o $SRC_DIR/build/include/flang/iso_fortran_env_impl.mod $SRC_DIR/build/tools/f18/iso_fortran_env_impl.o 
cd $SRC_DIR/build/tools/f18 && $BUILD_PREFIX/bin/cmake -E make_directory $SRC_DIR/build/include/flang && $SRC_DIR/build/bin/flang -cpp -c -o $SRC_DIR/build/tools/f18/iso_fortran_env_impl.o -module-dir $SRC_DIR/build/include/flang $SRC_DIR/flang/module/iso_fortran_env_impl.f90
LLVM ERROR: a dialect with namespace 'arith' has already been registered
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: $SRC_DIR/build/bin/flang -fc1 -triple arm64-apple-macosx11.1.0 -emit-obj -cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -module-dir $SRC_DIR/build/include/flang -resource-dir $SRC_DIR/build/lib/clang/20 -mframe-pointer=non-leaf -o $SRC_DIR/build/tools/f18/iso_fortran_env_impl.o -x f95-cpp-input $SRC_DIR/flang/module/iso_fortran_env_impl.f90
 #0 0x0000000114bf1188 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) ($PREFIX/lib/libLLVM.20.1.dylib+0x15d188)
 #1 0x0000000114bef010 llvm::sys::RunSignalHandlers() ($PREFIX/lib/libLLVM.20.1.dylib+0x15b010)
 #2 0x0000000114bf187c SignalHandler(int) ($PREFIX/lib/libLLVM.20.1.dylib+0x15d87c)
 #3 0x0000000199668624 (/usr/lib/system/libsystem_platform.dylib+0x1804ac624)
 #4 0x000000019962e88c (/usr/lib/system/libsystem_pthread.dylib+0x18047288c)
 #5 0x0000000199537c60 (/usr/lib/system/libsystem_c.dylib+0x18037bc60)
 #6 0x0000000114b3f734 llvm::report_fatal_error(llvm::Twine const&, bool) ($PREFIX/lib/libLLVM.20.1.dylib+0xab734)
 #7 0x0000000104147cf0 std::__1::pair<llvm::DenseMapIterator<llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>>, false>, bool> llvm::DenseMapBase<llvm::DenseMap<llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>>>, llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>>>>::try_emplace<std::nullptr_t>(llvm::StringRef const&, std::nullptr_t&&) ($SRC_DIR/build/lib/libCUFAttrs.20.1.dylib+0x10bcf0)
 #8 0x000000011e68ca50 fir::FIROpsDialect::FIROpsDialect(mlir::MLIRContext*) ($SRC_DIR/build/lib/libFIRDialect.20.1.dylib+0x10a50)
 #9 0x000000010341fda0 std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>> llvm::function_ref<std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>> ()>::callback_fn<fir::FIROpsDialect* mlir::MLIRContext::getOrLoadDialect<fir::FIROpsDialect>()::'lambda'()>(long) ($SRC_DIR/build/lib/libflangFrontend.20.1.dylib+0x23da0)
#10 0x000000010c8cd6dc mlir::MLIRContext::getOrLoadDialect(llvm::StringRef, mlir::TypeID, llvm::function_ref<std::__1::unique_ptr<mlir::Dialect, std::__1::default_delete<mlir::Dialect>> ()>) ($SRC_DIR/build/lib/libFlangOpenMPTransforms.20.1.dylib+0x2716dc)
#11 0x00000001034189d0 fir::support::loadNonCodegenDialects(mlir::MLIRContext&) ($SRC_DIR/build/lib/libflangFrontend.20.1.dylib+0x1c9d0)
#12 0x0000000103417bd8 Fortran::frontend::CodeGenAction::beginSourceFileAction() ($SRC_DIR/build/lib/libflangFrontend.20.1.dylib+0x1bbd8)
#13 0x0000000103416508 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) ($SRC_DIR/build/lib/libflangFrontend.20.1.dylib+0x1a508)
#14 0x0000000103403b74 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) ($SRC_DIR/build/lib/libflangFrontend.20.1.dylib+0x7b74)
#15 0x00000001027bfe6c Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) ($SRC_DIR/build/lib/libflangFrontendTool.20.1.dylib+0x3e6c)
#16 0x0000000102346bb0 fc1_main(llvm::ArrayRef<char const*>, char const*) ($SRC_DIR/build/bin/flang-20+0x100006bb0)
#17 0x00000001023456b0 main ($SRC_DIR/build/bin/flang-20+0x1000056b0)
#18 0x000000019928eb98 
flang-20: error: unable to execute command: Abort trap: 6
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.1.8
Target: arm64-apple-darwin24.5.0
Thread model: posix
InstalledDir: $SRC_DIR/build/bin
flang-20: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /var/folders/my/fnvhhdw53lq0ztwwqdlx9zw00000gp/T/iso_fortran_env_impl-734431
flang-20: note: diagnostic msg: /var/folders/my/fnvhhdw53lq0ztwwqdlx9zw00000gp/T/iso_fortran_env_impl-734431.sh
flang-20: note: diagnostic msg: Crash backtrace is located in
flang-20: note: diagnostic msg: /Users/lundby/Library/Logs/DiagnosticReports/flang-20_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
flang-20: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
flang-20: note: diagnostic msg: 

********************
[381/451] Generating ../../include/flang/ieee_exceptions.mod
[382/451] Generating ../../include/flang/ieee_features.mod
[383/451] Generating ../../include/flang/iso_c_binding.mod
ninja: build stopped: subcommand failed.
```

> PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:

These are included in `flang_diagnostics.zip`. Full build log is attached. 


[flang_build_failure.log](https://github.com/user-attachments/files/21939642/flang_build_failure.log)

[flang_diagnostics.zip](https://github.com/user-attachments/files/21939668/flang_diagnostics.zip)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWltz46i2_jXKCyWXhK5-yIMTx92pSiYpJ33m9JMLwZJNDwINoFz6158CObHsVnKc7r1npmrvLlfHWsDHty4sEMvEGL6WAKdBdhZk8xPS2Y3SpxdX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