diff options
author | Henry Yu <hazyfish@outlook.com> | 2023-03-29 00:06:06 -0700 |
---|---|---|
committer | Peter Rong <PeterRong96@gmail.com> | 2023-03-29 00:09:11 -0700 |
commit | fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc (patch) | |
tree | 91a060df079c0a402b466db6b4e6c55c3a6c751b | |
parent | 98286a04ef0af46279cf11b1e2c133e978d4224f (diff) | |
download | llvm-fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc.zip llvm-fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc.tar.gz llvm-fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc.tar.bz2 |
[AsmPrinter] Fix Crash when Emitting Global Constant of small bit width when targeting Big Endian arch
For Big Endian, the function `emitGlobalConstantLargeInt` tries to right shift `Realigned` by an amount `ExtraBitSize` in place. However, if the constant to emit has a bit width less than 64 and the bit width is not a multiple of 8, the shift amount will be greater than the bit width of `Realigned`, which causes assertion error described in issue [[ https://github.com/llvm/llvm-project/issues/59055 | issue #59055 ]].
This patch fixes the issue by avoiding right shift when bit width is under 64 to avoid the assertion error.
Reviewed By: Peter
Differential Revision: https://reviews.llvm.org/D138246
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 3 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 47623e6..a663c95 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3385,7 +3385,8 @@ static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) { ExtraBitsSize = alignTo(ExtraBitsSize, 8); ExtraBits = Realigned.getRawData()[0] & (((uint64_t)-1) >> (64 - ExtraBitsSize)); - Realigned.lshrInPlace(ExtraBitsSize); + if (BitWidth >= 64) + Realigned.lshrInPlace(ExtraBitsSize); } else ExtraBits = Realigned.getRawData()[BitWidth / 64]; } diff --git a/llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll b/llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll new file mode 100644 index 0000000..22979bc --- /dev/null +++ b/llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll @@ -0,0 +1,6 @@ +; RUN: llc -mtriple=aarch64_be < %s | FileCheck %s + +; CHECK-LABEL: G: +; CHECK: .byte 11 +; CHECK: .size G, 1 +@G = global <4 x i1> <i1 true, i1 false, i1 true, i1 true> |