annotate clang/test/Sema/builtins-bpf.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -x c -triple bpf-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
3 struct s {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
4 int a;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
5 int b[4];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
6 int c:1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
7 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
8 union u {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9 int a;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
10 int b[4];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 int c:1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
13 typedef struct {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
14 int a;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 int b;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
16 } __t;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
17 typedef int (*__f)(void);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
18 enum AA {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
19 VAL1 = 10,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20 VAL2 = 0xffffffff80000000UL,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
21 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
22 typedef enum {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
23 VAL10 = 10,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 VAL11 = 11,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 } __BB;
150
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 unsigned invalid1(const int *arg) {
anatofuz
parents:
diff changeset
28 return __builtin_preserve_field_info(arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 unsigned invalid2(const int *arg) {
anatofuz
parents:
diff changeset
32 return __builtin_preserve_field_info(*arg, 1); // expected-error {{__builtin_preserve_field_info argument 1 not a field access}}
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 void *invalid3(struct s *arg) {
anatofuz
parents:
diff changeset
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 *'}}
anatofuz
parents:
diff changeset
37 }
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 unsigned valid4(struct s *arg) {
anatofuz
parents:
diff changeset
40 return __builtin_preserve_field_info(arg->b[1], 1);
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 unsigned valid5(union u *arg) {
anatofuz
parents:
diff changeset
44 return __builtin_preserve_field_info(arg->b[2], 1);
anatofuz
parents:
diff changeset
45 }
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 unsigned valid6(struct s *arg) {
anatofuz
parents:
diff changeset
48 return __builtin_preserve_field_info(arg->a, 1);
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 unsigned valid7(struct s *arg) {
anatofuz
parents:
diff changeset
52 return __builtin_preserve_field_info(arg->c, 1ULL);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 unsigned valid8(union u *arg) {
anatofuz
parents:
diff changeset
56 return __builtin_preserve_field_info(arg->a, 1);
anatofuz
parents:
diff changeset
57 }
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 unsigned valid9(union u *arg) {
anatofuz
parents:
diff changeset
60 return __builtin_preserve_field_info(arg->c, 'a');
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 unsigned invalid10(struct s *arg) {
anatofuz
parents:
diff changeset
64 return __builtin_preserve_field_info(arg->a, arg); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
anatofuz
parents:
diff changeset
65 }
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 unsigned invalid11(struct s *arg, int info_kind) {
anatofuz
parents:
diff changeset
68 return __builtin_preserve_field_info(arg->a, info_kind); // expected-error {{__builtin_preserve_field_info argument 2 not a constant}}
anatofuz
parents:
diff changeset
69 }
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
71 unsigned valid12() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
72 const struct s t;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
73 return __builtin_preserve_type_info(t, 0) +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
74 __builtin_preserve_type_info(*(struct s *)0, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
75 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
76
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
77 unsigned valid13() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
78 __t t;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
79 return __builtin_preserve_type_info(t, 1) +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
80 __builtin_preserve_type_info(*(__t *)0, 0);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
81 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
82
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
83 unsigned valid14() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
84 enum AA t;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
85 return __builtin_preserve_type_info(t, 0) +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
86 __builtin_preserve_type_info(*(enum AA *)0, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
87 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
88
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
89 unsigned valid15() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
90 return __builtin_preserve_enum_value(*(enum AA *)VAL1, 1) +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
91 __builtin_preserve_enum_value(*(enum AA *)VAL2, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
92 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
93
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
94 unsigned invalid16() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
95 return __builtin_preserve_enum_value(*(enum AA *)0, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
96 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
97
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
98 unsigned invalid17() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
99 return __builtin_preserve_enum_value(*(enum AA *)VAL10, 1); // expected-error {{__builtin_preserve_enum_value argument 1 invalid}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
100 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
102 unsigned invalid18(struct s *arg) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
103 return __builtin_preserve_type_info(arg->a + 2, 0); // expected-error {{__builtin_preserve_type_info argument 1 invalid}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
104 }