Index: lib/Target/XCore/XCoreAsmPrinter.cpp =================================================================== --- lib/Target/XCore/XCoreAsmPrinter.cpp +++ lib/Target/XCore/XCoreAsmPrinter.cpp @@ -123,7 +123,6 @@ MCSymbol *GVSym = getSymbol(GV); const Constant *C = GV->getInitializer(); - unsigned Align = (unsigned)TD->getPreferredTypeAlignmentShift(C->getType()); // Mark the start of the global getTargetStreamer().emitCCTopData(GVSym->getName()); @@ -152,7 +151,9 @@ llvm_unreachable("Unknown linkage type!"); } - EmitAlignment(Align > 2 ? Align : 2, GV); + // Word alignment is the minimum requirement for global variables. + // This will be rounded up to meet the GV's specifications. + EmitAlignment(2,GV); if (GV->isThreadLocal()) { report_fatal_error("TLS is not supported by this target!"); Index: test/CodeGen/XCore/constants.ll =================================================================== --- test/CodeGen/XCore/constants.ll +++ test/CodeGen/XCore/constants.ll @@ -17,3 +17,57 @@ ; CHECK: retsp 0 ret i32 1; } + + +; Rules governing how .align directives are calculated. + +; section & align: use align. +@cg1 = constant i32 0, section ".NAMEDSECT", align 2 +; CHECK: .section .NAMEDSECT,"ad",@progbits +; CHECK: .globl cg1 +; CHECK: .align 2 +; CHECK: size cg1, 4 + +; section & no align: use max of type alignment & 4. +@cg2 = constant i64 0, section ".NAMEDSECT" +; CHECK: .globl cg2 +; CHECK: .align 4 +; CHECK: size cg2, 8 + +; section & no align: use max of type alignment & 4. +@cg3 = constant i8 0, section ".NAMEDSECT" +; CHECK: .globl cg3 +; CHECK: .align 4 +; CHECK: size cg3, 1 + +; align: use max of align, type alignment & 4. +@cg4 = constant i8 0, align 2 +; CHECK: .section .dp.rodata,"awd",@progbits +; CHECK: .globl cg4 +; CHECK: .align 4 +; CHECK: .size cg4, 1 + +; align: use max of align, type alignment & 4. +@cg5 = constant i8 0, align 8 +; CHECK: .globl cg5 +; CHECK: .align 8 +; CHECK: .size cg5, 1 + +; align: use max of align, type alignment & 4. +@cg6 = constant i64 0, align 2 +; CHECK: .globl cg6 +; CHECK: .align 4 +; CHECK: .size cg6, 8 + +; : use max of type alignment & 4. +@cg7 = constant i64 0, align 2 +; CHECK: .globl cg7 +; CHECK: .align 4 +; CHECK: .size cg7, 8 + +; : use max of type alignment & 4. +@cg8 = constant i8 0, align 2 +; CHECK: .globl cg8 +; CHECK: .align 4 +; CHECK: .size cg8, 1 +