Skip to content

A tiny Clang LibTooling utility that parses C++ source files into an AST, finds every function/method/constructor call, and reports whether the callee is noexcept.

License

Notifications You must be signed in to change notification settings

JayTwoLab/std_call_scan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

std_call_scan

English Korean

A tiny Clang LibTooling utility that parses C++ source files into an AST, finds every function/method/constructor call, and reports whether the callee is noexcept.
The tool prints a CSV to stdout, which you can redirect to a file.

Columns: file,line,col,kind,qualified-name,noexcept,signature,callee-source


Features

  • Walks calls to free functions, member methods, constructors, and overloaded operators
  • Evaluates noexcept via FunctionProtoType::isNothrow()
  • Optional filters:
    • --only-std — keep only calls whose qualified name starts with std::
    • --name-prefix <prefix> — keep only calls with a given qualified-name prefix (e.g., std::filesystem::)
    • --csv-header — print a header row
  • (By default) system headers are excluded; you can tweak the matcher in the source if you need them

Requirements

  • CMake ≥ 3.20
  • A working LLVM/Clang development environment (headers + libs)
    • Rocky/Red Hat example:
      sudo dnf install clang clang-devel llvm llvm-devel libedit-devel libffi-devel libxml2-devel zlib-devel libzstd-devel
    • Ubuntu example:
      sudo apt install clang libclang-dev llvm-dev libedit-dev libffi-dev libxml2-dev zlib1g-dev libzstd-dev

Build

Linux

# from the project root
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

This will produce an executable (e.g., build/std_call_scan).

Windows

  • (1) Download LLVM and Clang from the following site:

  • (2) Extract them to the same path.

    • Assume extraction to C:\llvm-package.
  • (3) Set environment variables as follows:

    • PATH : C:\llvm-package\bin
    • LLVM_DIR : C:\llvm-package\lib\cmake\llvm
    • Clang_DIR : C:\llvm-package\lib\cmake\clang
  • (4) Run cmake in the Visual Studio command prompt (make sure ninja is pre-installed):

      mkdir build && cd build
    
      cmake -G Ninja ^
        -DCMAKE_BUILD_TYPE=Release ^
        -DCMAKE_C_COMPILER=clang-cl ^
        -DCMAKE_CXX_COMPILER=clang-cl ^
        -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL ^
        -DLLVM_DIR="C:/llvm-package/lib/cmake/llvm" ^
        -DClang_DIR="C:/llvm-package/lib/cmake/clang" ^
        ..
    • One-line command:

      cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL -DLLVM_DIR="C:/llvm-package/lib/cmake/llvm" -DClang_DIR="C:/llvm-package/lib/cmake/clang" ..
  • (5) Execute build:

    ninja -v

Usage

Linux

# Edit variable in build_scan_env.sh, before execute script
./sh/build_scan_env.sh

CSV Schema

  • file: source file path containing the call site
  • line, col: 1‑based position of the call site
  • kind: call (free function), method (member), construct (constructor), opcall (operator call), etc.
  • qualified-name: fully qualified callee name (e.g., std::filesystem::create_directory)
  • noexcept: 1 if the callee is nothrow (per Clang's type system), 0 otherwise
  • signature: a pretty function signature
  • callee-source: a short source snippet of the call expression

⚠️ Notes & Limitations

  • Results can vary by standard library implementation (libstdc++/libc++/MSVC STL) and template instantiation.
  • System headers are excluded by default; edit the matcher in scanner.cpp if you want to include them.
  • The noexcept result reflects the callee type as seen by Clang; it does not run your code.

Examples

# Current project file as a smoke test
./build/std_call_scan --csv-header scanner.cpp

License

See LICENSE.


About

A tiny Clang LibTooling utility that parses C++ source files into an AST, finds every function/method/constructor call, and reports whether the callee is noexcept.

Resources

License

Stars

Watchers

Forks

Packages

No packages published