[llvm-bugs] [Bug 34198] New: Potential leaks reported on `new`ed pointer escaped via reinterpret_cast + bit ops
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Tue Aug 15 16:42:29 PDT 2017
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=34198
            Bug ID: 34198
           Summary: Potential leaks reported on `new`ed pointer escaped
                    via reinterpret_cast + bit ops
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: george.burgess.iv at gmail.com
                CC: llvm-bugs at lists.llvm.org
Test case:
using uintptr_t = unsigned long long;
uintptr_t bar;
void alloc() {
  bar = reinterpret_cast<uintptr_t>(new int) | 0;
}
$ clang --analyze /tmp/tc.cpp -fno-exceptions
/tmp/tc.cpp:4:7: warning: Potential memory leak
  bar = reinterpret_cast<uintptr_t>(new int) | 0;
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$
However, if the test-case is changed to:
using uintptr_t = unsigned long long;
uintptr_t bar;
void alloc() {
  bar = reinterpret_cast<uintptr_t>(new int);
  bar |= 0;
}
This "potential leak" warning doesn't appear, regardless of the value that
`bar` is `or`ed with.
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170815/632ee1e9/attachment-0001.html>
    
    
More information about the llvm-bugs
mailing list