builtins-bpf.c
2.79 KB
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
// RUN: %clang_cc1 -x c -triple bpf-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
struct s {
int a;
int b[4];
int c:1;
};
union u {
int a;
int b[4];
int c:1;
};
typedef struct {
int a;
int b;
} __t;
typedef int (*__f)(void);
enum AA {
VAL1 = 10,
VAL2 = 0xffffffff80000000UL,
};
typedef enum {
VAL10 = 10,
VAL11 = 11,
} __BB;
unsigned invalid1(const int *arg) {
return __builtin_preserve_field_info(arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
}
unsigned invalid2(const int *arg) {
return __builtin_preserve_field_info(*arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
}
void *invalid3(struct s *arg) {
return __builtin_preserve_field_info(arg->a, 1); // expected-warning {{incompatible integer to pointer conversion returning 'unsigned int' from a function with result type 'void *'}}
}
unsigned valid4(struct s *arg) {
return __builtin_preserve_field_info(arg->b[1], 1);
}
unsigned valid5(union u *arg) {
return __builtin_preserve_field_info(arg->b[2], 1);
}
unsigned valid6(struct s *arg) {
return __builtin_preserve_field_info(arg->a, 1);
}
unsigned valid7(struct s *arg) {
return __builtin_preserve_field_info(arg->c, 1ULL);
}
unsigned valid8(union u *arg) {
return __builtin_preserve_field_info(arg->a, 1);
}
unsigned valid9(union u *arg) {
return __builtin_preserve_field_info(arg->c, 'a');
}
unsigned invalid10(struct s *arg) {
return __builtin_preserve_field_info(arg->a, arg); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
}
unsigned invalid11(struct s *arg, int info_kind) {
return __builtin_preserve_field_info(arg->a, info_kind); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
}
unsigned valid12() {
const struct s t;
return __builtin_preserve_type_info(t, 0) +
__builtin_preserve_type_info(*(struct s *)0, 1);
}
unsigned valid13() {
__t t;
return __builtin_preserve_type_info(t, 1) +
__builtin_preserve_type_info(*(__t *)0, 0);
}
unsigned valid14() {
enum AA t;
return __builtin_preserve_type_info(t, 0) +
__builtin_preserve_type_info(*(enum AA *)0, 1);
}
unsigned valid15() {
return __builtin_preserve_enum_value(*(enum AA *)VAL1, 1) +
__builtin_preserve_enum_value(*(enum AA *)VAL2, 1);
}
unsigned invalid16() {
return __builtin_preserve_enum_value(*(enum AA *)0, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
}
unsigned invalid17() {
return __builtin_preserve_enum_value(*(enum AA *)VAL10, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
}
unsigned invalid18(struct s *arg) {
return __builtin_preserve_type_info(arg->a + 2, 0); // expected-error {{__builtin_preserve_type_info argument 1 invalid}}
}