← 返回 CLI 目录 抓取的
Clang
$ clang 基金会 低风险 LLVM Project · 代码托管与研发协同 · Apache-2.0 WITH LLVM-exception · macos / linux / windows
LLVM 的工业级 C/C++/Objective-C 编译前端,以清晰的报错诊断、AddressSanitizer/UBSan 运行时插桩、静态分析(--analyze)以及编译数据库片段输出(-MJ)著称,是 macOS 默认系统编译器及跨平台 C/C++ 构建核心。
FCRS-1.0 综合评分
83 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
brew install llvm CLI vs MCP 选型建议 仅 CLI 可用
本地编译器与 sanitizer 驱动;Agent 直接调用 clang 或通过 CMake/Ninja 触发。
Agent 友好度体检单
本地探针实测证据 — 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
实测版本
Apple clang version 21.0.0 (clang-2100.4.1.1)
冷启动耗时
85 ms
退出码 (help / 非法参数)
0 / 1
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
OVERVIEW: clang LLVM compiler
USAGE: clang [options] file...
OPTIONS:
-### Print (but do not run) the commands to run for this compilation
--analyzer-output <value>
Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|sarif-html|text).
--analyze Run the static analyzer
-B <prefix> Search $prefix$file for executables, libraries, and data files. If $prefix is a directory, search $prefix/$file
-b <arg> Pass -b <arg> to the linker on AIX
-cc1-args <value> pass cc1 options to depscan afterwards
-CC Include comments from within macros in preprocessed output
-cl-denorms-are-zero OpenCL only. Allow denormals to be flushed to zero.
-cl-ext=<value> OpenCL only. Enable or disable OpenCL extensions/optional features. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.
-cl-fast-relaxed-math OpenCL only. Sets -cl-finite-math-only and -cl-unsafe-math-optimizations, and defines __FAST_RELAXED_MATH__.
-cl-finite-math-only OpenCL only. Allow floating-point optimizations that assume arguments and results are not NaNs or +-Inf.
-cl-fp32-correctly-rounded-divide-sqrt
OpenCL only. Specify that single precision floating-point divide and sqrt used in the program source are correctly rounded.
-cl-kernel-arg-info OpenCL only. Generate kernel argument metadata.
-cl-mad-enable OpenCL only. Allow use of less precise MAD computations in the generated binary.
-cl-no-signed-zeros OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.
-cl-no-stdinc OpenCL only. Disables all standard includes containing non-native compiler types and functions.
-cl-opt-disable OpenCL only. This option disables all optimizations. By default optimizations are enabled.
-cl-single-precision-constant
OpenCL only. Treat double precision floating-point constant as single precision constant.
-cl-std=<value> OpenCL language standard to compile for.
-cl-strict-aliasing OpenCL only. This option is added for compatibility with OpenCL 1.0.
-cl-uniform-work-group-size
OpenCL only. Defines that the global work-size be a multiple of the work-group size specified to clEnqueueNDRangeKernel
-cl-unsafe-math-optimiza FCRS-1.0 六维评分拆解
Agent 友好度 17 / 25
支持 -fno-color-diagnostics、-fsyntax-only、-MJ JSON 编译片段与 -ast-dump=json,但常规报错仍默认以多行文本输出。
- Supports
-fno-color-diagnosticsand-fsyntax-only - Supports
-Xclang -ast-dump=json
安全与权限边界 20 / 25
纯本地运行且无网络或凭证风险,具备安全的 -fsyntax-only 只读校验模式。
- Read-only syntax checking via
-fsyntax-only
安装与运行摩擦 14 / 15
macOS 通过 Xcode CLT 自带,Linux 与 Windows 可通过 Homebrew llvm、发行版包管理器或官方发布包安装。
- Native availability across macOS, Linux, and Windows
能力覆盖与边际价值 14 / 15
编译诊断清晰,内置 ASan/UBSan 与 --analyze 静态分析器,验证能力强。
- Built-in ASan/UBSan and
--analyzestatic checker
维护与来源背书 10 / 10
由 LLVM 基金会及产业界长期联合维护。
- Official
llvm/llvm-projectrepository
文档与可验证性 8 / 10
官方手册与诊断索引完备,但完整 --help 输出较长。
- Official Clang User's Manual at clang.llvm.org
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
无需任何凭证;仅操作本地源代码与系统 SDK 头文件。
潜在副作用
只读查询 本地写入
费用与配额提示
基于 Apache-2.0 WITH LLVM-exception 开源,完全免费。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Clang (clang) Agent Rules - Use `-fsyntax-only -fno-color-diagnostics` for fast, clean verification edits. - Prefer `-fsanitize=address,undefined` on test binaries to catch memory errors deterministically.
Agent 高频安全命令配方
只读查询(安全推荐)
无产物运行语法与类型检查
clang -fsyntax-only -fno-color-diagnostics -Wall main.c
关闭颜色转义并校验 C/C++ 语法和类型,不生成任何目标文件。
以 JSON 导出 AST 语法树用于静态分析
clang -Xclang -ast-dump=json -fsyntax-only main.c
将解析后的 C/C++ 抽象语法树以结构化 JSON 输出到标准输出。
受控写入与预演
启用 AddressSanitizer 与 UBSan 编译调试二进制
clang -g -O1 -fsanitize=address,undefined -fno-color-diagnostics main.c -o build/app-san
将带内存与未定义行为检测插桩的测试可执行文件编译至 build/app-san。
核心优势
- + 诊断提示可读性高,配合
-fno-color-diagnostics与-fsyntax-only便于 Agent 迭代修复 C/C++ 问题。 - + 原生集成
-fsanitize=address,undefined,无需额外工具即可捕获内存与未定义行为。
注意事项与踩坑点
- ! 常规告警与错误默认输出格式化文本而非 JSON(除非显式启用实验性 SARIF 格式)。
- ! macOS 上 Homebrew 安装的
llvm默认为 keg-only,不修改PATH不会替换系统 Apple Clang。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI