Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -4505,12 +4505,12 @@ const MCConstantExpr *MCE = dyn_cast(Value); if (!MCE) return Error(ExprLoc, "unexpected expression in align"); - uint64_t IntValue = MCE->getValue(); - if (!isPowerOf2_64(IntValue)) - return Error(ExprLoc, "literal value not a power of two greater then zero"); - - Info.AsmRewrites->push_back( - AsmRewrite(AOK_Align, IDLoc, 5, Log2_64(IntValue))); + int64_t IntValue = MCE->getValue(); + if (MAI.getAlignmentIsInBytes()){ + if (!isPowerOf2_64(IntValue)) + return Error(ExprLoc, "literal value not a power of two greater then zero"); + } + Info.AsmRewrites->emplace_back(AOK_Align, IDLoc, 5); return false; } @@ -4676,7 +4676,6 @@ continue; } - unsigned AdditionalSkip = 0; // Rewrite expressions in $N notation. switch (Kind) { default: @@ -4712,12 +4711,7 @@ OS << ".byte"; break; case AOK_Align: { - unsigned Val = AR.Val; - OS << ".align " << Val; - - // Skip the original immediate. - assert(Val < 10 && "Expected alignment less then 2^10."); - AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4; + OS << ".align"; break; } case AOK_DotOperator: @@ -4730,7 +4724,7 @@ } // Skip the original expression. - AsmStart = Loc + AR.Len + AdditionalSkip; + AsmStart = Loc + AR.Len ; } // Emit the remainder of the asm string. Index: test/CodeGen/ms-inline-asm-align-with-error.c =================================================================== --- test/CodeGen/ms-inline-asm-align-with-error.c +++ test/CodeGen/ms-inline-asm-align-with-error.c @@ -0,0 +1,17 @@ +// RUN:not %clang_cc1 %s -ferror-limit 0 -triple x87_64-pc-windows-msvc -fasm-blocks -S -o - | FileCheck %s -check-prefix MICROSOFT +// RUN:not %clang_cc1 %s -ferror-limit 0 -triple i386-apple-darwin10 -fasm-blocks -S -o - | FileCheck %s -check-prefix DARWIN +int main() +{ + // DARWIN-NOT: error: + // MICROSOFT-NOT: error: + asm{align 2} + // DARWIN-NOT: error: + // MICROSOFT: error: literal value not a power of two greater then zero + // MICROSOFT: asm{align 5} + asm{align 5} + // DARWIN: error: invalid alignment value + // DARWIN: asm{align 32} + // MICROSOFT-NOT: error: + asm{align 32} + return 0; +} Index: test/CodeGen/ms-inline-asm-align.c =================================================================== --- test/CodeGen/ms-inline-asm-align.c +++ test/CodeGen/ms-inline-asm-align.c @@ -0,0 +1,15 @@ +// RUN:%clang_cc1 %s -ferror-limit 0 -triple x87_64-pc-windows-msvc -fasm-blocks -S -o - | FileCheck %s -check-prefix MICROSOFT +// RUN:%clang_cc1 %s -ferror-limit 0 -triple i386-apple-darwin10 -fasm-blocks -S -o - | FileCheck %s -check-prefix DARWIN +int main() +{ +// DARWIN: .align 2 +// MICROSOFT: .align 2 +asm{align 2} +// DARWIN: .aligm 4 +// MICROSOFT: .align 4 +asm{align 4} +// DARWIN: .align 8 +// MICROSOFT: .align 8 +asm{align 8} +return 0; +} Index: test/CodeGen/ms-inline-asm.c =================================================================== --- test/CodeGen/ms-inline-asm.c +++ test/CodeGen/ms-inline-asm.c @@ -291,13 +291,13 @@ void t28() { // CHECK: t28 __asm align 8 -// CHECK: .align 3 - __asm align 16; -// CHECK: .align 4 - __asm align 128; -// CHECK: .align 7 - __asm ALIGN 256; // CHECK: .align 8 + __asm align 16; +// CHECK: .align 16 + __asm align 20; +// CHECK: .align 20 + __asm ALIGN 31; +// CHECK: .align 31 // CHECK: "~{dirflag},~{fpsr},~{flags}"() }