Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-unsafe-buffer-usage-function-attr.cpp
blob7df01c46438c79bf9c895415eceec410c0989a5a
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions -verify %s
4 [[clang::unsafe_buffer_usage]]
5 void deprecatedFunction3();
7 void deprecatedFunction4(int z);
9 void someFunction();
11 [[clang::unsafe_buffer_usage]]
12 void overloading(int* x);
14 void overloading(char c[]);
16 void overloading(int* x, int size);
18 [[clang::unsafe_buffer_usage]]
19 void deprecatedFunction4(int z);
21 void caller(int z, int* x, int size, char c[]) {
22 deprecatedFunction3(); // expected-warning{{function introduces unsafe buffer manipulation}}
23 deprecatedFunction4(z); // expected-warning{{function introduces unsafe buffer manipulation}}
24 someFunction();
26 overloading(x); // expected-warning{{function introduces unsafe buffer manipulation}}
27 overloading(x, size);
28 overloading(c);
31 [[clang::unsafe_buffer_usage]]
32 void overloading(char c[]);
34 // Test variadics
35 [[clang::unsafe_buffer_usage]]
36 void testVariadics(int *ptr, ...);
38 template<typename T, typename... Args>
39 [[clang::unsafe_buffer_usage]]
40 T adder(T first, Args... args);
42 template <typename T>
43 void foo(T t) {}
45 template<>
46 [[clang::unsafe_buffer_usage]]
47 void foo<int *>(int *t) {}
49 void caller1(int *p, int *q) {
50 testVariadics(p, q); // expected-warning{{function introduces unsafe buffer manipulation}}
51 adder(p, q); // expected-warning{{function introduces unsafe buffer manipulation}}
53 int x;
54 foo(x);
55 foo(&x); // expected-warning{{function introduces unsafe buffer manipulation}}
58 // Test virtual functions
59 class BaseClass {
60 public:
61 [[clang::unsafe_buffer_usage]]
62 virtual void func() {}
64 virtual void func1() {}
67 class DerivedClass : public BaseClass {
68 public:
69 void func() {}
71 [[clang::unsafe_buffer_usage]]
72 void func1() {}
75 void testInheritance() {
76 DerivedClass DC;
77 DC.func();
78 DC.func1(); // expected-warning{{function introduces unsafe buffer manipulation}}
80 BaseClass *BC;
81 BC->func(); // expected-warning{{function introduces unsafe buffer manipulation}}
82 BC->func1();
84 BC = &DC;
85 BC->func(); // expected-warning{{function introduces unsafe buffer manipulation}}
86 BC->func1();