History

CodingStyle: Add notes on language and testing.

Edmund Grimley Evans committed 10 years ago

Commit 5bd5fd41 parent 3ff77a11 file · +69 −1Browse files

Showing the changes to CodingStyle (1 of 1 file). Show all

Unified · Split

CodingStyle+69−1
@@ -1,6 +1,74 @@
1
2In general, use the same coding style as the surrounding code.
3
4However, do not make any unnecessary changes as that complicates
5the VCS (git) history and makes it harder to merge patches. So
6do not modify code just to make it conform to a coding style.
7
1 Indentation8 Indentation
2 9
3Turn on a "fill tabs with spaces" option in your editor.10Turn on a "fill tabs with spaces" option in your editor.
4 11
5Be also careful that some files are indented with 2 spaces (when they12Remove tabs and trailing spaces from any lines that are modified.
13
14Note that some files are indented with 2 spaces (when they
6have large indentation) while most are indented with 4 spaces.15have large indentation) while most are indented with 4 spaces.
16
17 Language
18
19TCC is mostly implemented in C90. Do not use any non-C90 features
20that are not already in use.
21
22Non-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
35A simple "make test" is sufficient for some simple changes. However,
36before committing a change consider performing some of the following
37additional 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
49make clean
50./configure
51make
52make test
53cp libtcc.a libtcc.a.hide
54
55make clean
56./configure --extra-cflags="-fsanitize=address,undefined -g"
57make
58cp libtcc.a.hide libtcc.a
59make 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
66make clean
67./configure
68make
69# On Intel, because Valgrind does floating-point arithmetic differently:
70( cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref )
71make 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.)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t