llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.95k stars 11.04k forks source link

Test assert failures with Visual Studio 17.10.3 on Windows ARM64 #97631

Open hjyamauchi opened 1 week ago

hjyamauchi commented 1 week ago

If I build and run the tests (ninja check-clang check-llvm) near head (commit 259ce1199906554fba5c8d3b07b6ce14ee42d301) with Visual Studio 17.10.3 on a Windows ARM64 machine (using the arm64 native cl.exe, no emulation), I get a large number of test assert failures:

$ mkdir build
$ cd build
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS=clang ..\llvm
$ ninja check-clang check-llvm
...
Total Discovered Tests: 60182
  Skipped          :    28 (0.05%)
  Unsupported      :  1527 (2.54%)
  Passed           : 58150 (96.62%)
  Expectedly Failed:   166 (0.28%)
  Failed           :   311 (0.52%)

Here are the sort|uniq'd assert failures from the test run:

# |            1: Assertion failed: getAlign() && *getAlign() == Align && "Alignment representation error!", file C:\Users\hiroshi\llvm-project\llvm\lib\IR\Globals.cpp, line 144
# |            1: Assertion failed: VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE && "Simple vector VT not representable by simple integer vector VT!", file C:\Users\hiroshi\llvm-project\llvm\include\llvm/CodeGenTypes/MachineValueType.h, line 201
# | Assertion failed: (TLI.getTypeAction(*DAG.getContext(), Op.getValueType()) == TargetLowering::TypeLegal || Op.getOpcode() == ISD::TargetConstant || Op.getOpcode() == ISD::Register) && "Unexpected illegal type!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\LegalizeDAG.cpp, line 974
# | Assertion failed: Emitted && "Failed to emit a aext!", file C:\Users\hiroshi\llvm-project\llvm\lib\Target\X86\X86FastISel.cpp, line 3408
# | Assertion failed: Emitted && "Failed to emit a zext!", file C:\Users\hiroshi\llvm-project\llvm\lib\Target\X86\X86FastISel.cpp, line 3392
# | Assertion failed: From.getNode() != To.getNode() && "Potential legalization loop!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\LegalizeTypes.cpp, line 646
# | Assertion failed: getAlign() && *getAlign() == Align && "Alignment representation error!", file C:\Users\hiroshi\llvm-project\llvm\lib\IR\Globals.cpp, line 144
# | Assertion failed: isSimple() && "Expected a SimpleValueType!", file C:\Users\hiroshi\llvm-project\llvm\include\llvm/CodeGen/ValueTypes.h, line 307
# | Assertion failed: N1.getValueType() == N2.getValueType() && N1.getValueType() == VT && "Binary operator types must match!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 6898
# | Assertion failed: N1.getValueType().bitsGT(VT) && "Invalid truncate node, src < dst!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 6062
# | Assertion failed: N1.getValueType().bitsLT(VT) && "Invalid sext node, dst < src!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 5971
# | Assertion failed: N1.getValueType().bitsLT(VT) && "Invalid zext node, dst < src!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 5992
# | Assertion failed: NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid && "Didn't find type to promote to!", file C:\Users\hiroshi\llvm-project\llvm\include\llvm/CodeGen/TargetLowering.h, line 1647
# | Assertion failed: VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE && "Simple vector VT not representable by simple integer vector VT!", file C:\Users\hiroshi\llvm-project\llvm\include\llvm/CodeGenTypes/MachineValueType.h, line 201
# | Assertion failed: VT == N1.getValueType() && "Not an inreg extend!", file C:\Users\hiroshi\llvm-project\llvm\lib\CodeGen\SelectionDAG\SelectionDAG.cpp, line 7061
Assertion failed: getAlign() && *getAlign() == Align && "Alignment representation error!", file C:\Users\hiroshi\llvm-project\llvm\lib\IR\Globals.cpp, line 144

I started looking into this because the Swift toolchain build (using downstream swiftlang/llvm-project) seems to result in similar assert failures with VS 17.10.3.

hjyamauchi commented 1 week ago

I am not sure if this is a bug in the MSVC compiler or some undefined behavior in the LLVM code, but it seems to be related to the same pattern of equality checks of a byte-sized field in a value-type struct failing due to non-zero/garbage bits in the higher 24 bits on a 32-bit W register or a 32-bit piece of memory.

hjyamauchi commented 5 days ago

I created a reduced reproducer and reported here: https://developercommunity.visualstudio.com/t/VC-17103-arm64-C-compiler:-a-potenti/10699487