Collection of clang plugins that I wrote.
-
ListFreeChecker (Path sensitive checker):
ListFreeChecker
is used to check if we're freeing aList *
object withpfree()
in projects based on Postgres. Since in Postgres 13+,List
is implemented in array, it makes non-sense to free a list header. -
ReturnInPgTryBlockChecker (Path insensitive checker based on AST-matcher):
ReturnInPgTryBlockChecker
is used to check if there are unsafereturn
/continue
/break
/goto
statements inPG_TRY()
block in projects based on Postgres. It will break PostgreSQL's error stacks. E.g.,label1: PG_TRY(); { label2: return; // Unsafe. break; // Unsafe. continue; // Unsafe. goto label1; // Unsafe, because it's jumping out of PG_TRY block. for (;;) { break; continue; // Safe. Will not warn about it. } goto label2; // Safe. Will not warn about it. } PG_CATCH(); ... PG_END_TRY();
To use these plugins, you'll need to have LLVM 15 installed on your system. You can download LLVM from the official website or install it through your package manager.
Once you have LLVM installed, you can build the plugins by running the following commands:
git clone [email protected]:higuoxing/clang-plugins.git
cd clang-plugins
mkdir build
cd build
cmake -DCT_CLANG_INSTALL_DIR=/<path>/<to>/<clang-install-dir>
make -j`nproc`
-
Integrate with
scan-build
scan-build \ -load-plugin <path>/<to>/clang-plugins/build/lib/libReturnInPgTryBlockChecker.so -enable-checker alpha.postgres.ReturnInPgTryBlockChecker \ -load-plugin <path>/<to>/clang-plugins/build/lib/libListFreeChecker.so -enable-checker alpha.postgres.ListFreeChecker \ -o <path>/<to>/<scan-build-reports> \ make -j`nproc`
-
ListFreeChecker:
-
ReturnInPgTryBlock:
These plugins are licensed under the MIT License. See the LICENSE file for details.