1 // RUN: %clang_cc1 -x c -triple bpf-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
2 
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;
12 };
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,
21 };
22 typedef enum {
23   VAL10 = 10,
24   VAL11 = 11,
25 } __BB;
26 
invalid1(const int * arg)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}}
29 }
30 
invalid2(const int * arg)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}}
33 }
34 
invalid3(struct s * arg)35 void *invalid3(struct s *arg) {
36   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 *'}}
37 }
38 
valid4(struct s * arg)39 unsigned valid4(struct s *arg) {
40   return __builtin_preserve_field_info(arg->b[1], 1);
41 }
42 
valid5(union u * arg)43 unsigned valid5(union u *arg) {
44   return __builtin_preserve_field_info(arg->b[2], 1);
45 }
46 
valid6(struct s * arg)47 unsigned valid6(struct s *arg) {
48   return __builtin_preserve_field_info(arg->a, 1);
49 }
50 
valid7(struct s * arg)51 unsigned valid7(struct s *arg) {
52   return __builtin_preserve_field_info(arg->c, 1ULL);
53 }
54 
valid8(union u * arg)55 unsigned valid8(union u *arg) {
56   return __builtin_preserve_field_info(arg->a, 1);
57 }
58 
valid9(union u * arg)59 unsigned valid9(union u *arg) {
60   return __builtin_preserve_field_info(arg->c, 'a');
61 }
62 
invalid10(struct s * arg)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}}
65 }
66 
invalid11(struct s * arg,int info_kind)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}}
69 }
70 
valid12()71 unsigned valid12() {
72   const struct s t;
73   return __builtin_preserve_type_info(t, 0) +
74          __builtin_preserve_type_info(*(struct s *)0, 1);
75 }
76 
valid13()77 unsigned valid13() {
78   __t t;
79   return __builtin_preserve_type_info(t, 1) +
80          __builtin_preserve_type_info(*(__t *)0, 0);
81 }
82 
valid14()83 unsigned valid14() {
84   enum AA t;
85   return __builtin_preserve_type_info(t, 0) +
86          __builtin_preserve_type_info(*(enum AA *)0, 1);
87 }
88 
valid15()89 unsigned valid15() {
90   return __builtin_preserve_enum_value(*(enum AA *)VAL1, 1) +
91          __builtin_preserve_enum_value(*(enum AA *)VAL2, 1);
92 }
93 
invalid16()94 unsigned invalid16() {
95   return __builtin_preserve_enum_value(*(enum AA *)0, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
96 }
97 
invalid17()98 unsigned invalid17() {
99   return __builtin_preserve_enum_value(*(enum AA *)VAL10, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
100 }
101 
invalid18(struct s * arg)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}}
104 }
105