[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / builtins-bpf.c
blobfc540260c91c3f7b68152b24bd65e7415c3456c5
1 // RUN: %clang_cc1 -x c -triple bpf-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
3 struct s {
4 int a;
5 int b[4];
6 int c:1;
7 };
8 union u {
9 int a;
10 int b[4];
11 int c:1;
13 typedef struct {
14 int a;
15 int b;
16 } __t;
17 typedef int (*__f)(void);
18 enum AA {
19 VAL1 = 10,
20 VAL2 = 0xffffffff80000000UL,
22 typedef enum {
23 VAL10 = 10,
24 VAL11 = 11,
25 } __BB;
27 unsigned invalid1(const int *arg) {
28 return __builtin_preserve_field_info(arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
31 unsigned invalid2(const int *arg) {
32 return __builtin_preserve_field_info(*arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
35 void *invalid3(struct s *arg) {
36 return __builtin_preserve_field_info(arg->a, 1); // expected-error {{incompatible integer to pointer conversion returning 'unsigned int' from a function with result type 'void *'}}
39 unsigned valid4(struct s *arg) {
40 return __builtin_preserve_field_info(arg->b[1], 1);
43 unsigned valid5(union u *arg) {
44 return __builtin_preserve_field_info(arg->b[2], 1);
47 unsigned valid6(struct s *arg) {
48 return __builtin_preserve_field_info(arg->a, 1);
51 unsigned valid7(struct s *arg) {
52 return __builtin_preserve_field_info(arg->c, 1ULL);
55 unsigned valid8(union u *arg) {
56 return __builtin_preserve_field_info(arg->a, 1);
59 unsigned valid9(union u *arg) {
60 return __builtin_preserve_field_info(arg->c, 'a');
63 unsigned invalid10(struct s *arg) {
64 return __builtin_preserve_field_info(arg->a, arg); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
67 unsigned invalid11(struct s *arg, int info_kind) {
68 return __builtin_preserve_field_info(arg->a, info_kind); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
71 unsigned valid12(void) {
72 const struct s t;
73 return __builtin_preserve_type_info(t, 0) +
74 __builtin_preserve_type_info(*(struct s *)0, 1);
77 unsigned valid13(void) {
78 __t t;
79 return __builtin_preserve_type_info(t, 1) +
80 __builtin_preserve_type_info(*(__t *)0, 0);
83 unsigned valid14(void) {
84 enum AA t;
85 return __builtin_preserve_type_info(t, 0) +
86 __builtin_preserve_type_info(*(enum AA *)0, 1);
89 unsigned valid15(void) {
90 return __builtin_preserve_enum_value(*(enum AA *)VAL1, 1) +
91 __builtin_preserve_enum_value(*(enum AA *)VAL2, 1);
94 unsigned invalid16(void) {
95 return __builtin_preserve_enum_value(*(enum AA *)0, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
98 unsigned invalid17(void) {
99 return __builtin_preserve_enum_value(*(enum AA *)VAL10, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
102 unsigned invalid18(struct s *arg) {
103 return __builtin_preserve_type_info(arg->a + 2, 0); // expected-error {{__builtin_preserve_type_info argument 1 invalid}}