Implausibly high values for maximum statement nesting and cyclomatic complexity
dspinellis opened this issue · comments
Diomidis Spinellis commented
- Maximum nesting comes out at 57 when processing the kernel of FreeBSD 1.0.
- Maximum cyclomatic complexity comes out 810 when processing used commands of FreeBSD 2.0.
Diomidis Spinellis commented
Find the kernel culprit.
$ git ls-tree --name-only -r FreeBSD-release/1.0 | grep '^sys\/.*\.c$' | while read f ; do git show FreeBSD-release/1.0:$f | qmcalc | tr -d \\n; echo " $f"; done | awk '$14 > 7 {print $112, $14}'
sys/i386/isa/sound/gus_wave.c 8
sys/i386/isa/sound/gustest/gmod.c 12
sys/i386/isa/sound/gustest/gusload.c 8
sys/i386/isa/sound/gustest/midithru.c 11
sys/i386/isa/sound/gustest/pmtest.c 10
sys/i386/isa/sound/sequencer.c 10
sys/i386/isa/sound/soundcard.c 8
sys/netiso/tp_driver.c 57
sys/netiso/tp_input.c 8
sys/scsi/cd.c 16
Diomidis Spinellis commented
Isolate by running
git show FreeBSD-release/1.0:sys/netiso/tp_driver.c | qmcalc | awk '{print $14}'
57
Diomidis Spinellis commented
After de78033
$ git show FreeBSD-release/1.0:sys/netiso/tp_driver.c | ~/src/cqmetrics/src/qmcalc | awk '{print $14}'
7
Diomidis Spinellis commented
Reproduce the cyclomatic complexity problem.
$ git ls-tree --name-only -r FreeBSD-release/2.0 | grep -v -e '^sys\/.*\.c$' -e '^\.ref' | grep '\.c$' | sed 's|^|FreeBSD-release/2.0:|' | xargs git show | qmcalc | awk '{print $53}'
810
Diomidis Spinellis commented
Problem persists after de78033.
Diomidis Spinellis commented
Look at the cyclomatic complexity of individual files.
$ git ls-tree --name-only -r FreeBSD-release/2.0 | grep -v -e '^sys\/.*\.c$' -e '^\.ref' | grep '\.c$' | sed 's|^|FreeBSD-release/2.0:|' | while read f ; do git show $f | qmcalc | tr -d \\n; echo " $f"; done | awk '$53 > 100 {print $112, $53}' | sort -k2n
FreeBSD-release/2.0:games/adventure/main.c 344
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/combine.c 349
FreeBSD-release/2.0:gnu/usr.bin/perl/x2p/walk.c 358
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/cse.c 361
FreeBSD-release/2.0:gnu/usr.bin/cc/cc1/c-lex.c 379
FreeBSD-release/2.0:gnu/usr.bin/cc/cc1plus/lex.c 396
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/reload.c 454
FreeBSD-release/2.0:gnu/usr.bin/as/config/tc-m68k.c 504
FreeBSD-release/2.0:gnu/usr.bin/cc/cc1plus/decl.c 564
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/jump.c 569
FreeBSD-release/2.0:gnu/usr.bin/perl/perl/toke.c 577
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/fold-const.c 624
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/expr.c 632
FreeBSD-release/2.0:gnu/usr.bin/cc/cc_int/insn-recog.c 680
FreeBSD-release/2.0:gnu/usr.bin/perl/perl/eval.c 810
Diomidis Spinellis commented
The files with high cyclomatic complexity functions contain indeed large complex functions. See
- https://github.com/dspinellis/unix-history-repo/blob/FreeBSD-release/2.0/gnu/usr.bin/perl/perl/eval.c
- https://github.com/dspinellis/unix-history-repo/blob/FreeBSD-release/2.0/gnu/usr.bin/cc/cc_int/expr.c
- https://github.com/dspinellis/unix-history-repo/blob/FreeBSD-release/2.0/gnu/usr.bin/cc/cc_int/fold-const.c