Showing the changes to CodingStyle (1 of 1 file). Show all
Unified · Split
| @@ -1,6 +1,74 @@ | |||
| 1 | |||
| 2 | In general, use the same coding style as the surrounding code. | ||
| 3 | |||
| 4 | However, do not make any unnecessary changes as that complicates | ||
| 5 | the VCS (git) history and makes it harder to merge patches. So | ||
| 6 | do not modify code just to make it conform to a coding style. | ||
| 7 | |||
| 1 | Indentation | 8 | Indentation |
| 2 | 9 | ||
| 3 | Turn on a "fill tabs with spaces" option in your editor. | 10 | Turn on a "fill tabs with spaces" option in your editor. |
| 4 | 11 | ||
| 5 | Be also careful that some files are indented with 2 spaces (when they | 12 | Remove tabs and trailing spaces from any lines that are modified. |
| 13 | |||
| 14 | Note that some files are indented with 2 spaces (when they | ||
| 6 | have large indentation) while most are indented with 4 spaces. | 15 | have large indentation) while most are indented with 4 spaces. |
| 16 | |||
| 17 | Language | ||
| 18 | |||
| 19 | TCC is mostly implemented in C90. Do not use any non-C90 features | ||
| 20 | that are not already in use. | ||
| 21 | |||
| 22 | Non-C90 features currently in use, as revealed by | ||
| 23 | ./configure --extra-cflags="-std=c90 -Wpedantic": | ||
| 24 | |||
| 25 | - long long (including "LL" constants) | ||
| 26 | - inline | ||
| 27 | - very long string constants | ||
| 28 | - assignment between function pointer and 'void *' | ||
| 29 | - "//" comments | ||
| 30 | - empty macro arguments (DEF_ASMTEST in i386-tok.h) | ||
| 31 | - unnamed struct and union fields (in struct Sym), a C11 feature | ||
| 32 | |||
| 33 | Testing | ||
| 34 | |||
| 35 | A simple "make test" is sufficient for some simple changes. However, | ||
| 36 | before committing a change consider performing some of the following | ||
| 37 | additional tests: | ||
| 38 | |||
| 39 | - Build and run "make test" on several architectures. | ||
| 40 | |||
| 41 | - Build with ./configure --enable-cross. | ||
| 42 | |||
| 43 | - If the generation of relocations has been changed, try compiling | ||
| 44 | with TCC and linking with GCC/Clang. If the linker has been | ||
| 45 | modified, try compiling with GCC/Clang and linking with TCC. | ||
| 46 | |||
| 47 | - Test with ASan/UBSan to detect memory corruption and undefined behaviour: | ||
| 48 | |||
| 49 | make clean | ||
| 50 | ./configure | ||
| 51 | make | ||
| 52 | make test | ||
| 53 | cp libtcc.a libtcc.a.hide | ||
| 54 | |||
| 55 | make clean | ||
| 56 | ./configure --extra-cflags="-fsanitize=address,undefined -g" | ||
| 57 | make | ||
| 58 | cp libtcc.a.hide libtcc.a | ||
| 59 | make test | ||
| 60 | |||
| 61 | (On 64-bit architectures, misaligned access to struct CString is | ||
| 62 | expected.) | ||
| 63 | |||
| 64 | - Test with Valgrind to detect some uses of uninitialised values: | ||
| 65 | |||
| 66 | make clean | ||
| 67 | ./configure | ||
| 68 | make | ||
| 69 | # On Intel, because Valgrind does floating-point arithmetic differently: | ||
| 70 | ( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref ) | ||
| 71 | make test TCC="valgrind -q --leak-check=full `pwd`/tcc -B`pwd` -I`pwd`" | ||
| 72 | |||
| 73 | (Because of how VLAs are implemented, invalid reads are expected | ||
| 74 | with 79_vla_continue.) | ||