Skip to content

higuoxing/clang-plugins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clang Plugins Collection

Collection of clang plugins that I wrote.

Plugins

  1. ListFreeChecker (Path sensitive checker):

    ListFreeChecker is used to check if we're freeing a List * object with pfree() in projects based on Postgres. Since in Postgres 13+, List is implemented in array, it makes non-sense to free a list header.

  2. ReturnInPgTryBlockChecker (Path insensitive checker based on AST-matcher):

    ReturnInPgTryBlockChecker is used to check if there are unsafe return/continue/break/goto statements in PG_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();

Build

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 git@github.com:higuoxing/clang-plugins.git
cd clang-plugins
mkdir build
cd build
cmake -DCT_CLANG_INSTALL_DIR=/<path>/<to>/<clang-install-dir>
make -j`nproc`

Usage

  1. 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`

Found issues:

License

These plugins are licensed under the MIT License. See the LICENSE file for details.

About

Collection of clang plugins that I wrote.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published