Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Last active March 30, 2017 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sw17ch/845f4d2822f570c12dc2af4f5713c477 to your computer and use it in GitHub Desktop.
Save sw17ch/845f4d2822f570c12dc2af4f5713c477 to your computer and use it in GitHub Desktop.
some weird stuff in scan-build/ccc-analyzer
#include <stdint.h>
#define STACKY_LEN (1024 * STACKY_MULT)
int main(int argc, char * argv[]) {
(void)argc;
(void)argv;
#ifndef GOTTA_GO_FAST
uint8_t const stacky[STACKY_LEN] = {
[0] = 'A',
[STACKY_LEN - 1] = 'Z',
};
#else
uint8_t stacky[STACKY_LEN] = {
[0] = 'A',
};
stacky[STACKY_LEN - 1] = 'Z';
#endif
(void)stacky;
return 0;
}

Found a weird case with clang 8.1.0's ccc-analyzer tool that causes it to slow down immensely when using designated array initialization syntax.

ccc-analyzer

$ ./deps/scanbuild/checker-279/libexec/ccc-analyzer --version
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

run data

The C file uses two defines to control behavior:

  • STACKY_MULT is a multipler used to build a stack-allocated array
  • GOTTA_GO_FAST is used to control whether to use the problematic initialization syntax

As an example, this compiles quickly:

$ time ./deps/scanbuild/checker-279/libexec/ccc-analyzer --std=c11 -DSTACKY_MULT=8 -DGOTTA_GO_FAST ccc_analyzer_hates_me.c -o ccc_analyzer_hates_me.o

real    0m0.142s
user    0m0.075s
sys     0m0.034s

Whereas this does not:

$ time ./deps/scanbuild/checker-279/libexec/ccc-analyzer --std=c11 -DSTACKY_MULT=8 ccc_analyzer_hates_me.c -o ccc_analyzer_hates_me.o

real    0m4.835s
user    0m4.746s
sys     0m0.047s

Furthermore, doubling the STACKY_MULT define seems to have a greater-than-linear relationship with time.

-DSTACKY_MULT=2
real    0m0.380s
user    0m0.312s
sys     0m0.035s

-DSTACKY_MULT=4
real    0m1.216s
user    0m1.145s
sys     0m0.038s

-DSTACKY_MULT=8
real    0m4.679s
user    0m4.601s
sys     0m0.042s

-DSTACKY_MULT=16
real    0m18.767s
user    0m18.663s
sys     0m0.065s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment