Code Monkey home page Code Monkey logo

clang-plugins's Introduction

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 [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`

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.

clang-plugins's People

Contributors

higuoxing avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.