On Thu, Jan 28, 2021 at 11:24:30AM +0100, Tim Wiederhake wrote: > clang-tidy is a static code analysis tool under the llvm umbrella. It is > primarily meant to be used on C++ code bases, but some of the checks it > provides also apply to C. > > The findings vary in severity and contain pseudo-false-positives, i.e. > clang-tidy is flagging potential execution flows that could happen in > theory but are virtually impossible in real life: In function > `virGetUnprivSGIOSysfsPath`, variables `maj` and `min` would be read > unintialized if `stat()` failed and set `errno` to a negative value, to name > just one example. > > The main source of false positive findings is the lack of support for > `__attribute__((cleanup))` in clang-tidy, which is heavily used in libvirt > through glib's `g_autofree` and `g_auto()` macros: > > #include <stdlib.h> > > void freeptr(int** p) { > if (*p) > free(*p); > } > > int main() { > __attribute__((cleanup(freeptr))) int *ptr = NULL; > ptr = calloc(sizeof(int), 1); > return 0; /* flagged as memory leak of `ptr` */ > } > > This sadly renders clang-tidy's analysis of dynamic memory useless, hiding all > real issues that it could otherwise find. > > Meson provides excellent integration for clang-tidy (a "clang-tidy" target is > automatically generated if a ".clang-tidy" configuration file is present > in the project's root directory). The amount of false-positives and the slow > analysis, triggering time-outs in the CI, make this tool unfit for inclusion > in libvirt's GitLab CI though. Is it possible to make it viable for CI by disabling *all* checks by default and then selectively re-enabling just the handful that are useful and don't have false positives ? Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|