1 // RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
2 // RUN: -mllvm -debug-only=SafeBuffers \
3 // RUN: -std=c++20 -verify=expected %s
5 // RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions \
6 // RUN: -mllvm -debug-only=SafeBuffers \
7 // RUN: -std=c++20 %s \
8 // RUN: 2>&1 | grep 'The unclaimed DRE trace:' \
9 // RUN: | sed 's/^The unclaimed DRE trace://' \
10 // RUN: | %analyze_safe_buffer_debug_notes \
11 // RUN: | FileCheck %s
13 // This debugging facility is only available in debug builds.
18 void test_unclaimed_use(int *p
) { // expected-warning{{'p' is an unsafe pointer used for buffer access}}
19 p
++; // expected-note{{used in pointer arithmetic here}} \
20 expected
-note
{{safe buffers debug
: failed to produce fixit
for 'p' : has an unclaimed use
\n \
21 The unclaimed DRE trace
: DeclRefExpr
, UnaryOperator(++), CompoundStmt
}}
22 *((p
+ 1) + 1); // expected-warning{{unsafe pointer arithmetic}} \
23 expected
-note
{{used in pointer arithmetic here
}} \
24 expected
-note
{{safe buffers debug
: failed to produce fixit
for 'p' : has an unclaimed use
\n \
25 The unclaimed DRE trace
: DeclRefExpr
, ImplicitCastExpr(LValueToRValue
), BinaryOperator(+), ParenExpr
, BinaryOperator(+), ParenExpr
, UnaryOperator(*), CompoundStmt
}}
26 p
-= 1; // expected-note{{used in pointer arithmetic here}} \
27 expected
-note
{{safe buffers debug
: failed to produce fixit
for 'p' : has an unclaimed use
\n \
28 The unclaimed DRE trace
: DeclRefExpr
, BinaryOperator(-=), CompoundStmt
}}
29 p
--; // expected-note{{used in pointer arithmetic here}} \
30 expected
-note
{{safe buffers debug
: failed to produce fixit
for 'p' : has an unclaimed use
\n \
31 The unclaimed DRE trace
: DeclRefExpr
, UnaryOperator(--), CompoundStmt
}}
32 p
[5] = 5; // expected-note{{used in buffer access here}}
36 // CHECK: |- DeclRefExpr # 4
37 // CHECK: |-- UnaryOperator(++) # 1
38 // CHECK: |--- CompoundStmt # 1
39 // CHECK: |-- ImplicitCastExpr(LValueToRValue) # 1
40 // CHECK: |--- BinaryOperator(+) # 1
41 // CHECK: |---- ParenExpr # 1
42 // CHECK: |----- BinaryOperator(+) # 1
43 // CHECK: |------ ParenExpr # 1
44 // CHECK: |------- UnaryOperator(*) # 1
45 // CHECK: |-------- CompoundStmt # 1
46 // CHECK: |-- BinaryOperator(-=) # 1
47 // CHECK: |--- CompoundStmt # 1
48 // CHECK: |-- UnaryOperator(--) # 1
49 // CHECK: |--- CompoundStmt # 1