[llvm] fc1ffb4 - [AsmPrinter] Fix Crash when Emitting Global Constant of small bit width when targeting Big Endian arch
Peter Rong via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 29 00:09:18 PDT 2023
Author: Henry Yu
Date: 2023-03-29T00:09:11-07:00
New Revision: fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc
URL: https://github.com/llvm/llvm-project/commit/fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc
DIFF: https://github.com/llvm/llvm-project/commit/fc1ffb4c0ea886bf37a2169db3d9270eb600d9fc.diff
LOG: [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
Added:
llvm/test/CodeGen/AArch64/aarch64_be-global-const.ll
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 47623e6935b7..a663c957dac0 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 000000000000..22979bcf1f9f
--- /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
+ at G = global <4 x i1> <i1 true, i1 false, i1 true, i1 true>
More information about the llvm-commits
mailing list