Skip to content

Commit fc1ffb4

Browse files
HazyFishDataCorrupted
authored andcommitted
[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 [[ #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
1 parent 98286a0 commit fc1ffb4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,8 @@ static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) {
33853385
ExtraBitsSize = alignTo(ExtraBitsSize, 8);
33863386
ExtraBits = Realigned.getRawData()[0] &
33873387
(((uint64_t)-1) >> (64 - ExtraBitsSize));
3388-
Realigned.lshrInPlace(ExtraBitsSize);
3388+
if (BitWidth >= 64)
3389+
Realigned.lshrInPlace(ExtraBitsSize);
33893390
} else
33903391
ExtraBits = Realigned.getRawData()[BitWidth / 64];
33913392
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: llc -mtriple=aarch64_be < %s | FileCheck %s
2+
3+
; CHECK-LABEL: G:
4+
; CHECK: .byte 11
5+
; CHECK: .size G, 1
6+
@G = global <4 x i1> <i1 true, i1 false, i1 true, i1 true>

0 commit comments

Comments
 (0)