CodingStyle 2.1 KB

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