From e39ff50fd72e9ffaa28f141a5c9bb22f1b8f2844 Mon Sep 17 00:00:00 2001 From: Robert Lytton Date: Tue, 12 Nov 2013 10:09:34 +0000 Subject: [PATCH] XCore target requires preferred alignment. The xcore llvm backend does not handle 8 byte alignment viz: "%BadAlignment = alloca i64, align 8" So getPreferredTypeAlign() must never overalign. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194462 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 4 ++++ test/CodeGen/xcore-abi.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 6729986c8d..a03cf9e7d4 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -34,6 +34,7 @@ #include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -1757,6 +1758,9 @@ CharUnits ASTContext::getTypeAlignInChars(const Type *T) const { unsigned ASTContext::getPreferredTypeAlign(const Type *T) const { unsigned ABIAlign = getTypeAlign(T); + if (Target->getTriple().getArch() == llvm::Triple::xcore) + return ABIAlign; // Never overalign on XCore. + // Double and long long should be naturally aligned if possible. if (const ComplexType* CT = T->getAs()) T = CT->getElementType().getTypePtr(); diff --git a/test/CodeGen/xcore-abi.c b/test/CodeGen/xcore-abi.c index 56bec3d6b3..10881de7ce 100644 --- a/test/CodeGen/xcore-abi.c +++ b/test/CodeGen/xcore-abi.c @@ -1,3 +1,10 @@ +// RUN: %clang_cc1 -triple xcore -verify %s +_Static_assert(sizeof(long long) == 8, "sizeof long long is wrong"); +_Static_assert(_Alignof(long long) == 4, "alignof long long is wrong"); + +_Static_assert(sizeof(double) == 8, "sizeof double is wrong"); +_Static_assert(_Alignof(double) == 4, "alignof double is wrong"); + // RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s // CHECK: target datalayout = "e-p:32:32:32-a0:0:32-n32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f16:16:32-f32:32:32-f64:32:32" @@ -28,7 +35,7 @@ void testva (int n, ...) { // CHECK: [[V2:%[a-z0-9]+]] = load i8** [[V]], align 4 // CHECK: call void @f(i8* [[V2]]) - char v2 = va_arg (ap, char); + char v2 = va_arg (ap, char); // expected-warning{{second argument to 'va_arg' is of promotable type 'char'}} f(&v2); // CHECK: [[I:%[a-z0-9]+]] = load i8** [[AP]] // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 4 @@ -55,7 +62,7 @@ void testva (int n, ...) { // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 8 // CHECK: store i8* [[IN]], i8** [[AP]] // CHECK: [[V1:%[a-z0-9]+]] = load i64* [[P]] - // CHECK: store i64 [[V1]], i64* [[V:%[a-z0-9]+]], align 8 + // CHECK: store i64 [[V1]], i64* [[V:%[a-z0-9]+]], align 4 // CHECK:[[V2:%[a-z0-9]+]] = bitcast i64* [[V]] to i8* // CHECK: call void @f(i8* [[V2]]) @@ -95,7 +102,7 @@ void testva (int n, ...) { // CHECK: [[IN:%[a-z0-9]+]] = getelementptr i8* [[I]], i32 8 // CHECK: store i8* [[IN]], i8** [[AP]] // CHECK: [[V1:%[a-z0-9]+]] = load double* [[P]] - // CHECK: store double [[V1]], double* [[V:%[a-z0-9]+]], align 8 + // CHECK: store double [[V1]], double* [[V:%[a-z0-9]+]], align 4 // CHECK: [[V2:%[a-z0-9]+]] = bitcast double* [[V]] to i8* // CHECK: call void @f(i8* [[V2]]) } -- 2.40.0