r194462 - XCore target requires preferred alignment.

Robert Lytton robert at xmos.com
Tue Nov 12 02:09:35 PST 2013


Author: rlytton
Date: Tue Nov 12 04:09:34 2013
New Revision: 194462

URL: http://llvm.org/viewvc/llvm-project?rev=194462&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/CodeGen/xcore-abi.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=194462&r1=194461&r2=194462&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov 12 04:09:34 2013
@@ -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::getTypeAlignInChar
 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<ComplexType>())
     T = CT->getElementType().getTypePtr();

Modified: cfe/trunk/test/CodeGen/xcore-abi.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xcore-abi.c?rev=194462&r1=194461&r2=194462&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/xcore-abi.c (original)
+++ cfe/trunk/test/CodeGen/xcore-abi.c Tue Nov 12 04:09:34 2013
@@ -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]])
 }





More information about the cfe-commits mailing list