diff options
author | Kristof Umann <dkszelethus@gmail.com> | 2019-02-05 00:39:33 +0000 |
---|---|---|
committer | Kristof Umann <dkszelethus@gmail.com> | 2019-02-05 00:39:33 +0000 |
commit | 1a17032b788016299ea4e3c4b53670c6dcd94b4f (patch) | |
tree | 318aac876ac4171cb6613f534126f39430fc193e /clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp | |
parent | 7f09fd6b045da9fd62529fede180ac3e48a88305 (diff) | |
download | bcm5719-llvm-1a17032b788016299ea4e3c4b53670c6dcd94b4f.tar.gz bcm5719-llvm-1a17032b788016299ea4e3c4b53670c6dcd94b4f.zip |
[analyzer] Creating standard Sphinx documentation
The lack of documentation has been a long standing issue in the Static Analyzer,
and one of the leading reasons behind this was a lack of good documentation
infrastucture.
This lead serious drawbacks, such as
* Not having proper release notes for years
* Not being able to have a sensible auto-generated checker documentations (which
lead to most of them not having any)
* The HTML website that has to updated manually is a chore, and has been
outdated for a long while
* Many design discussions are now hidden in phabricator revisions
This patch implements a new documentation infrastucture using Sphinx, like most
of the other subprojects in LLVM. It transformed some pages as a proof-of-
concept, with many others to follow in later patches. The eventual goal is to
preserve the original website's (https://clang-analyzer.llvm.org/) frontpage,
but move everything else to the new format.
Some other ideas, like creating a unipage for each checker (similar to how
clang-tidy works now), are also being discussed.
Patch by Dániel Krupp!
Differential Revision: https://reviews.llvm.org/D54429
llvm-svn: 353126
Diffstat (limited to 'clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp')
-rw-r--r-- | clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp b/clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp new file mode 100644 index 00000000000..2a4103240fe --- /dev/null +++ b/clang/docs/analyzer/checkers/mismatched_deallocator_example.cpp @@ -0,0 +1,56 @@ +// C, C++ +void test() { + int *p = (int *)malloc(sizeof(int)); + delete p; // warn +} + +// C, C++ +void __attribute((ownership_returns(malloc))) *user_malloc(size_t); + +void test() { + int *p = (int *)user_malloc(sizeof(int)); + delete p; // warn +} + +// C, C++ +void test() { + int *p = new int; + free(p); // warn +} + +// C, C++ +void test() { + int *p = new int[1]; + realloc(p, sizeof(long)); // warn +} + +// C, C++ +template <typename T> +struct SimpleSmartPointer { + T *ptr; + + explicit SimpleSmartPointer(T *p = 0) : ptr(p) {} + ~SimpleSmartPointer() { + delete ptr; // warn + } +}; + +void test() { + SimpleSmartPointer<int> a((int *)malloc(4)); +} + +// C++ +void test() { + int *p = (int *)operator new(0); + delete[] p; // warn +} + +// Objective-C, C++ +void test(NSUInteger dataLength) { + int *p = new int; + NSData *d = [NSData dataWithBytesNoCopy:p + length:sizeof(int) freeWhenDone:1]; + // warn +dataWithBytesNoCopy:length:freeWhenDone: cannot take + // ownership of memory allocated by 'new' +} + |