https://bugs.llvm.org/show_bug.cgi?id=34365

            Bug ID: 34365
           Summary: Static analyzer is very conservative with atomic ops
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: kreme...@apple.com
          Reporter: george.burgess...@gmail.com
                CC: llvm-bugs@lists.llvm.org

$ cat tc.cpp
void bar() {
  int i = 2;
  char *c = new char;
  if (__sync_fetch_and_sub(&i, 1) == 1) delete c;
  if (__sync_fetch_and_sub(&i, 1) == 1) delete c;
}

$ clang++ --analyze tc.cpp -std=c++11
tc.cpp:5:41: warning: Attempt to free released memory
  if (__sync_fetch_and_sub(&i, 1) == 1) delete c;
                                        ^~~~~~~~
tc.cpp:6:1: warning: Potential leak of memory pointed to by 'c'
}
^

I'm unsure if it's possible to do much better than this in general, since
atomic ops are inherently annoying to reason about. That said, this issue makes
the analyzer pretty noisy when it's analyzing home-grown shared_ptr
implementations.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to