Skip to content

Commit db6655f

Browse files
committedFeb 10, 2016
[X86] Fix stack alignment for MCU target (Clang part), by Anton Nadolskiy.
This patch fixes stack alignments for MCU (should be aligned to 4 bytes). Differential Revision: http://reviews.llvm.org/D15647 llvm-svn: 260376
1 parent 2396c38 commit db6655f

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed
 

‎clang/include/clang/Basic/TargetInfo.h

+3
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ class TargetInfo : public RefCountedBase<TargetInfo> {
940940
return false;
941941
}
942942

943+
/// \brief Whether target allows to overalign ABI-specified prefered alignment
944+
virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
945+
943946
protected:
944947
virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
945948
return PointerWidth;

‎clang/lib/AST/ASTContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1904,8 +1904,8 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
19041904
if (T->isMemberPointerType())
19051905
return getPreferredTypeAlign(getPointerDiffType().getTypePtr());
19061906

1907-
if (Target->getTriple().getArch() == llvm::Triple::xcore)
1908-
return ABIAlign; // Never overalign on XCore.
1907+
if (!Target->allowsLargerPreferedTypeAlignment())
1908+
return ABIAlign;
19091909

19101910
// Double and long long should be naturally aligned if possible.
19111911
if (const ComplexType *CT = T->getAs<ComplexType>())

‎clang/lib/Basic/Targets.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,8 @@ class MicrosoftX86_32TargetInfo : public WindowsX86_32TargetInfo {
38073807
: WindowsX86_32TargetInfo(Triple) {
38083808
LongDoubleWidth = LongDoubleAlign = 64;
38093809
LongDoubleFormat = &llvm::APFloat::IEEEdouble;
3810+
DataLayoutString =
3811+
"e-m:e-p:32:32-i64:32-f64:32-f128:32-n8:16:32-a:0:32-S32";
38103812
}
38113813
void getTargetDefines(const LangOptions &Opts,
38123814
MacroBuilder &Builder) const override {
@@ -3926,6 +3928,10 @@ class MCUX86_32TargetInfo : public X86_32TargetInfo {
39263928
Builder.defineMacro("__iamcu");
39273929
Builder.defineMacro("__iamcu__");
39283930
}
3931+
3932+
bool allowsLargerPreferedTypeAlignment() const override {
3933+
return false;
3934+
}
39293935
};
39303936

39313937
// RTEMS Target
@@ -7491,6 +7497,9 @@ class XCoreTargetInfo : public TargetInfo {
74917497
// R0=ExceptionPointerRegister R1=ExceptionSelectorRegister
74927498
return (RegNo < 2)? RegNo : -1;
74937499
}
7500+
bool allowsLargerPreferedTypeAlignment() const override {
7501+
return false;
7502+
}
74947503
};
74957504

74967505
const Builtin::Info XCoreTargetInfo::BuiltinInfo[] = {

‎clang/test/CodeGen/iamcu-abi.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %clang_cc1 -triple i386-pc-elfiamcu -emit-llvm -o - %s | FileCheck %s
2+
3+
// CHECK: target datalayout = "e-m:e-p:32:32-i64:32-f64:32-f128:32-n8:16:32-a:0:32-S32"
4+
// CHECK: target triple = "i386-pc-elfiamcu"
5+
6+
7+
void food(double *d);
8+
void fooll(long long *ll);
9+
void fooull(unsigned long long *ull);
10+
void foold(long double *ld);
11+
12+
// CHECK-LABEL: define void @testdouble()
13+
// CHECK: alloca double, align 4
14+
void testdouble() {
15+
double d = 2.0;
16+
food(&d);
17+
}
18+
19+
// CHECK-LABEL: define void @testlonglong()
20+
// CHECK: alloca i64, align 4
21+
void testlonglong() {
22+
long long ll = 2;
23+
fooll(&ll);
24+
}
25+
26+
// CHECK-LABEL: define void @testunsignedlonglong()
27+
// CHECK: alloca i64, align 4
28+
void testunsignedlonglong() {
29+
unsigned long long ull = 2;
30+
fooull(&ull);
31+
}
32+
33+
// CHECK-LABEL: define void @testlongdouble()
34+
// CHECK: alloca double, align 4
35+
void testlongdouble() {
36+
long double ld = 2.0;
37+
foold(&ld);
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.