Skip to content

Commit 2d42f84

Browse files
[MC] Fix emission in asm of alignment 2^32. (#98688)
The alignment amount was getting corrupted due to accidental truncation.
1 parent a10570b commit 2d42f84

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class MCAsmStreamer final : public MCStreamer {
254254
void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
255255
SMLoc Loc = SMLoc()) override;
256256

257-
void emitAlignmentDirective(unsigned ByteAlignment,
257+
void emitAlignmentDirective(uint64_t ByteAlignment,
258258
std::optional<int64_t> Value, unsigned ValueSize,
259259
unsigned MaxBytesToEmit);
260260

@@ -1478,23 +1478,23 @@ void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
14781478
EmitEOL();
14791479
}
14801480

1481-
void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
1481+
void MCAsmStreamer::emitAlignmentDirective(uint64_t ByteAlignment,
14821482
std::optional<int64_t> Value,
14831483
unsigned ValueSize,
14841484
unsigned MaxBytesToEmit) {
14851485
if (MAI->useDotAlignForAlignment()) {
1486-
if (!isPowerOf2_32(ByteAlignment))
1486+
if (!isPowerOf2_64(ByteAlignment))
14871487
report_fatal_error("Only power-of-two alignments are supported "
14881488
"with .align.");
14891489
OS << "\t.align\t";
1490-
OS << Log2_32(ByteAlignment);
1490+
OS << Log2_64(ByteAlignment);
14911491
EmitEOL();
14921492
return;
14931493
}
14941494

14951495
// Some assemblers don't support non-power of two alignments, so we always
14961496
// emit alignments as a power of two if possible.
1497-
if (isPowerOf2_32(ByteAlignment)) {
1497+
if (isPowerOf2_64(ByteAlignment)) {
14981498
switch (ValueSize) {
14991499
default:
15001500
llvm_unreachable("Invalid size for machine code value!");
@@ -1511,7 +1511,7 @@ void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
15111511
llvm_unreachable("Unsupported alignment size!");
15121512
}
15131513

1514-
OS << Log2_32(ByteAlignment);
1514+
OS << Log2_64(ByteAlignment);
15151515

15161516
if (Value.has_value() || MaxBytesToEmit) {
15171517
if (Value.has_value()) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
2+
3+
; Make sure alignment of 2^32 isn't truncated to zero.
4+
5+
; CHECK: .globl g1
6+
; CHECK-NEXT: .p2align 32, 0x0
7+
; CHECK: .globl g2
8+
; CHECK-NEXT: .p2align 32, 0x0
9+
; CHECK: .globl g3
10+
; CHECK-NEXT: .p2align 32, 0x0
11+
12+
@g1 = global i32 0, align 4294967296
13+
@g2 = global i32 33, align 4294967296
14+
@g3 = constant i32 44, align 4294967296

0 commit comments

Comments
 (0)