File: arm64-mte.c

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,418,812 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (110 lines) | stat: -rw-r--r-- 4,139 bytes parent folder | download | duplicates (6)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Test memory tagging extension intrinsics
// RUN: %clang_cc1 -triple aarch64-none-linux-eabi -target-feature +mte -O3 -S -emit-llvm -o - %s  | FileCheck %s
#include <stddef.h>
#include <arm_acle.h>

// CHECK-LABEL: define{{.*}} i32* @create_tag1
int *create_tag1(int *a, unsigned b) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call i8* @llvm.aarch64.irg(i8* [[T0]], i64 [[T1]])
// CHECK: bitcast i8* [[T2]] to i32*
        return __arm_mte_create_random_tag(a,b);
}

// CHECK-LABEL: define{{.*}} i16* @create_tag2
short *create_tag2(short *a, unsigned b) {
// CHECK: [[T0:%[0-9]+]] = bitcast i16* %a to i8*
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call i8* @llvm.aarch64.irg(i8* [[T0]], i64 [[T1]])
// CHECK: bitcast i8* [[T2]] to i16*
        return __arm_mte_create_random_tag(a,b);
}

// CHECK-LABEL: define{{.*}} i8* @create_tag3
char *create_tag3(char *a, unsigned b) {
// CHECK: [[T1:%[0-9]+]] = zext i32 %b to i64
// CHECK: [[T2:%[0-9]+]] = tail call i8* @llvm.aarch64.irg(i8* %a, i64 [[T1]])
// CHECK: ret i8* [[T2:%[0-9]+]]
        return __arm_mte_create_random_tag(a,b);
}

// CHECK-LABEL: define{{.*}} i8* @increment_tag1
char *increment_tag1(char *a) {
// CHECK: call i8* @llvm.aarch64.addg(i8* %a, i64 3)
        return __arm_mte_increment_tag(a,3);
}

// CHECK-LABEL: define{{.*}} i16* @increment_tag2
short *increment_tag2(short *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i16* %a to i8*
// CHECK: [[T1:%[0-9]+]] = tail call i8* @llvm.aarch64.addg(i8* [[T0]], i64 3)
// CHECK: [[T2:%[0-9]+]]  = bitcast i8* [[T1]] to i16*
        return __arm_mte_increment_tag(a,3);
}

// CHECK-LABEL: define{{.*}} i32 @exclude_tag
unsigned exclude_tag(int *a, unsigned m) {
// CHECK: [[T0:%[0-9]+]] = zext i32 %m to i64
// CHECK: [[T1:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T2:%[0-9]+]] = tail call i64 @llvm.aarch64.gmi(i8* [[T1]], i64 [[T0]])
// CHECK: trunc i64 [[T2]] to i32
  return __arm_mte_exclude_tag(a, m);
}

// CHECK-LABEL: define{{.*}} i32* @get_tag1
int *get_tag1(int *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T1:%[0-9]+]] = tail call i8* @llvm.aarch64.ldg(i8* [[T0]], i8* [[T0]])
// CHECK: [[T2:%[0-9]+]]  = bitcast i8* [[T1]] to i32*
   return __arm_mte_get_tag(a);
}

// CHECK-LABEL: define{{.*}} i16* @get_tag2
short *get_tag2(short *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i16* %a to i8*
// CHECK: [[T1:%[0-9]+]] = tail call i8* @llvm.aarch64.ldg(i8* [[T0]], i8* [[T0]])
// CHECK: [[T2:%[0-9]+]]  = bitcast i8* [[T1]] to i16*
   return __arm_mte_get_tag(a);
}

// CHECK-LABEL: define{{.*}} void @set_tag1
void set_tag1(int *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: tail call void @llvm.aarch64.stg(i8* [[T0]], i8* [[T0]])
   __arm_mte_set_tag(a);
}

// CHECK-LABEL: define{{.*}} i64 @subtract_pointers
ptrdiff_t subtract_pointers(int *a, int *b) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T1:%[0-9]+]] = bitcast i32* %b to i8*
// CHECK: [[T2:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(i8* [[T0]], i8* [[T1]])
// CHECK: ret i64 [[T2]]
   return __arm_mte_ptrdiff(a, b);
}

// CHECK-LABEL: define{{.*}} i64 @subtract_pointers_null_1
ptrdiff_t subtract_pointers_null_1(int *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T1:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(i8* [[T0]], i8* null)
// CHECK: ret i64 [[T1]]
   return __arm_mte_ptrdiff(a, NULL);
}

// CHECK-LABEL: define{{.*}} i64 @subtract_pointers_null_2
ptrdiff_t subtract_pointers_null_2(int *a) {
// CHECK: [[T0:%[0-9]+]] = bitcast i32* %a to i8*
// CHECK: [[T1:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(i8* null, i8* [[T0]])
// CHECK: ret i64 [[T1]]
   return __arm_mte_ptrdiff(NULL, a);
}

// Check arithmetic promotion on return type
// CHECK-LABEL: define{{.*}} i32 @subtract_pointers4
int subtract_pointers4(void* a, void *b) {
// CHECK: [[T0:%[0-9]+]] = tail call i64 @llvm.aarch64.subp(i8* %a, i8* %b)
// CHECK-NEXT: %cmp = icmp slt i64 [[T0]], 1
// CHECK-NEXT:  = zext i1 %cmp to i32
  return __arm_mte_ptrdiff(a,b) <= 0;
}