blob: be5dfbcd9ef588366983124a16ade0625fd2bc41 [file] [log] [blame]
Csaba Dabis49885b12019-06-25 00:44:33 +00001// 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
9typedef unsigned __INTPTR_TYPE__ uintptr_t;
10
11class C {};
12
13C *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
22C **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