llvm-project/llvm/test/MC/RISCV/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

30 lines
949 B
ArmAsm

// RUN: llvm-mc -triple riscv32 %s -o - | FileCheck %s --check-prefix=ASM
// RUN: llvm-mc -triple riscv32 -filetype obj %s -o - | \
// RUN: llvm-objdump -dz - | FileCheck %s --check-prefix=OBJ
// RUN: llvm-mc -triple riscv64 %s -o - | FileCheck %s --check-prefix=ASM
// RUN: llvm-mc -triple riscv64 -filetype obj %s -o - | \
// RUN: llvm-objdump -dz - | FileCheck %s --check-prefix=OBJ
// llvm.org/pr30955 - LLVM was handling `.balign <alignment>, 0` strangely on
// non-x86 targets.
.text
// ASM: addi a0, a0, 1
// OBJ: 00150513 addi a0, a0, 0x1
addi a0, a0, 0x1
// ASM: .p2align 4, 0x0
// OBJ-NEXT: 0000 <unknown>
// OBJ-NEXT: 0000 <unknown>
// OBJ-NEXT: 0000 <unknown>
// OBJ-NEXT: 0000 <unknown>
// OBJ-NEXT: 0000 <unknown>
// OBJ-NEXT: 0000 <unknown>
.balign 0x10, 0
// ASM: addi a0, a0, 1
// OBJ-NEXT: 00150513 addi a0, a0, 0x1
addi a0, a0, 0x1