15bd5fd48SEdmund Grimley Evans
25bd5fd48SEdmund Grimley EvansIn general, use the same coding style as the surrounding code.
35bd5fd48SEdmund Grimley Evans
45bd5fd48SEdmund Grimley EvansHowever, do not make any unnecessary changes as that complicates
55bd5fd48SEdmund Grimley Evansthe VCS (git) history and makes it harder to merge patches. So
65bd5fd48SEdmund Grimley Evansdo not modify code just to make it conform to a coding style.
75bd5fd48SEdmund Grimley Evans
889ad24e7Sgus knight    Indentation
10e8ad336aSseykoTurn on a "fill tabs with spaces" option in your editor.
125bd5fd48SEdmund Grimley EvansRemove tabs and trailing spaces from any lines that are modified.
135bd5fd48SEdmund Grimley Evans
145bd5fd48SEdmund Grimley EvansNote that some files are indented with 2 spaces (when they
15e8ad336aSseykohave large indentation) while most are indented with 4 spaces.
165bd5fd48SEdmund Grimley Evans
175bd5fd48SEdmund Grimley Evans    Language
185bd5fd48SEdmund Grimley Evans
195bd5fd48SEdmund Grimley EvansTCC is mostly implemented in C90. Do not use any non-C90 features
205bd5fd48SEdmund Grimley Evansthat are not already in use.
215bd5fd48SEdmund Grimley Evans
225bd5fd48SEdmund Grimley EvansNon-C90 features currently in use, as revealed by
235bd5fd48SEdmund Grimley Evans./configure --extra-cflags="-std=c90 -Wpedantic":
245bd5fd48SEdmund Grimley Evans
255bd5fd48SEdmund Grimley Evans- long long (including "LL" constants)
265bd5fd48SEdmund Grimley Evans- inline
275bd5fd48SEdmund Grimley Evans- very long string constants
285bd5fd48SEdmund Grimley Evans- assignment between function pointer and 'void *'
295bd5fd48SEdmund Grimley Evans- "//" comments
305bd5fd48SEdmund Grimley Evans- empty macro arguments (DEF_ASMTEST in i386-tok.h)
315bd5fd48SEdmund Grimley Evans- unnamed struct and union fields (in struct Sym), a C11 feature
325bd5fd48SEdmund Grimley Evans
335bd5fd48SEdmund Grimley Evans    Testing
345bd5fd48SEdmund Grimley Evans
355bd5fd48SEdmund Grimley EvansA simple "make test" is sufficient for some simple changes. However,
365bd5fd48SEdmund Grimley Evansbefore committing a change consider performing some of the following
375bd5fd48SEdmund Grimley Evansadditional tests:
385bd5fd48SEdmund Grimley Evans
395bd5fd48SEdmund Grimley Evans- Build and run "make test" on several architectures.
405bd5fd48SEdmund Grimley Evans
415bd5fd48SEdmund Grimley Evans- Build with ./configure --enable-cross.
425bd5fd48SEdmund Grimley Evans
435bd5fd48SEdmund Grimley Evans- If the generation of relocations has been changed, try compiling
445bd5fd48SEdmund Grimley Evans  with TCC and linking with GCC/Clang. If the linker has been
455bd5fd48SEdmund Grimley Evans  modified, try compiling with GCC/Clang and linking with TCC.
465bd5fd48SEdmund Grimley Evans
475bd5fd48SEdmund Grimley Evans- Test with ASan/UBSan to detect memory corruption and undefined behaviour:
485bd5fd48SEdmund Grimley Evans
495bd5fd48SEdmund Grimley Evansmake clean
505bd5fd48SEdmund Grimley Evans./configure
515bd5fd48SEdmund Grimley Evansmake
525bd5fd48SEdmund Grimley Evansmake test
535bd5fd48SEdmund Grimley Evanscp libtcc.a libtcc.a.hide
545bd5fd48SEdmund Grimley Evans
555bd5fd48SEdmund Grimley Evansmake clean
565bd5fd48SEdmund Grimley Evans./configure --extra-cflags="-fsanitize=address,undefined -g"
575bd5fd48SEdmund Grimley Evansmake
585bd5fd48SEdmund Grimley Evanscp libtcc.a.hide libtcc.a
595bd5fd48SEdmund Grimley Evansmake test
605bd5fd48SEdmund Grimley Evans
615bd5fd48SEdmund Grimley Evans- Test with Valgrind to detect some uses of uninitialised values:
625bd5fd48SEdmund Grimley Evans
635bd5fd48SEdmund Grimley Evansmake clean
645bd5fd48SEdmund Grimley Evans./configure
655bd5fd48SEdmund Grimley Evansmake
665bd5fd48SEdmund Grimley Evans# On Intel, because Valgrind does floating-point arithmetic differently:
675bd5fd48SEdmund Grimley Evans( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref )
685bd5fd48SEdmund Grimley Evansmake test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`"
695bd5fd48SEdmund Grimley Evans
705bd5fd48SEdmund Grimley Evans  (Because of how VLAs are implemented, invalid reads are expected
715bd5fd48SEdmund Grimley Evans  with 79_vla_continue.)