Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-unsafe-buffer-usage-multi-decl-uuc-fixits.cpp
blob409a03fc0aad9b70e77e90a6c2f9f2a5c7d67cb0
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions \
3 // RUN: -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
5 void bar(int * param) {}
7 void foo1a() {
8 int *r = new int[7];
9 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
10 int *p = new int[4];
11 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:
12 p = r;
13 int tmp = p[9];
14 int *q;
15 q = r; // FIXME: we do not fix `q = r` here as the `.data()` fix-it is not generally correct
18 void uuc_if_body() {
19 int *r = new int[7];
20 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> r"
21 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
22 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
23 int *p = new int[4];
24 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
25 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
26 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
27 if (true)
28 p = r;
29 p[5] = 4;
32 void uuc_if_body1(bool flag) {
33 int *r = new int[7];
34 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> r"
35 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
36 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
37 int *p = new int[4];
38 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p"
39 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
40 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 4}"
41 if (flag) {
42 p = r;
44 p[5] = 4;
47 void uuc_if_body2_ptr_init(bool flag) {
48 int *r = new int[7];
49 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> r"
50 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
51 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:", 7}"
52 if (flag) {
53 } else {
54 int* p = r;
55 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:13}:"std::span<int> p"
56 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:14-[[@LINE-2]]:14}:"{"
57 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:15}:", <# placeholder #>}"
58 p[5] = 4;
62 void uuc_if_cond_no_unsafe_op() {
63 int *r = new int[7];
64 int *p = new int[4];
65 if ((p = r)) {
66 int x = 0;
70 void uuc_if_cond_unsafe_op() {
71 int *r = new int[7];
72 int *p = new int[4];
73 if ((p = r)) {
74 p[3] = 2;
78 void uuc_if_cond_unsafe_op1() {
79 int *r = new int[7];
80 int *p = new int[4];
81 if ((p = r)) {
82 r[3] = 2;
86 void uuc_if_cond_unsafe_op2() {
87 int *r = new int[7];
88 int *p = new int[4];
89 if ((p = r)) {
90 r[3] = 2;
92 p[4] = 6;
95 void uuc_call1() {
96 int *w = new int[4];
97 int *y = new int[4];
98 bar(w = y);
99 w[5] = 0;