
Clang
- 405 installs
- 155 repo stars
- Updated June 27, 2026
- mohitmishra786/low-level-dev-skills
clang is a Claude Code low-level development skill that configures clang and clang++ compiler flags, sanitizers, cross-compilation targets, and static analysis for C/C++ components linked into Rust or native tooling pipe
About
clang is a skill from mohitmishra786/low-level-dev-skills for developers working at the C/C++ and Rust boundary. It guides clang and clang++ flag selection, AddressSanitizer and UndefinedBehaviorSanitizer setup, cross-compilation triples, and clang-static-analyzer workflows when building native libraries consumed by Rust crates or standalone CLI tools. Developers reach for clang when CI builds fail on warning policies, sanitizer crashes need triage, or embedded targets require non-default toolchains. The skill focuses on compiler invocation and analysis configuration rather than rewriting application logic, making it a reference for build scripts, CMake presets, and cargo build integration with native dependencies.
- Warning and optimization flags
- Sanitizer instrumentation
- Cross-compilation triples
- Static analysis hooks
- Rust FFI compile steps
Clang by the numbers
- 405 all-time installs (skills.sh)
- +29 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #137 of 550 CLI & Terminal skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill clangAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 405 |
|---|---|
| repo stars | ★ 155 |
| Last updated | June 27, 2026 |
| Repository | mohitmishra786/low-level-dev-skills ↗ |
How do you configure clang sanitizers for C++ builds?
Configure clang/clang++ flags, sanitizers, cross-compilation, and static analysis for C/C++ components linked into Rust or native tooling pipelines.
Who is it for?
Developers linking C/C++ into Rust crates or native CLI tools who need correct sanitizer, cross-compile, and static-analysis compiler flags.
Skip if: Developers working only in high-level languages without native C/C++ compilation or clang-based toolchain requirements.
When should I use this skill?
A user asks to set clang flags, enable ASan or UBSan, cross-compile C/C++, or run clang static analysis on native code.
What you get
clang/clang++ compile commands with sanitizer flags, cross-compilation settings, and static-analysis invocation ready for CI or local builds.
- Compiler flag configurations
- Sanitizer-enabled build commands
Files
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.cppClang'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.yamlInterpret 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
# 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
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 -1For 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 progAutoFDO (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. For clang-tidy config examples, see references/clang-tidy.md.
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
clang-tidy Reference
Source: <https://clang.llvm.org/extra/clang-tidy/>
Configuration (.clang-tidy)
---
Checks: >
clang-analyzer-*,
bugprone-*,
modernize-*,
performance-*,
readability-identifier-naming,
-modernize-use-trailing-return-type,
-readability-magic-numbers
WarningsAsErrors: 'bugprone-*'
HeaderFilterRegex: '.*'
FormatStyle: file
CheckOptions:
- key: readability-identifier-naming.VariableCase
value: camelCaseCommon invocations
# Single file
clang-tidy src.cpp -- -std=c++17 -I./include
# All files using compile_commands.json
clang-tidy $(find src -name '*.cpp') -p build/
# Apply fixits (creates in-place changes)
clang-tidy -fix src.cpp -- -std=c++17
# Parallel (requires run-clang-tidy script)
run-clang-tidy -j4 -p build/ 2>&1 | tee tidy.log
# Generate compile_commands.json with CMake
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B build
ln -sf build/compile_commands.json .Key check families
| Family | Description |
|---|---|
bugprone-* | Use-after-move, dangling reference, suspicious constructs |
clang-analyzer-* | CSA: memory leaks, null deref, API misuse |
modernize-* | C++11/14/17/20 upgrade patterns |
performance-* | Unnecessary copies, pass-by-value candidates |
readability-* | Naming, complexity, clarity |
cppcoreguidelines-* | C++ Core Guidelines |
cert-* | CERT coding standard checks |
hicpp-* | HIC++ standard checks |
portability-* | Cross-platform issues |
Suppressing checks
// NOLINT: suppress all checks on this line
int x = getValue(); // NOLINT
// NOLINT(check-name): suppress specific check
int y = getValue(); // NOLINT(bugprone-narrowing-conversions)
// NOLINTNEXTLINE: suppress on next line
// NOLINTNEXTLINE(modernize-use-auto)
MyType* ptr = new MyType();In .clang-tidy, prefix a check with - to disable:
Checks: 'modernize-*,-modernize-use-trailing-return-type'Clang Flag Reference
Source: <https://clang.llvm.org/docs/UsersManual.html> Source: <https://clang.llvm.org/docs/ClangCommandLineReference.html>
Table of Contents
1. Optimisation 2. Diagnostics 3. Sanitizers 4. LTO / PGO 5. Code generation 6. Target-specific
---
Optimisation
| Flag | Effect |
|---|---|
-O0/1/2/3/Os/Oz/Og | Same semantics as GCC |
-Ofast | -O3 + -ffast-math |
-flto | Full LTO |
-flto=thin | ThinLTO (faster link) |
-fwhole-program-vtables | Devirtualise across modules (requires LTO) |
-fvirtual-function-elimination | Remove unreachable virtual functions (LTO) |
-fstrict-aliasing | Default at -O2+ |
-fno-strict-aliasing | Disable strict aliasing |
-ffast-math | Unsafe FP optimisations (implies -fno-honor-nans etc.) |
-ffp-model=fast/strict/precise | Clang-specific FP model control |
---
Diagnostics
| Flag | Effect |
|---|---|
-Wall -Wextra | Standard warning set |
-Weverything | All warnings (audit use only) |
-Wpedantic | Strict standards conformance warnings |
-Werror | Warnings as errors |
-Werror=foo | Specific warning as error |
-ferror-limit=N | Stop after N errors (default 20) |
-ftemplate-backtrace-limit=N | Template instantiation depth limit |
-fno-elide-type | Print full template types |
-fdiagnostics-show-template-tree | Tree diff for template mismatches |
-fdiagnostics-color=auto/always/never | Colour control |
-fdiagnostics-format=clang/msvc/vi | Output format |
--show-fixits | Show suggested fixes inline |
-Rpass=<regex> | Optimisation remarks (pass did transform) |
-Rpass-missed=<regex> | Remarks for missed transforms |
-Rpass-analysis=<regex> | Analysis remarks |
-fsave-optimization-record | Save remarks to .opt.yaml |
---
Sanitizers
| Flag | Sanitizer |
|---|---|
-fsanitize=address | AddressSanitizer (heap/stack/global OOB, UAF) |
-fsanitize=undefined | UndefinedBehaviorSanitizer |
-fsanitize=thread | ThreadSanitizer |
-fsanitize=memory | MemorySanitizer (uninit reads; requires all-clang build) |
-fsanitize=leak | LeakSanitizer (standalone) |
-fsanitize-recover=all | Continue after sanitizer error |
-fsanitize-blacklist=file | Suppress specific functions/files |
-fno-omit-frame-pointer | Needed for good ASan stack traces |
See skills/runtimes/sanitizers for full decision tree and report interpretation.
---
LTO / PGO
| Flag | Phase | Effect |
|---|---|---|
-flto | compile+link | Full LTO via LLVM bitcode |
-flto=thin | compile+link | ThinLTO |
-fuse-ld=lld | link | Use lld linker |
-fprofile-instr-generate | compile | LLVM PGO instrumentation |
-fprofile-instr-use=file | compile | Apply PGO profile |
-fprofile-generate | compile | GCC-compatible profiling |
-fprofile-use=file | compile | GCC-compatible profile use |
-fprofile-sample-use=file | compile | AutoFDO (sampling-based) |
-fcs-profile-generate | compile | Context-sensitive PGO |
---
Code generation
| Flag | Effect |
|---|---|
-fPIC | Position-independent code |
-fPIE | Position-independent executable |
-fvisibility=hidden | Default to hidden symbol visibility |
-fstack-protector-strong | Stack canary |
-fcf-protection=full | Intel CET (x86) |
-fsanitize-cfi-* | Control Flow Integrity (LTO required) |
-mllvm -inline-threshold=N | Tune inliner threshold directly |
---
Target-specific
x86-64
-march=x86-64-v2 # SSE4.2, POPCNT (Nehalem+)
-march=x86-64-v3 # AVX2 (Haswell+)
-march=x86-64-v4 # AVX-512
-march=native # Detect host CPUAArch64 / ARM
-target aarch64-linux-gnu
-mcpu=cortex-a72
-mfloat-abi=hardWebAssembly
--target=wasm32-unknown-unknown
-nostdlibRelated skills
FAQ
What does the clang skill configure?
The clang skill configures clang and clang++ compiler flags, sanitizers like ASan and UBSan, cross-compilation targets, and static analysis for C/C++ components. Developers use it when native code links into Rust crates or standalone tooling pipelines.
When should developers use clang over generic C++ help?
Developers should use the clang skill when builds need specific clang sanitizer flags, cross-compilation triples, or clang-static-analyzer integration—not for general application logic written only in Rust or Python without native compilation.