File: address-space-cast.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (75 lines) | stat: -rw-r--r-- 3,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// RUN: %clang_cc1 -no-opaque-pointers %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s

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

void func_pchar(__private__ char *x);
void func_pvoid(__private__ void *x);
void func_pint(__private__ int *x);

class Base {
};

class Derived : public Base {
};

void fn(Derived *p) {
  __private__ Base *b = (__private__ Base *)p;
}

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]]
  __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]]
  priv_char_ptr = (__private__ char *)gen_void_ptr;

  // CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
  // CHECK-NEXT: store i8 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]]
  __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]]
  priv_void_ptr = (__private__ void *)gen_void_ptr;

  // CHECK: %[[cast:.*]] = addrspacecast i32* %{{.*}} to i8 addrspace(5)*
  // CHECK-NEXT: store i8 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]]
  __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]])
  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]])
  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]])
  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]])
  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]])
  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]])
  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]])
  func_pint((__private__ int *)gen_void_ptr);
}