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

    <tr>
        <th>Summary</th>
        <td>
            aarch64-w64-windows-gnu: OpenMP SEGFAULTs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    #### Clang information:
```
clang version 15.0.7
Target: aarch64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clangarm64/bin
```
#### Description
After OpenMP started being build for CLANGARM64  many upstream packages started using it for their aarch64 builds too. 
Then, applications like Inskscape, Darktable and GraphicksMagic started crashing during execution or while running unit tests.
None of these crashes were happening in CLANGARM64 with OpenMP disabled in their builds,  and none with these crashes happen in CLANG64 of MINGW64 builds of the same applications with OpenMP enabled.

### Steps to reproduce
#### Option 1 - Run OpenMP unit tests in MSYS2's CLANGARM64
- In a Windows on ARM machine, uncomment the  `clangarm64` repo in `/etc/pacman.conf` (https://www.msys2.org/docs/repos-mirrors/) and update all packages with `pacman -Syu`
- Install pip with `pacman -S ${MINGW_PACKAGE_PREFIX}-python-pip`
- Install lit with `pip install lit`
- Edit `mingw-w64-openmp/PKGBUILD` and add an extra `OPENMP_LLVM_LIT_EXECUTABLE` to the CMake call. E.g:
```
      -B "build-${MSYSTEM}-${shared_libs}" \
 -DOPENMP_LLVM_LIT_EXECUTABLE:FILEPATH="${MINGW_PREFIX}/bin/lit-script.py"
```
- Build OpenMP package
- cd to `src/build-${MSYSTEM}-shared` and run `ninja check-openmp`
The unit tests fails, some even error out: https://gist.github.com/hmartinez82/02a36d1471c1f24c66f2c37b8e07ce2f

#### Option 2 - Run Darktable or Darktable's cltest
- Install Darktable with `pacman -S mingw-w64-clang-aarch64-darktable`
- Run `darktable-cltest.exe`. It crashes at https://github.com/darktable-org/darktable/blob/5253d9a8f7e5d33581e457203353a99baf21ae03/src/common/gaussian.c#L219
LLDB's output:
```
lldb) target create "darktable-cltest"
(rrent executable set to 'C:\msys64\clangarm64\bin\darktable-cltest.exe' (aarch64).
(lldb) process handle SIGSEGV --notify true --pass true --stop true
NAME         PASS     STOP     NOTIFY
===========  ======= =======  =======
SIGSEGV      true     true     true
(lldb) r
(lldb) Process 13060 launched: 'C:\msys64\clangarm64\bin\darktable-cltest.exe' (aarch64)
Process 13060 stopped
* thread #10, stop reason = Exception 0xc0000005 encountered at address 0x7ffd5fd1976c: Access violation reading location 0xffffe5b86ff1e840
    frame #0: 0x00007ffd5fd1976c libdarktable.dll`.omp_outlined. at gaussian.c:219:15
```

#### Option 3 - Open Inkscape's about dialog
- Install Inkscape with `pacman -S mingw-w64-clang-aarch64-inkscape`
- Run Inkscape and create a new empty document
- Open the about box with Help -> About Inkscape
LLDB's output:
```
$ lldb -- inkscape
(lldb) target create "inkscape"
(rrent executable set to 'C:\msys64\clangarm64\bin\inkscape.exe' (aarch64).
(lldb) process handle SIGSEGV --notify true --pass true --stop true
NAME         PASS STOP     NOTIFY
===========  =======  =======  =======
SIGSEGV true     true     true
(lldb) r
(lldb) Process 7340 launched: 'C:\msys64\clangarm64\bin\inkscape.exe' (aarch64)
Process 7340 stopped
* thread #27, stop reason = Exception 0xc0000005 encountered at address 0x7ffd491acb0c: Access violation reading location 0x100000001
 frame #0: 0x00007ffd491acb0c libinkscape_base.dll`Inkscape::Filters::FilterGaussian::~FilterGaussian() + 3524
libinkscape_base.dll`Inkscape::Filters::FilterGaussian::~FilterGaussian:
-> 0x7ffd491acb0c <+3524>: ldrsw  x11, [x29]
    0x7ffd491acb10 <+3528>: madd   x13, x10, x8, x9
    0x7ffd491acb14 <+3532>: ldrsw  x9, [x19]
 0x7ffd491acb18 <+3536>: sub    x10, x9, #0x1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWFuTm7jW_TXql124QBhs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