http://llvm.org/bugs/show_bug.cgi?id=16499

            Bug ID: 16499
           Summary: False positive warning: Use of memory after it is
                    freed (use of pointer, not memory)
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Clang static analyzer give false warning that memory used after it is freed.
Warning is bogus because only pointer value is used, but not memory it points
to.

Example:
>cat test.cpp 
#include <iostream> // std::cout
#include <stdlib.h> // malloc

void f() {
  char *buffer = (char *)malloc(10);
  free(buffer);
  std::cout << (void *)buffer << std::endl;
      // OK, memory freed, but only pointer value needed
}

>clang++ --analyze test.cpp 
test.cpp:7:3: warning: Use of memory after it is freed
  std::cout << (void *)buffer << std::endl;
  ^            ~~~~~~~~~~~~~~
1 warning generated.

This is simplified version of warning that can be found in libc++ sources 
libcxx/src/debug.cpp, '__libcpp_db::__erase_i' method.

Environment:
>clang++ --version
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

>uname -a
Darwin mac-osx-x64 11.4.2 Darwin Kernel Version 11.4.2 ...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to