/clang
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,
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill clang --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/clang
Context preview
The summary Claude sees to decide when to auto-load this skill.
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,
SKILL.md
clang.SKILL.mdname: clang
description: 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.
Clang
Purpose
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.
Triggers
- "I want better compiler diagnostics/errors"
- "How do I use clang-tidy / clang-format?"
- "How do I see what the compiler optimised or didn't?"
- "I'm on macOS / FreeBSD using clang"
- "clang-cl for MSVC-compatible builds" — see `skills/compilers/msvc-cl`
- Sanitizer queries — see `skills/runtimes/sanitizers`
Workflow
1. Build mode flags (identical to GCC)
Clang 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` |
2. Clang-specific diagnostic flags
# 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.
3. Optimization remarks
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 paths
- `remark: loop not vectorized: loop control flow is not understood` — restructure the loop
- `remark: not vectorized: cannot prove it is safe to reorder...` — add `__restrict__` or `#pragma clang loop vectorize(assume_safety)`
4. Static analysis
# 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 modernisation
- `performance-*`: unnecessary copies, move candidates
- `readability-*`: naming, complexity
5. LTO with lld
# 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.
6. PGO (LLVM instrumentation)
# 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`.
7. GCC compatibility
Clang is intentionally GCC-compatible for driver flags. Key differences:
- Clang does not support all GCC-specific attributes; check with `__has_attribute(foo)`
- `-Weverything` enables all Clang warnings (no GCC equivalent); too noisy for production, useful for one-off audits
- Some GCC intrinsics need `#include <x86intrin.h>` on Clang too
- `__int128` is supported; `__float128` requires `-lquadmath` on some targets
8. macOS specifics
On macOS, `clang` is the system compiler (Apple LLVM). Key points:
- `ld64` is the default linker; `lld` requires explicit `-fuse-ld=lld` and Homebrew LLVM
- Use `-mmacosx-version-min=X.Y` to set deployment target
- Sanitizers on macOS use `DYLD_INSERT_LIBRARIES`; do not strip the binary
- `xcrun clang` resolves to the Xcode toolchain clang
For flag reference, see [references/flags.md](references/flags.md). For clang-tidy config examples, see [references/clang-tidy.md](references/clang-tidy.md).
Related skills
- Use `skills/compilers/gcc` for GCC-equivalent flag mapping
- Use `skills/runtimes/sanitizers` for `-fsanitize=*` workflows
- Use `skills/compilers/llvm` for IR-level work (`opt`, `llc`, `llvm-dis`)
- Use `skills/compilers/msvc-cl` for `clang-cl` on Windows
- Use `skills/binaries/linkers-lto` for linker-level LTO details
Read more
name: clang description: 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.
Clang
Purpose
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.
Triggers
- "I want better compiler diagnostics/errors"
- "How do I use clang-tidy / clang-format?"
- "How do I see what the compiler optimised or didn't?"
- "I'm on macOS / FreeBSD using clang"
- "clang-cl for MSVC-compatible builds" — see `skills/compilers/msvc-cl`
- Sanitizer queries — see `skills/runtimes/sanitizers`
Workflow
1. Build mode flags (identical to GCC)
Clang 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` |
2. Clang-specific diagnostic flags
# 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.
3. Optimization remarks
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 paths
- `remark: loop not vectorized: loop control flow is not understood` — restructure the loop
- `remark: not vectorized: cannot prove it is safe to reorder...` — add `__restrict__` or `#pragma clang loop vectorize(assume_safety)`
4. Static analysis
# 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 modernisation
- `performance-*`: unnecessary copies, move candidates
- `readability-*`: naming, complexity
5. LTO with lld
# 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.
6. PGO (LLVM instrumentation)
# 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`.
7. GCC compatibility
Clang is intentionally GCC-compatible for driver flags. Key differences:
- Clang does not support all GCC-specific attributes; check with `__has_attribute(foo)`
- `-Weverything` enables all Clang warnings (no GCC equivalent); too noisy for production, useful for one-off audits
- Some GCC intrinsics need `#include <x86intrin.h>` on Clang too
- `__int128` is supported; `__float128` requires `-lquadmath` on some targets
8. macOS specifics
On macOS, `clang` is the system compiler (Apple LLVM). Key points:
- `ld64` is the default linker; `lld` requires explicit `-fuse-ld=lld` and Homebrew LLVM
- Use `-mmacosx-version-min=X.Y` to set deployment target
- Sanitizers on macOS use `DYLD_INSERT_LIBRARIES`; do not strip the binary
- `xcrun clang` resolves to the Xcode toolchain clang
For flag reference, see [references/flags.md](references/flags.md). For clang-tidy config examples, see [references/clang-tidy.md](references/clang-tidy.md).
Related skills
- Use `skills/compilers/gcc` for GCC-equivalent flag mapping
- Use `skills/runtimes/sanitizers` for `-fsanitize=*` workflows
- Use `skills/compilers/llvm` for IR-level work (`opt`, `llc`, `llvm-dis`)
- Use `skills/compilers/msvc-cl` for `clang-cl` on Windows
- Use `skills/binaries/linkers-lto` for linker-level LTO details
A curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /custom-allocators
Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

