重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
clang by mohitmishra786/low-level-dev-skills
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill clang指导代理了解 Clang 的特定功能:卓越的诊断信息、消毒器集成、优化备注、静态分析以及 LLVM 工具链。涵盖与 GCC 的差异以及 Apple/FreeBSD 系统的具体细节。
skills/compilers/msvc-clskills/runtimes/sanitizersClang 接受大多数 GCC 标志。主要区别:
| 功能 | GCC | Clang |
|---|---|---|
| 最小化大小 | -Os | -Os 或 (更激进) |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
-Oz| 仅优化热点代码 | — | -fprofile-instr-use(LLVM PGO) |
| Thin LTO | -flto | -flto=thin(更快) |
| 静态分析器 | -fanalyzer | clang --analyze 或 clang-tidy |
# 内联显示修复建议
clang -Wall -Wextra --show-fixits src.c
# 限制错误数量
clang -ferror-limit=5 src.c
# 详细的模板错误(禁用省略)
clang -fno-elide-type src.cpp
# 为模板不匹配显示树形差异
clang -fdiagnostics-show-template-tree src.cpp
Clang 的诊断信息包含精确的范围高亮和 GCC 所缺乏的修复建议。
优化备注让你了解 Clang 做了或拒绝做什么:
# 内联决策
clang -O2 -Rpass=inline src.c
# 错失的向量化
clang -O2 -Rpass-missed=loop-vectorize src.c
# 循环未被向量化的原因
clang -O2 -Rpass-analysis=loop-vectorize src.c
# 将所有备注保存到 YAML 以便后处理
clang -O2 -fsave-optimization-record src.c
# 生成 src.opt.yaml
解读备注:
remark: foo inlined into bar — 发生了内联;对热点路径有益remark: loop not vectorized: loop control flow is not understood — 重构循环remark: not vectorized: cannot prove it is safe to reorder... — 添加 __restrict__ 或 #pragma clang loop vectorize(assume_safety)# 内置分析器(CSA)
clang --analyze -Xanalyzer -analyzer-output=text src.c
# clang-tidy(独立工具,检查项更丰富)
clang-tidy src.c -- -std=c++17 -I/usr/include
# 启用特定的检查类别
clang-tidy -checks='clang-analyzer-*,modernize-*,bugprone-*' src.cpp --
# 自动应用修复建议
clang-tidy -fix src.cpp --
常见的 clang-tidy 检查类别:
bugprone-*:真正的错误(移动后使用、悬垂引用等)clang-analyzer-*:CSA 检查(内存、空指针解引用)modernize-*:C++11/14/17 现代化performance-*:不必要的拷贝、可移动的候选对象readability-*:命名、复杂度# 完整 LTO
clang -O2 -flto -fuse-ld=lld src.c -o prog
# Thin LTO(链接更快,质量几乎相同)
clang -O2 -flto=thin -fuse-ld=lld src.c -o prog
# 检查 lld 是否可用
clang -fuse-ld=lld -Wl,--version 2>&1 | head -1
对于大型项目,推荐使用 ThinLTO:链接时间比完整 LTO 快 5-10 倍,且代码质量相当。
# 步骤 1:插桩
clang -O2 -fprofile-instr-generate prog.c -o prog_inst
# 步骤 2:使用代表性输入运行
./prog_inst < workload.input
# 生成 default.profraw
# 步骤 3:合并性能分析文件
llvm-profdata merge -output=prog.profdata default.profraw
# 步骤 4:使用性能分析文件
clang -O2 -fprofile-instr-use=prog.profdata prog.c -o prog
AutoFDO(基于采样,侵入性更小):使用 perf 收集,使用 create_llvm_prof 转换,使用 -fprofile-sample-use 应用。参见 skills/profilers/linux-perf。
Clang 在驱动程序标志方面有意保持与 GCC 兼容。主要区别:
__has_attribute(foo) 检查-Weverything 启用所有 Clang 警告(GCC 无等效项);对于生产环境过于嘈杂,适用于一次性审计#include <x86intrin.h>__int128;__float128 在某些目标平台上需要 -lquadmath在 macOS 上,clang 是系统编译器(Apple LLVM)。要点:
ld64 是默认链接器;lld 需要显式指定 -fuse-ld=lld 和 Homebrew LLVM-mmacosx-version-min=X.Y 设置部署目标DYLD_INSERT_LIBRARIES;不要剥离二进制文件xcrun clang 解析为 Xcode 工具链的 clang关于标志的参考,请参阅 references/flags.md。关于 clang-tidy 配置示例,请参阅 references/clang-tidy.md。
skills/compilers/gcc 获取 GCC 等效标志映射skills/runtimes/sanitizers 获取 -fsanitize=* 工作流程skills/compilers/llvm 进行 IR 级别的工作(opt、llc、llvm-dis)skills/compilers/msvc-cl 获取 Windows 上的 clang-clskills/binaries/linkers-lto 获取链接器级别的 LTO 详细信息每周安装次数
52
代码仓库
GitHub 星标数
34
首次出现
2026年2月20日
安全审计
安装于
cursor51
gemini-cli51
codex51
kimi-cli51
amp51
github-copilot51
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 detailsWeekly Installs
52
Repository
GitHub Stars
34
First Seen
Feb 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
cursor51
gemini-cli51
codex51
kimi-cli51
amp51
github-copilot51
Flutter/Dart代码审查最佳实践:提升应用性能与质量的完整检查清单
1,200 周安装
session-logs 技能:搜索和管理 OpenClaw 会话日志的完整指南
954 周安装
Apple Notes CLI 终端命令行工具 - 在 macOS 终端管理 Apple 笔记
966 周安装
团队测试技能:多智能体测试流水线编排,实现渐进式层级覆盖与覆盖率收敛
45 周安装
GitHub Copilot for Azure 技能创作指南:规范、令牌预算与渐进式披露
948 周安装
GitHub代码安全审计工具 - 自动化查找缺陷、安全漏洞与代码质量问题
1,000 周安装
Python Excel自动化:openpyxl库操作XLSX文件教程,创建编辑格式化电子表格
961 周安装