[llvm] 4d73c46 - [MCParser] Set default alignment value when meeting invalid align
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 07:23:16 PDT 2022
Author: serge-sans-paille
Date: 2022-06-02T16:22:35+02:00
New Revision: 4d73c46ccf863d49baad930e6b32bb3e4aa8c3ae
URL: https://github.com/llvm/llvm-project/commit/4d73c46ccf863d49baad930e6b32bb3e4aa8c3ae
DIFF: https://github.com/llvm/llvm-project/commit/4d73c46ccf863d49baad930e6b32bb3e4aa8c3ae.diff
LOG: [MCParser] Set default alignment value when meeting invalid align
Upon invalid alignment value, still set a default valid alignment value to avoid
hitting later asserts.
Fix #55273
Differential Revision: https://reviews.llvm.org/D125688
Added:
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/AsmParser/directive_align.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 7b98e434360ff..d0d2a435a52ff 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 91148eb635bad..0430f51740861 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
+
More information about the llvm-commits
mailing list