skills/clang/SKILL.md
Clang/LLVM compiler skill for C/C++ projects. Use when working with clang or clang++ for diagnostics, sanitizer instrumentation, optimization remarks, static analysis with clang-tidy, LTO via lld, or when migrating from GCC to Clang. Activates on queries about clang flags, clang-tidy, clang-format, better error messages, Apple/FreeBSD toolchains, or LLVM-specific optimizations. Covers flag selection, diagnostic tuning, and integration with LLVM tooling.
npx skillsauth add awfixers-stuff/opencode-config clangInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through Clang-specific features: superior diagnostics, sanitizer integration, optimization remarks, static analysis, and LLVM tooling. Covers divergences from GCC and Apple/FreeBSD specifics.
skills/compilers/msvc-clskills/runtimes/sanitizersClang accepts most GCC flags. Key differences:
| Feature | GCC | Clang |
|---------|-----|-------|
| Min size | -Os | -Os or -Oz (more aggressive) |
| Optimise only hot | — | -fprofile-instr-use (LLVM PGO) |
| Thin LTO | -flto | -flto=thin (faster) |
| Static analyser | -fanalyzer | clang --analyze or clang-tidy |
# Show fix-it hints inline
clang -Wall -Wextra --show-fixits src.c
# Limit error count
clang -ferror-limit=5 src.c
# Verbose template errors (disable elision)
clang -fno-elide-type src.cpp
# Show tree diff for template mismatch
clang -fdiagnostics-show-template-tree src.cpp
Clang's diagnostics include exact range highlighting and fix-it suggestions that GCC lacks.
Optimization remarks let you see what Clang did or refused to do:
# Inliner decisions
clang -O2 -Rpass=inline src.c
# Missed vectorisation
clang -O2 -Rpass-missed=loop-vectorize src.c
# Why a loop was not vectorized
clang -O2 -Rpass-analysis=loop-vectorize src.c
# Save all remarks to YAML for post-processing
clang -O2 -fsave-optimization-record src.c
# Produces src.opt.yaml
Interpret remarks:
remark: foo inlined into bar — inlining happened; good for hot pathsremark: loop not vectorized: loop control flow is not understood — restructure the loopremark: not vectorized: cannot prove it is safe to reorder... — add __restrict__ or #pragma clang loop vectorize(assume_safety)# Built-in analyser (CSA)
clang --analyze -Xanalyzer -analyzer-output=text src.c
# clang-tidy (separate tool, richer checks)
clang-tidy src.c -- -std=c++17 -I/usr/include
# Enable specific check families
clang-tidy -checks='clang-analyzer-*,modernize-*,bugprone-*' src.cpp --
# Apply fixits automatically
clang-tidy -fix src.cpp --
Common clang-tidy check families:
bugprone-*: real bugs (use-after-move, dangling, etc.)clang-analyzer-*: CSA checks (memory, null deref)modernize-*: C++11/14/17 modernisationperformance-*: unnecessary copies, move candidatesreadability-*: naming, complexity# Full LTO
clang -O2 -flto -fuse-ld=lld src.c -o prog
# Thin LTO (faster link, nearly same quality)
clang -O2 -flto=thin -fuse-ld=lld src.c -o prog
# Check lld is available
clang -fuse-ld=lld -Wl,--version 2>&1 | head -1
For large projects, ThinLTO is preferred: link times 5-10x faster than full LTO with comparable code quality.
# Step 1: instrument
clang -O2 -fprofile-instr-generate prog.c -o prog_inst
# Step 2: run with representative input
./prog_inst < workload.input
# Generates default.profraw
# Step 3: merge profiles
llvm-profdata merge -output=prog.profdata default.profraw
# Step 4: use profile
clang -O2 -fprofile-instr-use=prog.profdata prog.c -o prog
AutoFDO (sampling-based, less intrusive): collect with perf, convert with create_llvm_prof, use with -fprofile-sample-use. See skills/profilers/linux-perf.
Clang is intentionally GCC-compatible for driver flags. Key differences:
__has_attribute(foo)-Weverything enables all Clang warnings (no GCC equivalent); too noisy for production, useful for one-off audits#include <x86intrin.h> on Clang too__int128 is supported; __float128 requires -lquadmath on some targetsOn macOS, clang is the system compiler (Apple LLVM). Key points:
ld64 is the default linker; lld requires explicit -fuse-ld=lld and Homebrew LLVM-mmacosx-version-min=X.Y to set deployment targetDYLD_INSERT_LIBRARIES; do not strip the binaryxcrun clang resolves to the Xcode toolchain clangFor flag reference, see references/flags.md. For clang-tidy config examples, see references/clang-tidy.md.
skills/compilers/gcc for GCC-equivalent flag mappingskills/runtimes/sanitizers for -fsanitize=* workflowsskills/compilers/llvm for IR-level work (opt, llc, llvm-dis)skills/compilers/msvc-cl for clang-cl on Windowsskills/binaries/linkers-lto for linker-level LTO detailsdevelopment
Use when starting dev servers, watchers, tilt, or any process expected to outlive the conversation. Provides zmx session management patterns for long-lived processes.
development
Zig testing skill for writing and running tests. Use when using zig build test, writing comptime tests, using test filters, working with test allocators to detect leaks, or using Zig's built-in fuzz testing (0.14+). Activates on queries about Zig tests, zig test, zig build test, comptime testing, test allocators, Zig fuzz testing, or detecting memory leaks in Zig tests.
development
Zig debugging skill. Use when debugging Zig programs with GDB or LLDB, interpreting Zig runtime panics, using std.debug.print for tracing, configuring debug builds, or debugging Zig programs in VS Code. Activates on queries about debugging Zig, Zig panics, zig gdb, zig lldb, std.debug.print, Zig stack traces, or Zig error return traces.
tools
Zig cross-compilation skill. Use when cross-compiling Zig programs to different targets, using Zig's built-in cross-compilation for embedded, WASM, Windows, ARM, or using zig cc to cross-compile C code without a system cross-toolchain. Activates on queries about Zig cross-compilation, zig target triples, zig cc cross-compile, Zig embedded targets, or Zig WASM.