Skip to content

Commit

Permalink
[clang] Convert several tests to opaque pointers
Browse files Browse the repository at this point in the history
Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D150829
  • Loading branch information
s-barannikov committed May 18, 2023
1 parent 34e49d3 commit 0bf5f63
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 427 deletions.
14 changes: 7 additions & 7 deletions clang/test/CodeGenCXX/2011-12-19-init-list-ctor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s
// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s

struct A {
A(const char *);
Expand All @@ -18,9 +18,9 @@ struct S {
{ 2, "goodbye" }
};

// CHECK: store i32 0, i32* getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 0, i32 0)
// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 0, i32 1), i8* noundef getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
// CHECK: store i32 1, i32* getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 1, i32 0)
// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 1, i32 1), i8* noundef getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
// CHECK: store i32 2, i32* getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 2, i32 0)
// CHECK: call void @_ZN1AC1EPKc(%struct.A* {{[^,]*}} getelementptr inbounds ([3 x %struct.S], [3 x %struct.S]* @arr, i64 0, i64 2, i32 1), i8* noundef getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
// CHECK: store i32 0, ptr @arr
// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds (%struct.S, ptr @arr, i32 0, i32 1), ptr noundef @.str)
// CHECK: store i32 1, ptr getelementptr inbounds (%struct.S, ptr @arr, i64 1)
// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds (%struct.S, ptr @arr, i64 1, i32 1), ptr noundef @.str.1)
// CHECK: store i32 2, ptr getelementptr inbounds (%struct.S, ptr @arr, i64 2)
// CHECK: call void @_ZN1AC1EPKc(ptr {{[^,]*}} getelementptr inbounds (%struct.S, ptr @arr, i64 2, i32 1), ptr noundef @.str.2)
7 changes: 4 additions & 3 deletions clang/test/CodeGenCXX/address-space-cast-coerce.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -no-opaque-pointers %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s

template<typename T, unsigned int n> struct my_vector_base;

Expand Down Expand Up @@ -46,8 +46,9 @@ int mane() {
char1 f1{1};
char1 f2{1};

// CHECK: %[[a:[^ ]+]] = addrspacecast i16 addrspace(5)* %{{[^ ]+}} to i16*
// CHECK: %[[a:[^ ]+]] = addrspacecast %{{[^ ]+}} addrspace(5)* %{{[^ ]+}} to %{{[^ ]+}}
// CHECK: [[TMP:%.+]] = alloca i16
// CHECK: [[COERCE:%.+]] = addrspacecast ptr addrspace(5) [[TMP]] to ptr
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %{{.+}}, ptr align 2 [[COERCE]], i64 1, i1 false)

char1 f3 = f1 + f2;
}
59 changes: 30 additions & 29 deletions clang/test/CodeGenCXX/address-space-cast.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -no-opaque-pointers %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s

#define __private__ __attribute__((address_space(5)))

Expand All @@ -16,60 +16,61 @@ void fn(Derived *p) {
__private__ Base *b = (__private__ Base *)p;
}

// CHECK-LABEL: test_cast
void test_cast(char *gen_char_ptr, void *gen_void_ptr, int *gen_int_ptr) {
// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
__private__ char *priv_char_ptr = (__private__ char *)gen_char_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
priv_char_ptr = (__private__ char *)gen_void_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
priv_char_ptr = (__private__ char *)gen_int_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
__private__ void *priv_void_ptr = (__private__ void *)gen_char_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
priv_void_ptr = (__private__ void *)gen_void_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
priv_void_ptr = (__private__ void *)gen_int_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i32 addrspace(5)*
// CHECK-NEXT: store i32 addrspace(5)* %[[cast]]
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: store ptr addrspace(5) %[[cast]]
__private__ int *priv_int_ptr = (__private__ int *)gen_void_ptr;

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(ptr addrspace(5) noundef %[[cast]])
func_pchar((__private__ char *)gen_char_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(ptr addrspace(5) noundef %[[cast]])
func_pchar((__private__ char *)gen_void_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(ptr addrspace(5) noundef %[[cast]])
func_pchar((__private__ char *)gen_int_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(ptr addrspace(5) noundef %[[cast]])
func_pvoid((__private__ void *)gen_char_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(ptr addrspace(5) noundef %[[cast]])
func_pvoid((__private__ void *)gen_void_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(i8 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z10func_pvoidPU3AS5v(ptr addrspace(5) noundef %[[cast]])
func_pvoid((__private__ void *)gen_int_ptr);

// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i32 addrspace(5)*
// CHECK-NEXT: call void @_Z9func_pintPU3AS5i(i32 addrspace(5)* noundef %[[cast]])
// CHECK: %[[cast:.*]] = addrspacecast ptr %{{.*}} to ptr addrspace(5)
// CHECK-NEXT: call void @_Z9func_pintPU3AS5i(ptr addrspace(5) noundef %[[cast]])
func_pint((__private__ int *)gen_void_ptr);
}
27 changes: 11 additions & 16 deletions clang/test/CodeGenCXX/aix-alignment.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// REQUIRES: powerpc-registered-target
// RUN: %clang_cc1 -no-opaque-pointers -triple powerpc-unknown-aix \
// RUN: %clang_cc1 -triple powerpc-unknown-aix \
// RUN: -emit-llvm -o - -x c++ %s | \
// RUN: FileCheck %s --check-prefixes=AIX,AIX32
// RUN: %clang_cc1 -no-opaque-pointers -triple powerpc64-unknown-aix \
// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
// RUN: -emit-llvm -o - %s -x c++| \
// RUN: FileCheck %s --check-prefixes=AIX,AIX64

Expand All @@ -11,18 +11,15 @@ struct B {
~B() {}
};

// AIX32: %call = call noalias noundef nonnull i8* @_Znam(i32 noundef 8)
// AIX64: %call = call noalias noundef nonnull i8* @_Znam(i64 noundef 8)
// AIX32: %call = call noalias noundef nonnull ptr @_Znam(i32 noundef 8)
// AIX64: %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 8)
B *allocBp() { return new B[0]; }

// AIX-LABEL: delete.notnull:
// AIX32: %0 = bitcast %struct.B* %call to i8*
// AIX32: %1 = getelementptr inbounds i8, i8* %0, i32 -8
// AIX32: %2 = getelementptr inbounds i8, i8* %1, i32 4
// AIX32: %3 = bitcast i8* %2 to i32*
// AIX64: %0 = bitcast %struct.B* %call to i8*
// AIX64: %1 = getelementptr inbounds i8, i8* %0, i64 -8
// AIX64: %2 = bitcast i8* %1 to i64*
// AIX32: %0 = getelementptr inbounds i8, ptr %call, i32 -8
// AIX32: [[PTR:%.+]] = getelementptr inbounds i8, ptr %0, i32 4
// AIX64: [[PTR:%.+]] = getelementptr inbounds i8, ptr %call, i64 -8
// AIX: %{{.+}} = load i{{[0-9]+}}, ptr [[PTR]]
void bar() { delete[] allocBp(); }

typedef struct D {
Expand All @@ -32,9 +29,7 @@ typedef struct D {
~D(){};
} D;

// AIX: define void @_Z3foo1D(%struct.D* noalias sret(%struct.D) align 4 %agg.result, %struct.D* noundef %x)
// AIX: %1 = bitcast %struct.D* %agg.result to i8*
// AIX: %2 = bitcast %struct.D* %x to i8*
// AIX32 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 %2, i32 16, i1 false)
// AIX64: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %2, i64 16, i1 false)
// AIX: define void @_Z3foo1D(ptr noalias sret(%struct.D) align 4 %agg.result, ptr noundef %x)
// AIX32 call void @llvm.memcpy.p0.p0.i32(ptr align 4 %agg.result, ptr align 4 %x, i32 16, i1 false)
// AIX64: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %agg.result, ptr align 4 %x, i64 16, i1 false)
D foo(D x) { return x; }
Loading

0 comments on commit 0bf5f63

Please sign in to comment.