llvm-project/llvm/test/MC/ARM/align-fill-byte-zero.s
Sam Elliott ea222be0d9
[MC] Honour alignment directive fill value for non-intel (#100136)
As reported in https://llvm.org/PR30955, `.balign` with a fill-value of 0 did
not actually align using zeroes, on non-x86 targets.

This is because the check of whether to use the code alignment routines
or whether to just use the fill value was checking whether the fill
value was equal to `TextAlignFillValue`, which has not been changed from
its default of 0 on most targets (it has been changed for x86). However,
most targets do not set the fill value because it doesn't entirely make
sense -- i.e. on AArch64 there's no reasonable byte value to use for
alignment, as instructions are word-sized and have to be well-aligned.

I think the check at the end `AsmParser::parseDirectiveAlign` is
suspicious even on x86 - if you use `.balign <align>, 0x90` in a code
section, you don't end up with a block of `0x90` repeated, you end up
with a block of NOPs of various widths. This functionality is never
tested.

The fix here is to modify the check to ignore the default text align
fill value when choosing to do code alignment or not.

Fixes #30303
2024-07-24 18:24:39 +01:00

41 lines
1.4 KiB
ArmAsm

// RUN: llvm-mc -triple armv7a %s -o - | FileCheck %s --check-prefix=ASM-ARM
// RUN: llvm-mc -triple armv7a -filetype obj %s -o - | \
// RUN: llvm-objdump --triple=armv7a -dz - | FileCheck %s --check-prefix=OBJ-ARM
// RUN: llvm-mc -triple thumbv7a %s -o - | FileCheck %s --check-prefix=ASM-THUMB
// RUN: llvm-mc -triple thumbv7a -filetype obj %s -o - | \
// RUN: llvm-objdump --triple=thumbv7a -dz - | FileCheck %s --check-prefix=OBJ-THUMB
// llvm.org/pr30955 - LLVM was handling `.balign <alignment>, 0` strangely on
// non-x86 targets.
.text
// ASM-ARM: add r0, r0, #1
// OBJ-ARM: e2800001 add r0, r0, #1
// ASM-THUMB: add.w r0, r0, #1
// OBJ-THUMB: f100 0001 add.w r0, r0, #0x1
add r0, r0, 0x1
// ASM-ARM: .p2align 4, 0x0
// OBJ-ARM-NEXT: 00000000 andeq r0, r0, r0
// OBJ-ARM-NEXT: 00000000 andeq r0, r0, r0
// OBJ-ARM-NEXT: 00000000 andeq r0, r0, r0
// ASM-THUMB: .p2align 4, 0x0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
// OBJ-THUMB-NEXT: 0000 movs r0, r0
.balign 0x10, 0
// ASM-ARM: add r0, r0, #1
// OBJ-ARM-NEXT: e2800001 add r0, r0, #1
// ASM-THUMB: add.w r0, r0, #1
// OBJ-THUMB-NEXT: f100 0001 add.w r0, r0, #0x1
add r0, r0, 0x1