diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 7b98e434360f..d0d2a435a52f 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -3451,10 +3451,14 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { // up to one. if (Alignment == 0) Alignment = 1; - if (!isPowerOf2_64(Alignment)) + else if (!isPowerOf2_64(Alignment)) { ReturnVal |= Error(AlignmentLoc, "alignment must be a power of 2"); - if (!isUInt<32>(Alignment)) + Alignment = PowerOf2Floor(Alignment); + } + if (!isUInt<32>(Alignment)) { ReturnVal |= Error(AlignmentLoc, "alignment must be smaller than 2**32"); + Alignment = 1u << 31; + } } // Diagnose non-sensical max bytes to align. diff --git a/llvm/test/MC/AsmParser/directive_align.s b/llvm/test/MC/AsmParser/directive_align.s index 91148eb635ba..0430f5174086 100644 --- a/llvm/test/MC/AsmParser/directive_align.s +++ b/llvm/test/MC/AsmParser/directive_align.s @@ -12,10 +12,25 @@ TEST1: .align32 3,,2 # CHECK: TEST2: -# CHECK: .balign 3, 10 +# CHECK-WARN: error: alignment must be a power of 2 +# CHECK: .p2align 1, 0xa TEST2: .balign 3,10 # CHECK-WARN: p2align directive with no operand(s) is ignored TEST3: .p2align + +# CHECK: TEST4: +# CHECK: .p2align 31, 0x90 +# CHECK-WARN: error: alignment must be smaller than 2**32 +TEST4: + .balign 0x100000000, 0x90 + +# CHECK: TEST5: +# CHECK: .p2align 31, 0x90 +# CHECK-WARN: error: alignment must be a power of 2 +# CHECK-WARN: error: alignment must be smaller than 2**32 +TEST5: + .balign 0x100000001, 0x90 +