teak-llvm/clang/test/CodeGen/align-systemz.c
Ulrich Weigand 6e2cea6f0c Respect alignment when loading up a coerced function argument
Code in CGCall.cpp that loads up function arguments that need to be
coerced to a different type may in some cases ignore the fact that
the source of the argument is not naturally aligned. This may cause
incorrect code to be generated. In some places in CreateCoercedLoad,
we already have setAlignment calls to address this, but I ran into one
where it was missing, causing wrong code generation on SystemZ.

However, in that location, we do not actually know what alignment of
the source location we can rely on; the callers do not pass anything
to this routine. This is already an issue in other places in
CreateCoercedLoad; and the same problem exists for CreateCoercedStore.

To avoid pessimising code, and to fix the FIXMEs already in place,
this patch also adds an alignment argument to the CreateCoerced*
routines and uses it instead of forcing an alignment of 1. The
callers are changed to pass in the best information they have.

This actually requires changes in a number of existing test cases
since we now get better alignment in many places.

Differential Revision: http://reviews.llvm.org/D11033

llvm-svn: 241898
2015-07-10 11:31:43 +00:00

44 lines
888 B
C

// RUN: %clang_cc1 -triple s390x-linux-gnu -emit-llvm %s -o - | FileCheck %s
// SystemZ prefers to align all global variables to two bytes.
struct test {
signed char a;
};
char c;
// CHECK-DAG: @c = common global i8 0, align 2
struct test s;
// CHECK-DAG: @s = common global %struct.test zeroinitializer, align 2
extern char ec;
// CHECK-DAG: @ec = external global i8, align 2
extern struct test es;
// CHECK-DAG: @es = external global %struct.test, align 2
// Dummy function to make sure external symbols are used.
void func (void)
{
c = ec;
s = es;
}
// Alignment should be respected for coerced argument loads
struct arg { long y __attribute__((packed, aligned(4))); };
extern struct arg x;
void f(struct arg);
void test (void)
{
f(x);
}
// CHECK-LABEL: @test
// CHECK: load i64, i64* getelementptr inbounds (%struct.arg, %struct.arg* @x, i32 0, i32 0), align 4