Try Documentalist,
my app that offers fast, offline access to 190+ programmer API docs.
cmd-line options
-std=
: c++98
, c++11
, c++14
, c++1z
-stdlib=
: libc++
(preferable on Mac OS X), libstdc++
(preferable on Linux). https://stackoverflow.com/questions/14972425/should-i-use-libc-or-libstdc
sanitizers
address sanitizer (memory corruptions), 2x slowdown
Compile with:
-O1 -g -fsanitize=address -fno-omit-frame-pointer
Add
-fno-optimize-sibling-calls
for better callstacks
Link with:
-g -fsanitize=address
testing sanitizer is enabled
It's good to verify that sanitizer is enabled and working. Add this snippet of code and call it from your code. It should trigger sanitizer
void trigger_address_sanitizer() {
char *a = (char*)malloc(4);
char c = a[5]; /* this line should trigger sanitizer */
printf("c: %d\n", (int)c);
free((void*)a);
}
memory sanitizer (uninitialized reads), 3x slowdown
Compile with
-fsanitize=memory -fno-omit-frame-pointer -g -O2
Link with
-fsanitize=memory -g
on mac
brew install llvm
installs latest version (currently 5.0).
To not conflict with XCode, binaries are in
/usr/local/Cellar/llvm/5.0.0/bin/
` e..g. /usr/local/Cellar/llvm/5.0.0/bin/clang
Links
- https://arvid.io/2017/08/04/using-clang-on-windows/
- https://metricpanda.com/rival-fortress-update-27-compiling-with-clang-on-windows
- https://stackoverflow.com/questions/46553436/building-with-cmake-ninja-and-clang-on-windows
- https://www.youtube.com/watch?v=TLh—v8OxHE : gcc & clang & VSCode
- http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/
- https://bitsmaker.gitlab.io/post/clang-tidy-from-vs2015/
- https://www.reddit.com/r/cpp/comments/67av0m/is_there_a_better_way_to_marry_cmake_clang_and_vs/
- https://stackoverflow.com/questions/38171878/how-do-i-tell-cmake-to-use-clang-on-windows
misc
http://stackoverflow.com/questions/28203937/installing-llvm-libraries-along-with-xcode
http://llvm.org/releases/3.8.0/tools/clang/docs/
https://github.com/tpoechtrager/wclang - allows cross-compiling Windows code on Linux using clang wrapper
http://eli.thegreenplace.net/2014/05/01/modern-source-to-source-transformation-with-clang-and-libtooling/
http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/
http://www.seethroughskin.com/blog/clang-ast-parsing-for-automated-code-generation/
http://www.seethroughskin.com/blog/simplified-clang-python-bindings/
http://seanhn.wordpress.com/2012/07/10/better-interpreter-fuzzing-with-clang/
http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-clang-refactoring-tools
https://github.com/jeaye/color_coded
https://github.com/Neopallium/lua-clang-cindex - luajit bindings
https://github.com/llvm-mirror/clang/tree/master/bindings/python
https://github.com/indygreg/clanalyze/
https://github.com/sbinet/go-clang
https://github.com/mjsabby/ClangSharp, http://www.clangsharp.org/
https://github.com/SimonRichards/clang-sharp, https://github.com/SimonRichards/ClassMirror
http://blog.quarkslab.com/clang-hardening-cheat-sheet.html
ASAN:
https://gist.github.com/kwk/4171e37f4bcdf7705329
http://btorpey.github.io/blog/2014/03/27/using-clangs-address-sanitizer/
https://alastairs-place.net/blog/2016/05/20/code-coverage-from-the-command-line-with-clang/
On mac:
brew install llvm --with-clang --with-clang-extra-tool --with-compiler-rt --with-libcxx --with-lld --with-lld --with-python --with-rtti --with-utils --HEAD
/usr/local/opt/llvm/bin/clang
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/opt/llvm/lib/python2.7/site-packages' > ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
LD_LIBRARY_PATH=/usr/local/opt/llvm/lib ~/src/pyclang/cindex-dump.py draw_flood.c
In each *.py tool:
from clang.cindex import Config
Config.set_library_path(LLVM_LIB_DIR)
-std=c++11
-std=gnu++11
-Weverything
-Wall
-stdlib=libc++ : use clang's C++ library (as opposed to OS's libstdc++)