Lecture 14
LLVM and Clang
Lecture
Notes: PDF
Outline
- LLVM Project: history and architecture
- LLVM IR
- Clang: parser and static analysis tool
- Clang Static Analyzer and its symbolic execution engine
- Clang Extra Tools: Clang-Tidy
Workshop
Outline
- Compiling/Installing LLVM
- Compiling C/C++ programs to executables and LLVM IR
- Exploring C/C++ programs with Clang (tokens, AST, call graph, CFG, exploded graph)
- Running Clang Static Analyzer
- Exploring Clang Static Analyzer and Clang-Tidy checks
Examples
Tasks
Exploring test.c
:
- Dump tokens:
clang -cc1 -dump-tokens test.c
- Dump and view AST:
clang -cc1 -ast-dump test.c clang -cc1 -ast-view test.c
- Dump and view call graph:
clang -cc1 -analyze -analyzer-checker="debug.DumpCallGraph" test.c clang -cc1 -analyze -analyzer-checker="debug.ViewCallGraph" test.c
- View CFG and Exploded Graph:
clang -cc1 -analyze -analyzer-checker="debug.ViewCFG" test.c clang -cc1 -analyze -analyzer-checker="debug.ViewExplodedGraph" test.c
References
- LLVM (Wikipedia)
- Clang (Wikipedia)
- LLVM Web Site
- LLVM Project (GitHub)
- Clang Static Analyzer - A Checker Developer’s Guide
- [LLVM] Chapters 2, 3, 4, 5, 9, 10
- LLVM Language Reference Manual