Loading...
Loading...
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 skill4agent add mohitmishra786/low-level-dev-skills clangskills/compilers/msvc-clskills/runtimes/sanitizers| Feature | GCC | Clang |
|---|---|---|
| Min size | | |
| Optimise only hot | — | |
| Thin LTO | | |
| Static analyser | | |
# 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# 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.yamlremark: foo inlined into barremark: loop not vectorized: loop control flow is not understoodremark: not vectorized: cannot prove it is safe to reorder...__restrict__#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 --clang-tidybugprone-*clang-analyzer-*modernize-*performance-*readability-*# 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# 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 progperfcreate_llvm_prof-fprofile-sample-useskills/profilers/linux-perf__has_attribute(foo)-Weverything#include <x86intrin.h>__int128__float128-lquadmathclangld64lld-fuse-ld=lld-mmacosx-version-min=X.YDYLD_INSERT_LIBRARIESxcrun clangskills/compilers/gccskills/runtimes/sanitizers-fsanitize=*skills/compilers/llvmoptllcllvm-disskills/compilers/msvc-clclang-clskills/binaries/linkers-lto