34 lines · cpp
1// RUN: %clang_analyze_cc1 \2// RUN: -analyzer-checker=core,cplusplus.NewDeleteLeaks \3// RUN: -verify %s4 5// expected-no-diagnostics: Whenever we cannot evaluate an operation we escape6// the operands. After the evaluation it would be an7// 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 34