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:
2. Clang-specific diagnostic flags
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:
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)
4. Static analysis
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
5. LTO with lld
For large projects, ThinLTO is preferred: link times 5-10x faster than full LTO with comparable code quality.
6. PGO (LLVM instrumentation)
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) -Weverythingenables 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 __int128is supported;__float128requires-lquadmathon some targets
8. macOS specifics
On macOS, clang is the system compiler (Apple LLVM). Key points:
ld64is the default linker;lldrequires explicit-fuse-ld=lldand Homebrew LLVM- Use
-mmacosx-version-min=X.Yto set deployment target - Sanitizers on macOS use
DYLD_INSERT_LIBRARIES; do not strip the binary xcrun clangresolves to the Xcode toolchain clang
For flag reference, see references/flags.md [blocked]. For clang-tidy config examples, see references/clang-tidy.md [blocked].
Related skills
- Use
skills/compilers/gccfor GCC-equivalent flag mapping - Use
skills/runtimes/sanitizersfor-fsanitize=*workflows - Use
skills/compilers/llvmfor IR-level work (opt,llc,llvm-dis) - Use
skills/compilers/msvc-clforclang-clon Windows - Use
skills/binaries/linkers-ltofor linker-level LTO details


