r307121 - [AMDGPU] Fix size and alignment of size_t and pointer types
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 4 21:58:24 PDT 2017
Author: yaxunl
Date: Tue Jul 4 21:58:24 2017
New Revision: 307121
URL: http://llvm.org/viewvc/llvm-project?rev=307121&view=rev
Log:
[AMDGPU] Fix size and alignment of size_t and pointer types
Differential Revision: https://reviews.llvm.org/D34995
Added:
cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/default-address-space.c
cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
cfe/trunk/test/Index/pipe-size.cl
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Jul 4 21:58:24 2017
@@ -2189,6 +2189,15 @@ public:
Triple.getEnvironmentName() == "amdgizcl" ||
!isAMDGCN(Triple));
UseAddrSpaceMapMangling = true;
+
+ // Set pointer width and alignment for target address space 0.
+ PointerWidth = PointerAlign = DataLayout->getPointerSizeInBits();
+ if (getMaxPointerWidth() == 64) {
+ LongWidth = LongAlign = 64;
+ SizeType = UnsignedLong;
+ PtrDiffType = SignedLong;
+ IntPtrType = SignedLong;
+ }
}
void setAddressSpaceMap(bool DefaultIsPrivate) {
@@ -2216,6 +2225,10 @@ public:
return 64;
}
+ uint64_t getPointerAlignV(unsigned AddrSpace) const override {
+ return getPointerWidthV(AddrSpace);
+ }
+
uint64_t getMaxPointerWidth() const override {
return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
}
@@ -2392,12 +2405,7 @@ public:
}
/// \returns Target specific vtbl ptr address space.
- unsigned getVtblPtrAddressSpace() const override {
- // \todo: We currently have address spaces defined in AMDGPU Backend. It
- // would be nice if we could use it here instead of using bare numbers (same
- // applies to getDWARFAddressSpace).
- return 2; // constant.
- }
+ unsigned getVtblPtrAddressSpace() const override { return AS.Constant; }
/// \returns If a target requires an address within a target specific address
/// space \p AddressSpace to be converted in order to be used, then return the
Modified: cfe/trunk/test/CodeGen/default-address-space.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/default-address-space.c?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/default-address-space.c (original)
+++ cfe/trunk/test/CodeGen/default-address-space.c Tue Jul 4 21:58:24 2017
@@ -50,7 +50,7 @@ void test3() {
// PIZ: %[[arrayidx:.*]] = getelementptr inbounds i32, i32 addrspace(4)* %[[r0]]
// PIZ: store i32 0, i32 addrspace(4)* %[[arrayidx]]
// CHECK-LABEL: define void @test4(i32* %a)
-// CHECK: %[[alloca:.*]] = alloca i32*, align 4, addrspace(5)
+// CHECK: %[[alloca:.*]] = alloca i32*, align 8, addrspace(5)
// CHECK: %[[a_addr:.*]] = addrspacecast{{.*}} %[[alloca]] to i32**
// CHECK: store i32* %a, i32** %[[a_addr]]
// CHECK: %[[r0:.*]] = load i32*, i32** %[[a_addr]]
Modified: cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp Tue Jul 4 21:58:24 2017
@@ -15,8 +15,8 @@ void func2(void) {
// CHECK: %lv1 = alloca i32, align 4, addrspace(5)
// CHECK: %lv2 = alloca i32, align 4, addrspace(5)
// CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
- // CHECK: %lp1 = alloca i32*, align 4, addrspace(5)
- // CHECK: %lp2 = alloca i32*, align 4, addrspace(5)
+ // CHECK: %lp1 = alloca i32*, align 8, addrspace(5)
+ // CHECK: %lp2 = alloca i32*, align 8, addrspace(5)
// CHECK: %lvc = alloca i32, align 4, addrspace(5)
// CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
@@ -34,12 +34,12 @@ void func2(void) {
la[0] = 3;
// CHECK: %[[r3:.*]] = addrspacecast i32* addrspace(5)* %lp1 to i32**
- // CHECK: store i32* %[[r0]], i32** %[[r3]], align 4
+ // CHECK: store i32* %[[r0]], i32** %[[r3]], align 8
int *lp1 = &lv1;
// CHECK: %[[r4:.*]] = addrspacecast i32* addrspace(5)* %lp2 to i32**
// CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i32 0, i32 0
- // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 4
+ // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 8
int *lp2 = la;
// CHECK: call void @_Z5func1Pi(i32* %[[r0]])
@@ -80,3 +80,5 @@ void func4(int x) {
// CHECK: call void @_Z5func1Pi(i32* %[[r0]])
func1(&x);
}
+
+// CHECK-NOT: !opencl.ocl.version
Modified: cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl Tue Jul 4 21:58:24 2017
@@ -22,8 +22,8 @@ void func2(void) {
// CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
// CL12: %lp1 = alloca i32 addrspace(5)*, align 4, addrspace(5)
// CL12: %lp2 = alloca i32 addrspace(5)*, align 4, addrspace(5)
- // CL20: %lp1 = alloca i32*, align 4, addrspace(5)
- // CL20: %lp2 = alloca i32*, align 4, addrspace(5)
+ // CL20: %lp1 = alloca i32*, align 8, addrspace(5)
+ // CL20: %lp2 = alloca i32*, align 8, addrspace(5)
// CHECK: %lvc = alloca i32, align 4, addrspace(5)
// CHECK: store i32 1, i32 addrspace(5)* %lv1
@@ -39,13 +39,13 @@ void func2(void) {
// CL12: store i32 addrspace(5)* %lv1, i32 addrspace(5)* addrspace(5)* %lp1, align 4
// CL20: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
- // CL20: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 4
+ // CL20: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 8
int *lp1 = &lv1;
// CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32] addrspace(5)* %la, i32 0, i32 0
// CL12: store i32 addrspace(5)* %[[arraydecay]], i32 addrspace(5)* addrspace(5)* %lp2, align 4
// CL20: %[[r1:.*]] = addrspacecast i32 addrspace(5)* %[[arraydecay]] to i32*
- // CL20: store i32* %[[r1]], i32* addrspace(5)* %lp2, align 4
+ // CL20: store i32* %[[r1]], i32* addrspace(5)* %lp2, align 8
int *lp2 = la;
// CL12: call void @func1(i32 addrspace(5)* %lv1)
Modified: cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl Tue Jul 4 21:58:24 2017
@@ -27,13 +27,13 @@ private char *private_p = 0;
// CHECK: @local_p = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
local char *local_p = 0;
-// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+// CHECK: @global_p = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8
global char *global_p = 0;
-// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+// CHECK: @constant_p = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8
constant char *constant_p = 0;
-// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+// CHECK: @generic_p = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8
generic char *generic_p = 0;
// Test NULL as initializer.
@@ -44,19 +44,19 @@ private char *private_p_NULL = NULL;
// CHECK: @local_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
local char *local_p_NULL = NULL;
-// CHECK: @global_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+// CHECK: @global_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8
global char *global_p_NULL = NULL;
-// CHECK: @constant_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+// CHECK: @constant_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8
constant char *constant_p_NULL = NULL;
-// CHECK: @generic_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+// CHECK: @generic_p_NULL = local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8
generic char *generic_p_NULL = NULL;
// Test constant folding of null pointer.
// A null pointer should be folded to a null pointer in the target address space.
-// CHECK: @fold_generic = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 4
+// CHECK: @fold_generic = local_unnamed_addr addrspace(1) global i32 addrspace(4)* null, align 8
generic int *fold_generic = (global int*)(generic float*)(private char*)0;
// CHECK: @fold_priv = local_unnamed_addr addrspace(1) global i16* null, align 4
@@ -104,8 +104,8 @@ int fold_int5_local = (int) &((local Str
// NOOPT: @test_static_var_private.sp3 = internal addrspace(1) global i8* null, align 4
// NOOPT: @test_static_var_private.sp4 = internal addrspace(1) global i8* null, align 4
// NOOPT: @test_static_var_private.sp5 = internal addrspace(1) global i8* null, align 4
-// NOOPT: @test_static_var_private.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4
-// NOOPT: @test_static_var_private.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 4
+// NOOPT: @test_static_var_private.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8
+// NOOPT: @test_static_var_private.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8
void test_static_var_private(void) {
static private char *sp1 = 0;
@@ -123,8 +123,8 @@ void test_static_var_private(void) {
// NOOPT: @test_static_var_local.sp3 = internal addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
// NOOPT: @test_static_var_local.sp4 = internal addrspace(1) global i8 addrspace(3)* null, align 4
// NOOPT: @test_static_var_local.sp5 = internal addrspace(1) global i8 addrspace(3)* null, align 4
-// NOOPT: @test_static_var_local.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4
-// NOOPT: @test_static_var_local.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 4
+// NOOPT: @test_static_var_local.SS1 = internal addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8
+// NOOPT: @test_static_var_local.SS2 = internal addrspace(1) global %struct.StructTy2 zeroinitializer, align 8
void test_static_var_local(void) {
static local char *sp1 = 0;
static local char *sp2 = NULL;
@@ -143,9 +143,9 @@ void test_static_var_local(void) {
// NOOPT: store i8* null, i8** %sp3, align 4
// NOOPT: store i8* null, i8** %sp4, align 4
// NOOPT: %[[SS1:.*]] = bitcast %struct.StructTy1* %SS1 to i8*
-// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_private.SS1 to i8 addrspace(2)*), i64 32, i32 4, i1 false)
+// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_private.SS1 to i8 addrspace(2)*), i64 32, i32 8, i1 false)
// NOOPT: %[[SS2:.*]] = bitcast %struct.StructTy2* %SS2 to i8*
-// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 4, i1 false)
+// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 8, i1 false)
void test_func_scope_var_private(void) {
private char *sp1 = 0;
private char *sp2 = NULL;
@@ -163,9 +163,9 @@ void test_func_scope_var_private(void) {
// NOOPT: store i8 addrspace(3)* null, i8 addrspace(3)** %sp3, align 4
// NOOPT: store i8 addrspace(3)* null, i8 addrspace(3)** %sp4, align 4
// NOOPT: %[[SS1:.*]] = bitcast %struct.StructTy1* %SS1 to i8*
-// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_local.SS1 to i8 addrspace(2)*), i64 32, i32 4, i1 false)
+// NOOPT: call void @llvm.memcpy.p0i8.p2i8.i64(i8* %[[SS1]], i8 addrspace(2)* bitcast (%struct.StructTy1 addrspace(2)* @test_func_scope_var_local.SS1 to i8 addrspace(2)*), i64 32, i32 8, i1 false)
// NOOPT: %[[SS2:.*]] = bitcast %struct.StructTy2* %SS2 to i8*
-// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 4, i1 false)
+// NOOPT: call void @llvm.memset.p0i8.i64(i8* %[[SS2]], i8 0, i64 24, i32 8, i1 false)
void test_func_scope_var_local(void) {
local char *sp1 = 0;
local char *sp2 = NULL;
@@ -189,28 +189,28 @@ private char *p1;
// CHECK: @p2 = weak local_unnamed_addr addrspace(1) global i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), align 4
local char *p2;
-// CHECK: @p3 = common local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 4
+// CHECK: @p3 = common local_unnamed_addr addrspace(1) global i8 addrspace(2)* null, align 8
constant char *p3;
-// CHECK: @p4 = common local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 4
+// CHECK: @p4 = common local_unnamed_addr addrspace(1) global i8 addrspace(1)* null, align 8
global char *p4;
-// CHECK: @p5 = common local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 4
+// CHECK: @p5 = common local_unnamed_addr addrspace(1) global i8 addrspace(4)* null, align 8
generic char *p5;
// Test default initialization of sturcture.
-// CHECK: @S1 = weak local_unnamed_addr addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 4
+// CHECK: @S1 = weak local_unnamed_addr addrspace(1) global %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, align 8
StructTy1 S1;
-// CHECK: @S2 = common local_unnamed_addr addrspace(1) global %struct.StructTy2 zeroinitializer, align 4
+// CHECK: @S2 = common local_unnamed_addr addrspace(1) global %struct.StructTy2 zeroinitializer, align 8
StructTy2 S2;
// Test default initialization of array.
-// CHECK: @A1 = weak local_unnamed_addr addrspace(1) global [2 x %struct.StructTy1] [%struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }], align 4
+// CHECK: @A1 = weak local_unnamed_addr addrspace(1) global [2 x %struct.StructTy1] [%struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }, %struct.StructTy1 { i8* null, i8 addrspace(3)* addrspacecast (i8 addrspace(4)* null to i8 addrspace(3)*), i8 addrspace(2)* null, i8 addrspace(1)* null, i8 addrspace(4)* null }], align 8
StructTy1 A1[2];
-// CHECK: @A2 = common local_unnamed_addr addrspace(1) global [2 x %struct.StructTy2] zeroinitializer, align 4
+// CHECK: @A2 = common local_unnamed_addr addrspace(1) global [2 x %struct.StructTy2] zeroinitializer, align 8
StructTy2 A2[2];
// Test comparison with 0.
@@ -597,7 +597,7 @@ int test_and_ptr(private char* p1, local
// Test folding of null pointer in function scope.
// NOOPT-LABEL: test_fold_private
// NOOPT: call void @test_fold_callee
-// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 4
+// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 8
// NOOPT: %{{.*}} = sub i64 %{{.*}}, 0
// NOOPT: call void @test_fold_callee
// NOOPT: %{{.*}} = add nsw i64 %{{.*}}, 0
@@ -612,7 +612,7 @@ void test_fold_private(void) {
// NOOPT-LABEL: test_fold_local
// NOOPT: call void @test_fold_callee
-// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 4
+// NOOPT: store i32 addrspace(1)* null, i32 addrspace(1)** %glob, align 8
// NOOPT: %{{.*}} = sub i64 %{{.*}}, 0
// NOOPT: call void @test_fold_callee
// NOOPT: %{{.*}} = add nsw i64 %{{.*}}, sext (i32 ptrtoint (i32 addrspace(3)* addrspacecast (i32 addrspace(4)* null to i32 addrspace(3)*) to i32) to i64)
Added: cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl?rev=307121&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl Tue Jul 4 21:58:24 2017
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -triple r600 -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
+
+#ifdef __AMDGCN__
+#define PTSIZE 8
+#else
+#define PTSIZE 4
+#endif
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#endif
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef global void *global_ptr_t;
+typedef constant void *constant_ptr_t;
+typedef local void *local_ptr_t;
+typedef private void *private_ptr_t;
+
+void check(bool);
+
+void test() {
+ // CHECK-NOT: call void @check(i1 zeroext false)
+ check(sizeof(size_t) == PTSIZE);
+ check(__alignof__(size_t) == PTSIZE);
+ check(sizeof(intptr_t) == PTSIZE);
+ check(__alignof__(intptr_t) == PTSIZE);
+ check(sizeof(uintptr_t) == PTSIZE);
+ check(__alignof__(uintptr_t) == PTSIZE);
+ check(sizeof(ptrdiff_t) == PTSIZE);
+ check(__alignof__(ptrdiff_t) == PTSIZE);
+
+ check(sizeof(char) == 1);
+ check(__alignof__(char) == 1);
+ check(sizeof(short) == 2);
+ check(__alignof__(short) == 2);
+ check(sizeof(int) == 4);
+ check(__alignof__(int) == 4);
+ check(sizeof(long) == 8);
+ check(__alignof__(long) == 8);
+#ifdef cl_khr_fp16
+ check(sizeof(half) == 2);
+ check(__alignof__(half) == 2);
+#endif
+ check(sizeof(float) == 4);
+ check(__alignof__(float) == 4);
+#ifdef cl_khr_fp64
+ check(sizeof(double) == 8);
+ check(__alignof__(double) == 8);
+#endif
+
+ check(sizeof(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4));
+ check(__alignof__(void*) == (__OPENCL_C_VERSION__ >= 200 ? 8 : 4));
+ check(sizeof(global_ptr_t) == PTSIZE);
+ check(__alignof__(global_ptr_t) == PTSIZE);
+ check(sizeof(constant_ptr_t) == PTSIZE);
+ check(__alignof__(constant_ptr_t) == PTSIZE);
+ check(sizeof(local_ptr_t) == 4);
+ check(__alignof__(private_ptr_t) == 4);
+}
Modified: cfe/trunk/test/Index/pipe-size.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pipe-size.cl?rev=307121&r1=307120&r2=307121&view=diff
==============================================================================
--- cfe/trunk/test/Index/pipe-size.cl (original)
+++ cfe/trunk/test/Index/pipe-size.cl Tue Jul 4 21:58:24 2017
@@ -11,6 +11,6 @@ __kernel void testPipe( pipe int test )
// SPIR: store i32 4, i32* %s, align 4
// SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8
// SPIR64: store i32 8, i32* %s, align 4
- // AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 4
+ // AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8
// AMD: store i32 8, i32 addrspace(5)* %s, align 4
}
Added: cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp?rev=307121&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp (added)
+++ cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp Tue Jul 4 21:58:24 2017
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple amdgcn---amdgiz -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef __attribute__((address_space(1))) void *global_ptr_t;
+typedef __attribute__((address_space(2))) void *constant_ptr_t;
+typedef __attribute__((address_space(3))) void *local_ptr_t;
+typedef __attribute__((address_space(5))) void *private_ptr_t;
+
+void test() {
+ static_assert(sizeof(size_t) == 8, "bad size");
+ static_assert(alignof(size_t) == 8, "bad alignment");
+ static_assert(sizeof(intptr_t) == 8, "bad size");
+ static_assert(alignof(intptr_t) == 8, "bad alignment");
+ static_assert(sizeof(uintptr_t) == 8, "bad size");
+ static_assert(alignof(uintptr_t) == 8, "bad alignment");
+ static_assert(sizeof(ptrdiff_t) == 8, "bad size");
+ static_assert(alignof(ptrdiff_t) == 8, "bad alignment");
+
+ static_assert(sizeof(char) == 1, "bad size");
+ static_assert(alignof(char) == 1, "bad alignment");
+ static_assert(sizeof(short) == 2, "bad size");
+ static_assert(alignof(short) == 2, "bad alignment");
+ static_assert(sizeof(int) == 4, "bad size");
+ static_assert(alignof(int) == 4, "bad alignment");
+ static_assert(sizeof(long) == 8, "bad size");
+ static_assert(alignof(long) == 8, "bad alignment");
+ static_assert(sizeof(long long) == 8, "bad size");
+ static_assert(alignof(long long) == 8, "bad alignment");
+ static_assert(sizeof(float) == 4, "bad size");
+ static_assert(alignof(float) == 4, "bad alignment");
+ static_assert(sizeof(double) == 8, "bad size");
+ static_assert(alignof(double) == 8, "bad alignment");
+
+ static_assert(sizeof(void*) == 8, "bad size");
+ static_assert(alignof(void*) == 8, "bad alignment");
+ static_assert(sizeof(global_ptr_t) == 8, "bad size");
+ static_assert(alignof(global_ptr_t) == 8, "bad alignment");
+ static_assert(sizeof(constant_ptr_t) == 8, "bad size");
+ static_assert(alignof(constant_ptr_t) == 8, "bad alignment");
+ static_assert(sizeof(local_ptr_t) == 4, "bad size");
+ static_assert(alignof(local_ptr_t) == 4, "bad alignment");
+ static_assert(sizeof(private_ptr_t) == 4, "bad size");
+ static_assert(alignof(private_ptr_t) == 4, "bad alignment");
+}
More information about the cfe-commits
mailing list