Debian Codegraph @

clang/test/PCH/unsafe-buffer-usage-pragma-pch-complex.cpp

raw
1 // Test PCHs:
2 // MAIN - includes textual_1.h
3 // \ loads pch_1.h - includes textual_2.h
4 // \ loads pch_2.h
5
6 // RUN: rm -rf %t
7 // RUN: mkdir -p %t
8 // RUN: split-file %s %t
9
10 // RUN: %clang_cc1 -Wno-unused-value -std=c++20 -emit-pch -o %t/pch_2.h.pch %t/pch_2.h -x c++
11 // RUN: %clang_cc1 -Wno-unused-value -std=c++20 -include-pch %t/pch_2.h.pch -emit-pch -o %t/pch_1.h.pch %t/pch_1.h -x c++
12 // RUN: %clang_cc1 -Wno-unused-value -std=c++20 -include-pch %t/pch_1.h.pch -verify %t/main.cpp -Wunsafe-buffer-usage
13
14
15 //--- textual_1.h
16 int a(int *s) {
17 s[2]; // <- expected warning here
18 #pragma clang unsafe_buffer_usage begin
19 return s[1];
20 #pragma clang unsafe_buffer_usage end
21 }
22
23 //--- textual_2.h
24 int b(int *s) {
25 s[2]; // <- expected warning here
26 #pragma clang unsafe_buffer_usage begin
27 return s[1];
28 #pragma clang unsafe_buffer_usage end
29 }
30
31 //--- pch_1.h
32 #include "textual_2.h"
33
34 int c(int *s) {
35 s[2]; // <- expected warning here
36 #pragma clang unsafe_buffer_usage begin
37 return s[1];
38 #pragma clang unsafe_buffer_usage end
39 }
40
41 //--- pch_2.h
42 int d(int *s) {
43 s[2]; // <- expected warning here
44 #pragma clang unsafe_buffer_usage begin
45 return s[1];
46 #pragma clang unsafe_buffer_usage end
47 }
48
49
50 //--- main.cpp
51 #include "textual_1.h"
52 // expected-warning@textual_1.h:2{{unsafe buffer access}} \
53 expected-note@textual_1.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}
54 // expected-warning@textual_2.h:2{{unsafe buffer access}} \
55 expected-note@textual_2.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}
56 // expected-warning@pch_1.h:4{{unsafe buffer access}} \
57 expected-note@pch_1.h:4{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}
58 // expected-warning@pch_2.h:2{{unsafe buffer access}} \
59 expected-note@pch_2.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}
60 int main() {
61 int s[] = {1, 2, 3};
62 return a(s) + b(s) + c(s) + d(s);
63 }