| 1 |
// RUN: %clang_analyze_cc1 \ |
| 2 |
// RUN: -analyzer-checker=core,cplusplus.NewDeleteLeaks \ |
| 3 |
// RUN: -verify %s |
| 4 |
|
| 5 |
// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape |
| 6 |
// the operands. After the evaluation it would be an |
| 7 |
// Unknown value and the tracking would be lost. |
| 8 |
|
| 9 |
typedef unsigned __INTPTR_TYPE__ uintptr_t; |
| 10 |
|
| 11 |
class C {}; |
| 12 |
|
| 13 |
C *simple_escape_in_bitwise_op(C *Foo) { |
| 14 |
C *Bar = new C(); |
| 15 |
Bar = reinterpret_cast<C *>(reinterpret_cast<uintptr_t>(Bar) & 0x1); |
| 16 |
(void)Bar; |
| 17 |
// no-warning: "Potential leak of memory pointed to by 'Bar'" was here. |
| 18 |
|
| 19 |
return Bar; |
| 20 |
} |
| 21 |
|
| 22 |
C **indirect_escape_in_bitwise_op() { |
| 23 |
C *Qux = new C(); |
| 24 |
C **Baz = &Qux; |
| 25 |
Baz = reinterpret_cast<C **>(reinterpret_cast<uintptr_t>(Baz) | 0x1); |
| 26 |
Baz = reinterpret_cast<C **>(reinterpret_cast<uintptr_t>(Baz) & |
| 27 |
~static_cast<uintptr_t>(0x1)); |
| 28 |
// no-warning: "Potential leak of memory pointed to by 'Qux'" was here. |
| 29 |
|
| 30 |
delete *Baz; |
| 31 |
return Baz; |
| 32 |
} |
| 33 |
|