Skip to content

The home of the clang-based implementation of lifetime safety warnings.

Notifications You must be signed in to change notification settings

mgehre/llvm-project

 
 

Repository files navigation

Actions Status

The -Wlifetime warnings implemented in clang

This project contains clang's experimental implementation of the lifetime safety profile of the C++ core guidelines.

You can try this implementation on Compiler Explorer by choosing the clang version experimental -Wlifetime.

Warning flags

  • -Wdangling-gsl: Statement-local analysis (enabled by default)
  • -Wreturn-stack-address: Statement-local analysis (enabled by default)
  • -Wlifetime: Main flow-sensitive analysis
  • -Wlifetime-filter: Reduce the number of false-postives at the cost of additional false negatives.
  • -Wno-lifetime-null: Disable flow-sensitive warnings about nullness of Pointers
  • -Wlifetime-global: Flow-sensitive analysis that requires global variables of Pointer type to always point to variables with static lifetime
  • -Wlifetime-disabled: Get warnings when the flow-sensitive analysis is disabled on a function due to forbidden constructs (reinterpret_cast or pointer arithmetic)

Suppress Warnings

Build

You can either try it on Compiler Explorer, or build clang yourself:

mkdir build
cd build 
cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang
make
# Run the tests (optional)
make check-clang 
# Use clang
./bin/clang++ <some-source> <warning-flags>

Further information

The specification

CppCon 2019 Talk, focusing on statement local analysis

EuroLLVM 2019 Talk, focusing on flow-sensitive analysis

CppCon 2018 Talk, focusing on flow-sensitive analysis

CppCon 2018 Keynote, by Herb Sutter

CppCon 2015 Keynote, by Herb Sutter, first introduction

Development

Tests:

Implementation:

About

The home of the clang-based implementation of lifetime safety warnings.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 46.1%
  • LLVM 28.6%
  • C 10.8%
  • Assembly 10.6%
  • Python 1.4%
  • Objective-C 0.7%
  • Other 1.8%