<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ARM 32 Bits Windows MSVC C compiler is Fixed in Version LLVM/Clang 11.0.1, But C++ Still Crash"
   href="https://bugs.llvm.org/show_bug.cgi?id=49196">49196</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ARM 32 Bits Windows MSVC C compiler is Fixed in Version LLVM/Clang 11.0.1, But C++ Still Crash
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>falhumai96@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24531" name="attach_24531" title="Bug attachments">attachment 24531</a> <a href="attachment.cgi?id=24531&action=edit" title="Bug attachments">[details]</a></span>
Bug attachments

I am trying to compile a simple C++ code, as follows, using the LLVM/Clang
compiler that targets either of `armv4-pc-windows-msvc` or
`armv7-pc-windows-msvc` (basically any ARM, not ARM64, target for Windows
MSVC):

```
#include <iostream>

int main() {
    std::cout << "Hello, world!\n";
}
```

Here's also a simple CXX script I used to cross compile the code to Windows
MSVC from Linux:


```
#!/usr/bin/env bash

export MSVC_CROSS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1
&& pwd )"
export MSVC_CROSS_DIR="$MSVC_CROSS_DIR/.."


if [ -z "$MSVC_CROSS_MSVC_DIR" ]; then
    export MSVC_CROSS_MSVC_DIR="$MSVC_CROSS_DIR/MSVC/14.20.27508"
fi

if [ -z "$MSVC_CROSS_WINDOWS_KITS_DIR" ]; then
    export MSVC_CROSS_WINDOWS_KITS_DIR="$MSVC_CROSS_DIR/WindowsKits/10"
fi

if [ -z "$MSVC_CROSS_WINDOWS_KITS_VER" ]; then
    export MSVC_CROSS_WINDOWS_KITS_VER="10.0.18362.0"
fi

if [ -z "$MSVC_CROSS_MS_COMPATIBILITY_VERSION" ]; then
    export MSVC_CROSS_MS_COMPATIBILITY_VERSION="19.20.27508"
fi

clang "$@" -target armv4-pc-windows-msvc \
  -frtti \
  -fuse-ld=lld \
  -Wl,-machine:arm \
  "-fms-compatibility-version=$MSVC_CROSS_MS_COMPATIBILITY_VERSION" \
  -fms-extensions \
  -fdelayed-template-parsing \
  -fexceptions \
  -fcxx-exceptions \
  -mthread-model posix \
  -fno-threadsafe-statics \
  -Wno-overlength-strings \
  -Wno-microsoft-enum-value \
  -Wno-language-extension-token \
  -Wno-unused-command-line-argument \
  -Wno-msvc-not-found \
  -Wno-pragma-pack \
  -Wno-ignored-attributes \
  -Wno-ignored-pragma-intrinsic \
  -Wno-expansion-to-defined \
  -Wno-microsoft-anon-tag \
  -Wno-nonportable-include-path \
  -Wno-void-pointer-to-int-cast \
  -Wno-int-to-void-pointer-cast \
  -Wno-pointer-type-mismatch \
  -Wno-asm-operand-widths \
  -DWIN32 \
  -D_WIN32 \
  -D_MT \
  -D_DLL \
  -Xclang -disable-llvm-verifier \
  -Xclang '--dependent-lib=msvcrt' \
  -Xclang '--dependent-lib=ucrt' \
  -Xclang '--dependent-lib=oldnames' \
  -Xclang '--dependent-lib=vcruntime' \
  -D_CRT_SECURE_NO_WARNINGS \
  -D_CRT_NONSTDC_NO_DEPRECATE \
  -U__GNUC__ \
  -U__gnu_linux__ \
  -U__GNUC_MINOR__ \
  -U__GNUC_PATCHLEVEL__ \
  -U__GNUC_STDC_INLINE__  \
  -idirafter "$MSVC_CROSS_MSVC_DIR/include" \
  -idirafter
"$MSVC_CROSS_WINDOWS_KITS_DIR/Include/$MSVC_CROSS_WINDOWS_KITS_VER/ucrt" \
  -idirafter
"$MSVC_CROSS_WINDOWS_KITS_DIR/Include/$MSVC_CROSS_WINDOWS_KITS_VER/shared" \
  -idirafter
"$MSVC_CROSS_WINDOWS_KITS_DIR/Include/$MSVC_CROSS_WINDOWS_KITS_VER/um" \
  -idirafter
"$MSVC_CROSS_WINDOWS_KITS_DIR/Include/$MSVC_CROSS_WINDOWS_KITS_VER/winrt" \
  "-L$MSVC_CROSS_MSVC_DIR/lib/arm" \
  "-L$MSVC_CROSS_WINDOWS_KITS_DIR/Lib/$MSVC_CROSS_WINDOWS_KITS_VER/um/arm" \
  "-L$MSVC_CROSS_WINDOWS_KITS_DIR/Lib/$MSVC_CROSS_WINDOWS_KITS_VER/ucrt/arm" \
  -lmsvcrt -lkernel32 -Wno-msvc-not-found -Xlinker /subsystem:console -x c++
```

I did build other simple C code, and it passes, while it wasn't passing back in
version 10 and earlier of LLVM/Clang. However, C++ still crash in the backend,
with the following example error (when running with `-v`):

```
clang version 11.0.1
Target: armv4-pc-windows-msvc
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang-11" -cc1 -triple thumbv7-pc-windows-msvc19.20.27508 -emit-obj
-mrelax-all -mincremental-linker-compatible -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name hello.cpp
-mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math
-mconstructor-aliases -target-cpu cortex-a9 -target-feature +strict-align
-target-abi aapcs -mfloat-abi hard -fallow-half-arguments-and-returns -v
-resource-dir /usr/lib/clang/11.0.1 -idirafter
/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../MSVC/14.20.27508/include
-idirafter
/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/ucrt
-idirafter
/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/shared
-idirafter
/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/um
-idirafter
/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/winrt
-D WIN32 -D _WIN32 -D _MT -D _DLL -D _CRT_SECURE_NO_WARNINGS -D
_CRT_NONSTDC_NO_DEPRECATE -U __GNUC__ -U __gnu_linux__ -U __GNUC_MINOR__ -U
__GNUC_PATCHLEVEL__ -U __GNUC_STDC_INLINE__ -internal-isystem
/usr/lib/clang/11.0.1/include -Wno-overlength-strings -Wno-microsoft-enum-value
-Wno-language-extension-token -Wno-unused-command-line-argument
-Wno-msvc-not-found -Wno-pragma-pack -Wno-ignored-attributes
-Wno-ignored-pragma-intrinsic -Wno-expansion-to-defined -Wno-microsoft-anon-tag
-Wno-nonportable-include-path -Wno-void-pointer-to-int-cast
-Wno-int-to-void-pointer-cast -Wno-pointer-type-mismatch
-Wno-asm-operand-widths -Wno-msvc-not-found -fdeprecated-macro
-fdebug-compilation-dir /home/falhumai96 -ferror-limit 19 -mllvm
-arm-restrict-it -fno-use-cxa-atexit -fms-extensions -fms-compatibility
-fms-compatibility-version=19.20.27508 -std=c++14 -fno-threadsafe-statics
-fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics
-disable-llvm-verifier --dependent-lib=msvcrt --dependent-lib=ucrt
--dependent-lib=oldnames --dependent-lib=vcruntime -faddrsig -o
/tmp/hello-11dad0.o -x c++ hello.cpp
clang -cc1 version 11.0.1 based upon LLVM 11.0.1 default target
x86_64-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/clang/11.0.1/include

/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../MSVC/14.20.27508/include

/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/ucrt

/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/shared

/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/um

/home/falhumai96/Documents/WindowsMSVCCrossSDK/crossccshellscripts/../WindowsKits/10/Include/10.0.18362.0/winrt
End of search list.
fatal error: error in backend: Cannot select: 0x55b833e46688: ch = catchret
0x55b832cd2bf8, BasicBlock:ch< 0x55b833e43930>, BasicBlock:ch< 0x55b833e30a48>
In function:
??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z
clang-11: error: clang frontend command failed with exit code 70 (use -v to see
invocation)
clang version 11.0.1
Target: armv4-pc-windows-msvc
Thread model: posix
InstalledDir: /usr/bin
clang-11: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/hello-7ea7e2.cpp
clang-11: note: diagnostic msg: /tmp/hello-7ea7e2.sh
clang-11: note: diagnostic msg: 

********************
```

I have attached the scripts I use for cross compilation (provided that you have
the Windows SDK and the MSVC SDK somewhere in your system, and the
`crossccshellscripts` exists in the same dir as SDKs folder), the sample C++
code `hello.cpp`, and the CPP `hello-7ea7e2.cpp` and SH `hello-7ea7e2.sh` files
generated when the bug happened. I also tried compiling on Windows directly
from the release files in your GitHub, and it still have the same crashes on
ARM target.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>