From 5bd1a50ca220d9a2280b9639da57284ad30961ab Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 8 Sep 2015 18:59:47 +0000 Subject: [PATCH] [MC/ELF] Accept zero for .align directive .align directive refuses alignment 0 -- a comment in the code hints this is done for GNU as compatibility, but it seems GNU as accepts .align 0 (and silently rounds up alignment to 1). Differential Revision: http://reviews.llvm.org/D12682 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247048 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 6 +++++- test/MC/ELF/align-zero.s | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/MC/ELF/align-zero.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 5e174de8a93..7126a909b9e 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -2706,7 +2706,11 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { Alignment = 1ULL << Alignment; } else { - // Reject alignments that aren't a power of two, for gas compatibility. + // Reject alignments that aren't either a power of two or zero, + // for gas compatibility. Alignment of zero is silently rounded + // up to one. + if (Alignment == 0) + Alignment = 1; if (!isPowerOf2_64(Alignment)) Error(AlignmentLoc, "alignment must be a power of 2"); } diff --git a/test/MC/ELF/align-zero.s b/test/MC/ELF/align-zero.s new file mode 100644 index 00000000000..d8087d127d2 --- /dev/null +++ b/test/MC/ELF/align-zero.s @@ -0,0 +1,4 @@ +// Test that an alignment of zero is accepted. +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - + + .align 0 -- 2.34.1