Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

unix.Malloc and cplusplus.NewDeleteLeaks doesn't report leaks in functions declared in header files. #23424

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR23425
Status NEW
Importance P normal
Reported by Anton (anton.yartsev@Gmail.com)
Reported on 2015-05-05 18:09:24 -0700
Last modified on 2019-11-19 10:47:06 -0800
Version trunk
Hardware PC Windows XP
CC anton.yartsev@Gmail.com, ganna@apple.com, llvm-bugs@lists.llvm.org, pavel.kryukov@phystech.edu
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Symptoms: the analyzer doesn't report a leak in a given case:
>cat header.h
void f();

>cat test.cpp
#include "header.h"

void f() {
  int *p = new int;
}

>clang -cc1 -analyzer-checker=cplusplus.NewDeleteLeaks test.cpp

Adding an option '-analyzer-opt-analyze-headers' makes analyzer report a
warning:
>clang -cc1 -analyzer-checker=cplusplus.NewDeleteLeaks -analyzer-opt-analyze-
headers -analyze test.cpp
test.cpp:5:1: warning: Potential leak of memory pointed to by 'p'
}
^
1 warning generated.

Clang help for -analyzer-opt-analyze-headers says that an option 'Force the
static analyzer to analyze functions defined in header files', but in the test
above the function is defined in the cpp file.
The deadcode.DeadStores checker reports an error regardless of whether -
analyzer-opt-analyze-headers was passed or not:
>clang -cc1 -analyzer-checker=deadcode.DeadStores -analyze test.cpp
test.cpp:4:8: warning: Value stored to 'p' during its initialization is never
read
  int *p = new int;
       ^   ~~~~~~~
1 warning generated.
Quuxplusone commented 9 years ago

Filed radar://20827905 for the purpose of internal tracking.

Quuxplusone commented 9 years ago

I think this is fixed.

Quuxplusone commented 4 years ago
I see that warnings are reported for system headers now.
I filed a new bug: https://bugs.llvm.org/show_bug.cgi?id=44065