| 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 |
| 4 |
|
| 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 |
| 12 |
|
| 13 |
// This debugging facility is only available in debug builds. |
| 14 |
// |
| 15 |
// REQUIRES: asserts |
| 16 |
|
| 17 |
void test_unclaimed_use(int *p) { // expected-warning{{'p' is an unsafe pointer used for buffer access}} |
| 18 |
p++; // expected-note{{used in pointer arithmetic here}} \ |
| 19 |
expected-note{{safe buffers debug: failed to produce fixit for 'p' : has an unclaimed use\n \ |
| 20 |
The unclaimed DRE trace: DeclRefExpr, UnaryOperator(++), CompoundStmt}} |
| 21 |
*((p + 1) + 1); // expected-warning{{unsafe pointer arithmetic}} \ |
| 22 |
expected-note{{used in pointer arithmetic here}} \ |
| 23 |
expected-note{{safe buffers debug: failed to produce fixit for 'p' : has an unclaimed use\n \ |
| 24 |
The unclaimed DRE trace: DeclRefExpr, ImplicitCastExpr(LValueToRValue), BinaryOperator(+), ParenExpr, BinaryOperator(+), ParenExpr, UnaryOperator(*), CompoundStmt}} |
| 25 |
p -= 1; // expected-note{{used in pointer arithmetic here}} \ |
| 26 |
expected-note{{safe buffers debug: failed to produce fixit for 'p' : has an unclaimed use\n \ |
| 27 |
The unclaimed DRE trace: DeclRefExpr, BinaryOperator(-=), CompoundStmt}} |
| 28 |
p--; // expected-note{{used in pointer arithmetic here}} \ |
| 29 |
expected-note{{safe buffers debug: failed to produce fixit for 'p' : has an unclaimed use\n \ |
| 30 |
The unclaimed DRE trace: DeclRefExpr, UnaryOperator(--), CompoundStmt}} |
| 31 |
p[5] = 5; // expected-note{{used in buffer access here}} |
| 32 |
} |
| 33 |
|
| 34 |
// CHECK: Root # 1 |
| 35 |
// CHECK: |- DeclRefExpr # 4 |
| 36 |
// CHECK: |-- UnaryOperator(++) # 1 |
| 37 |
// CHECK: |--- CompoundStmt # 1 |
| 38 |
// CHECK: |-- ImplicitCastExpr(LValueToRValue) # 1 |
| 39 |
// CHECK: |--- BinaryOperator(+) # 1 |
| 40 |
// CHECK: |---- ParenExpr # 1 |
| 41 |
// CHECK: |----- BinaryOperator(+) # 1 |
| 42 |
// CHECK: |------ ParenExpr # 1 |
| 43 |
// CHECK: |------- UnaryOperator(*) # 1 |
| 44 |
// CHECK: |-------- CompoundStmt # 1 |
| 45 |
// CHECK: |-- BinaryOperator(-=) # 1 |
| 46 |
// CHECK: |--- CompoundStmt # 1 |
| 47 |
// CHECK: |-- UnaryOperator(--) # 1 |
| 48 |
// CHECK: |--- CompoundStmt # 1 |