Repository navigation
0.1.0
The first release of cchecker: it checks C code for the rules of a project and runs the usual analyzers in one command. It runs gcc -fanalyzer, clang-tidy and its own rules on the files of a compile database in parallel, and prints their findings in one format with stable codes, as lines or --json. A baseline file accepts today's findings, so CI fails only on new ones; suppressions with a reason go next to the code.
The rules read clang's JSON AST and the annotations of include/cchecker.h:
- Effects on the call graph: a
CC_SHORTfunction never reaches a blocking call; aCC_HOTfunction never allocates or makes a system call. Roots can also come from settings or from libuv loop callbacks. - Locks on every path: locks released and held as they should be, no system call under a
CC_NO_SYSCALL_UNDERlock,CC_LOCK_LEVELorder, andCC_PAIRset/restore pairs. - Ownership on every path:
CC_OWNSpointers freed or handed on, never freed twice or used after free; collector values (CC_GC) never stored inmallocmemory or statics.
Install and run (needs Agentica 0.26.1+, gcc 10+, clang and clang-tidy):
git clone --branch 0.1.0 https://github.com/agentica-lang/cchecker ~/cchecker
agentica ~/cchecker/cchecker.agc -p build # in your project, with build/compile_commands.jsonSee the README.
Changelog
The first release.
Added
cchecker: runsgcc -fanalyzer,clang-tidyand its ownruleson the C files of a compile database (or of the
command line) in parallel, and prints their findings in one format with stable codes (CC-GCC-,CC-TIDY-,
CC-EFFECT-,CC-PATH-,CC-OWN-), as lines or--json. The default tools aregcc,clang-tidy,rules, so
clangis needed too;--tools gcc,clang-tidyruns without it, and--clang PROGRAMnames the clang that dumps
the AST.- Exit codes: 0 no new findings, 1 new findings, 2 usage or tool error. A non-zero exit of a tool is a tool error, a
file that does not compile is never a finding, only the analyzer warnings of gcc are findings (a gcc killed after
analyzer errors or halfway is a tool error, with itsfatal errorline), and a timeout stops the tool's children
too (withtimeoutinstalled). - A file whose
#includeis not found is not checked, withcchecker: warning: FILE not checked: HEADER not found
and an entry inunchecked_filesof--json; the other files are checked and the exit code does not change. - A baseline file (
--baseline,--update-baseline) that accepts findings by code, file and message, not by line.
An update keeps the entries of the tools and files the run did not cover, and a header that a partial run did not
name keeps the larger count of its entry. It is refused when a file of the database was skipped, while--checks,
--no-inferor a[library]flag set to false turns a check off, and with a-c FILEthat leaves out ashortor
hotname of[roots]of the project settings. include/cchecker.h: the annotation macros (CC_SHORT,CC_BLOCKING,CC_HOT,CC_OWNS,CC_PAIR,
CC_NO_SYSCALL_UNDER, ...), anannotateattribute for clang and empty for other compilers. UnderCCHECKER_AST
they aredeprecatedattributes, whose text clang 19 keeps in its JSON AST.- The
rulestool: one call graph of the project from clang's JSON AST, function pointers included where the project
stores a function in a field, a variable or a parameter.CC-EFFECT-SHORT-BLOCKS: aCC_SHORTfunction reaches a
blocking call (aCC_BLOCKINGfunction, or a known blocking call of libc, pthread or libuv; auv_fs_*call with
no callback blocks only when its libc call does, else it is a system call).CC-EFFECT-HOT-ALLOCATESand
CC-EFFECT-HOT-SYSCALL: aCC_HOTfunction allocates or makes a system call. The printed line and thepathfield
of--jsongive the call path; the baseline matches the message without it.--all-pathsgives a finding for each
distinct bad call, each with its shortest path. - The effect walk does not go into an error exit: a function that is
_Noreturn,[[noreturn]],CC_NORETURN,
__attribute__((noreturn))(also through a typedef, or with a calling convention after it) or
__attribute__((cold)), or a library call that never returns (_exit,abort, ...).[effects] follow_cold = truefollows it; aCC_BLOCKINGmark on such a function still counts. openandopenatwithO_NONBLOCK, andrecv,send,recvfromandsendtowithMSG_DONTWAIT, are not
blocking forCC_SHORTwhen the flag is a constant, with the values of the target (Linux and macOS);
[library] libc_nonblocking_flagsturns it off.- Settings, read from the first of
-c FILE(its[tool.cchecker]table when it has one),cchecker.toml, the
[tool.cchecker]table ofagentica.toml, and the defaults;configin--jsonsays which.[library]turns the
families of library knowledge off one by one, andsourcein--jsonnames the one of a finding.[roots]names
CC_SHORTandCC_HOTroots without a mark. - Inferred roots: a function passed as a callback to a libuv call that runs it on the loop thread (timers, handles,
streams, UDP, DNS,uv_fs_*requests and more; the lists match libuv 1.50) is aCC_SHORTroot
(libuv_callbacks_short,--no-infer). Its finding gives the call inroot; a callback that leads to no function
is listed inunresolved_callbacksof--json. - Assumptions of a project:
CC_ASSUME_SHORTand[assume] shortname a function that counts as fine for
CC_SHORT;CC_STOPand[assume] stopone that no rule walks into;[assume] stop_fieldsthe function-pointer
fields whose calls no rule follows; short locks (CC_NO_SYSCALL_UNDER()or[assume] short_locks) are not
blocking forCC_SHORT. A name that no function of the compile database declares is an error. - Locks on every path: a control flow graph of each function that takes or releases a lock.
CC-PATH-LOCK-NOT-RELEASED: a path returns with a lock the function took;CC-PATH-LOCK-NOT-HELD: a path releases
a lock it did not take.CC_ACQUIRES(lock)andCC_RELEASES(lock)mark the helpers that take or drop a lock for
their caller. A function with more paths than the rules follow is listed inincomplete_functionsof--json
(file,line,function) and on standard error; one too large for a graph is an error of therulestool. - What runs under a lock:
CC_NO_SYSCALL_UNDER()on the field of a lock (orCC_NO_SYSCALL_UNDER(lock)on a
function) andCC-PATH-SYSCALL-UNDER-LOCKfor a system or blocking call made or reached under it, aCC_RELEASES
helper included;CC_LOCK_LEVEL(n)andCC-PATH-LOCK-ORDERfor a lock taken while one of the same or a higher
level is held. A lock mark that cannot be read is one error of therulestool, on the file of the mark. - Pairs of calls:
CC_PAIR(set, restore)on a function (or onsetitself, for all its callers).
CC-PATH-PAIR-NOT-RESTORED: a path returns aftersetwithoutrestore;CC-PATH-PAIR-NOT-SET: arestorewith
nosetbefore it. - Ownership on every path:
CC_OWNSon a local, a parameter, a function (it returns an owned pointer) or a field,
andCC_FREESon a parameter.CC-OWN-LEAK,CC-OWN-DOUBLE-FREEandCC-OWN-USE-AFTER-FREE. - Values of the collector:
CC_GCon a type andCC_GC_ALLOCon an allocator (the Boehm allocators are known,
[library] libgc_alloc).CC-OWN-GC-IN-MALLOCandCC-OWN-GC-IN-STATIC: such a value stored in memory from
mallocor in a static. - Suppressions with a reason: a comment
cchecker: ignore CODE: reasonafter the code of a finding's line or alone on
the line above (//,///,//!,/* */), andCC_IGNORE("CODE", "reason")on a function for the codes of the
rules.--jsonlists them undersuppressed; a code that matches no finding isCC-UNUSED-IGNORE; neither goes
into the baseline. - Speed: a native module in C scans clang's AST, which clang writes into a FIFO. The 84 files of the VM of Agentica
take 17.9 s and 411 MB at-j 2, and a chain of 3000 else-if 4 s and 170 MB.-jdefaults to the number of cores,
and the jobs of the largest files start first.