
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
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin %s | FileCheck %s
|
|
// <rdar://problem/11043589>
|
|
|
|
struct Length {
|
|
Length(double v) {
|
|
m_floatValue = static_cast<float>(v);
|
|
}
|
|
|
|
bool operator==(const Length& o) const {
|
|
return getFloatValue() == o.getFloatValue();
|
|
}
|
|
bool operator!=(const Length& o) const { return !(*this == o); }
|
|
private:
|
|
float getFloatValue() const {
|
|
return m_floatValue;
|
|
}
|
|
float m_floatValue;
|
|
};
|
|
|
|
|
|
struct Foo {
|
|
static Length inchLength(double inch);
|
|
static bool getPageSizeFromName(const Length &A) {
|
|
static const Length legalWidth = inchLength(8.5);
|
|
if (A != legalWidth) return true;
|
|
return false;
|
|
}
|
|
};
|
|
|
|
// CHECK: @_ZZN3Foo19getPageSizeFromNameERK6LengthE10legalWidth = linkonce_odr global %struct.Length zeroinitializer, align 4
|
|
// CHECK: store float %{{.*}}, float* getelementptr inbounds (%struct.Length, %struct.Length* @_ZZN3Foo19getPageSizeFromNameERK6LengthE10legalWidth, i32 0, i32 0), align 4
|
|
|
|
bool bar(Length &b) {
|
|
Foo f;
|
|
return f.getPageSizeFromName(b);
|
|
}
|