Clang
$ clang Foundation Low RiskLLVM's production C/C++/Objective-C compiler frontend featuring clear diagnostics, AddressSanitizer/UBSan instrumentation, static analysis (--analyze), and compilation-database fragment emission (-MJ). Widely used as the default system compiler on macOS and across cross-platform C/C++ builds.
brew install llvm Local compiler and sanitizer driver; agents run clang directly or through CMake/Ninja.
Agent-Readiness Checklist
Local Probe EvidenceCaptured --help excerpt
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 6-Dimension Breakdown
Supports -fno-color-diagnostics, -fsyntax-only, -MJ JSON compilation fragments, and -ast-dump=json, though standard compiler errors default to multi-line text.
- Supports
-fno-color-diagnosticsand-fsyntax-only - Supports
-Xclang -ast-dump=json
Purely local execution with zero network/credential exposure and safe -fsyntax-only mode.
- Read-only syntax checking via
-fsyntax-only
Preinstalled via Xcode CLT on macOS and widely packaged via Homebrew llvm, distro packages, and Windows installers.
- Native availability across macOS, Linux, and Windows
Fast frontend diagnostics, built-in sanitizers, and static analyzer make it a premier C/C++ verification tool.
- Built-in ASan/UBSan and
--analyzestatic checker
Backed by the LLVM Foundation and major industry contributors under Apache-2.0.
- Official
llvm/llvm-projectrepository
Extensive user manual and diagnostic reference, though raw --help output is long.
- Official Clang User's Manual at clang.llvm.org
Security, Auth & Guardrails
No credentials required; operates strictly on local source files and SDK headers.
Apache-2.0 WITH LLVM-exception open-source compiler; completely free.
# 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-Ready Command Recipes
Safe Read-Only Queries
clang -fsyntax-only -fno-color-diagnostics -Wall main.c
Checks C/C++ syntax and types cleanly with color disabled and zero output artifacts.
clang -Xclang -ast-dump=json -fsyntax-only main.c
Emits the parsed C/C++ Abstract Syntax Tree as structured JSON to stdout.
Controlled Writes & Previews
clang -g -O1 -fsanitize=address,undefined -fno-color-diagnostics main.c -o build/app-san
Builds a sanitizer-instrumented binary into build/app-san for runtime memory bug detection.
Strengths for Agents
- + Readable diagnostics,
-fno-color-diagnostics, and-fsyntax-onlymake iterative C/C++ fixes reliable. - + Integrated
-fsanitize=address,undefinedcatches memory and UB issues without external tools.
Caveats & Pitfalls
- ! Standard compiler warnings/errors default to formatted text rather than JSON unless SARIF flags are explicitly configured.
- ! Homebrew
llvmon macOS is keg-only and does not override system Apple Clang without updatingPATH.