
Detect Heap Bugs with AddressSanitizer
Compile with -fsanitize=address to catch heap overflows, use after free, double free and leaks, and learn to read the report that names the exact line.
Tag
15 posts

Compile with -fsanitize=address to catch heap overflows, use after free, double free and leaks, and learn to read the report that names the exact line.

Run individual LLVM passes such as mem2reg and instcombine on IR with opt, build a pipeline, list the passes and print what each pass changed.

Configure clang-format with a .clang-format file, format files and diffs, and fail CI on unformatted code so style discussions end before review.

Write LLVM IR from C with clang -S -emit-llvm, then read types, basic blocks, loads, stores, phi nodes and calls well enough to check what the compiler did.

Set up clangd for go-to-definition, completion and live diagnostics in VS Code, Neovim or any editor, using a compile_commands.json from your build.

Install Clang on Linux, macOS or Windows, point Make, CMake or Meson at it, and fix the handful of warnings and flags that differ from GCC.

Follow one C function through Clang, LLVM IR, the optimizer and the code generator, and see what each stage produces and which tool lets you run it alone.

Add stack protector, fortify, PIE, full RELRO and CET flags to a CMake 3.28 project with feature checks, per-target options and a verification step.

A curated set of GCC and Clang warnings, from -Wformat=2 and -Wstringop-overflow to -Wvla and -Wconversion, that flag memory-safety bugs before they ship.

Turn on _FORTIFY_SOURCE=3 with -O2 on glibc 2.33 or later and see which libc calls get bounds checks, how level 3 differs from 2 and what it cannot catch.

Rewrite float reductions, indirect gathers and early-exit loops in C so GCC and Clang vectorize them, using partial sums and blocked scans.

Turn on auto-vectorization in GCC and Clang, read the optimization reports that say why a loop was skipped, and set the flags that matter, including -march.