@@ -12,7 +12,7 @@ This article focuses on some of the non-obvious and easy to make mistakes
12
12
non-experienced C programmers are likely to make and are/can not completely
13
13
be covered by tooling without going into edge cases relevant to performance
14
14
and covering the most simple and conservative approach:
15
- - 1.[Pointer semantics](# pointer_semantics)
15
+ - 1.[Pointer semantics]($link.unsafeRef(' pointer_semantics') )
16
16
- 2.[Sequence points](#seq_pts)
17
17
- 3.[Bit-fields](#bitfields)
18
18
@@ -57,17 +57,17 @@ abbreviated via macro `NULL`.
57
57
[]($section.id("pointer_access_practice"))
58
58
**Pointer access** in **practice**.
59
59
- Provenance as regions pointer is allowed to point to for access.
60
- [provenance.c]($code.asset('./ provenance.c').language('c'))
60
+ [provenance.c]($code.asset('provenance.c').language('c'))
61
61
- Copy around some bytes from not overlapping regions (otherwise use memmove).
62
- [copy_bytes.c]($code.asset('./ copy_bytes.c').language('c'))
62
+ [copy_bytes.c]($code.asset('copy_bytes.c').language('c'))
63
63
- Correct alignment of pointers with temporary, when necessary.
64
- [correct_alignment.c]($code.asset('./ correct_alignment.c').language('c'))
64
+ [correct_alignment.c]($code.asset('correct_alignment.c').language('c'))
65
65
- Ensure correct storage and padding size for pointers via sizeof.
66
- [storage_padding.c]($code.asset('./ storage_padding.c').language('c'))
66
+ [storage_padding.c]($code.asset('storage_padding.c').language('c'))
67
67
- Allowed aliasing of pointers (type-based aliasing analysis)
68
- [allowed_aliasing.c]($code.asset('./ allowed_aliasing.c').language('c'))
68
+ [allowed_aliasing.c]($code.asset('allowed_aliasing.c').language('c'))
69
69
- Non-allowed aliasing of pointers (type-based aliasing analysis)
70
- [non_allowed_aliasing.c]($code.asset('./ non_allowed_aliasing.c').language('c'))
70
+ [non_allowed_aliasing.c]($code.asset('non_allowed_aliasing.c').language('c'))
71
71
72
72
[]($section.id("pointer_exceptions"))
73
73
**The Exceptions**
@@ -81,7 +81,7 @@ abbreviated via macro `NULL`.
81
81
back. This also means that `sizeof (function pointer) == sizeof (void *)` must be uphold, which is not true for
82
82
microcontrollers with separate address space for code and data or CHERI in mixed capability mode/hybrid compilation mode.
83
83
Address space annotations are mandatory for this to work and it is unfortunate that standards do not reflect this as of 2024-04-28.
84
- [aliasing_exceptions_uniform_address_space.c]($code.asset('./ aliasing_exceptions_uniform_address_space.c').language('c'))
84
+ [aliasing_exceptions_uniform_address_space.c]($code.asset('aliasing_exceptions_uniform_address_space.c').language('c'))
85
85
86
86
[]($section.id("pointer_construction_requirements"))
87
87
**Pointer construction requirements** are unspecified in all C standards with potentially some hints and nothing
@@ -154,12 +154,12 @@ Other more elaborative examples can be seen in the github gist "What is the Stri
154
154
155
155
[]($section.id("opaque"))
156
156
Opaque type idiom.
157
- [opaque.h]($code.asset('./ opaque.h').language('c'))
158
- [opaque.c]($code.asset('./ opaque.c').language('c'))
157
+ [opaque.h]($code.asset('opaque.h').language('c'))
158
+ [opaque.c]($code.asset('opaque.c').language('c'))
159
159
160
160
[]($section.id("ptrintconv"))
161
161
Pointer to integer and integer to pointer conversion.
162
- [ptrtoint_inttoptr.c]($code.asset('./ ptrtoint_inttoptr.c').language('c'))
162
+ [ptrtoint_inttoptr.c]($code.asset('ptrtoint_inttoptr.c').language('c'))
163
163
164
164
[]($section.id("lto"))
165
165
Link time optimization (LTO) usage and problems. One can use `ptrtoint_inttoptr.c` with flags for strong LTO
@@ -172,24 +172,24 @@ compiler automatically do runtime selection of the best SIMD routine instead of
172
172
is vectorized and one has to check for example via `clang -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize`
173
173
or `gcc -O3 -ftree-vectorizer-verbose=3` and use [clang extensions](https://clang.llvm.org/docs/LanguageExtensions.html)
174
174
and [gcc extensions](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) like `__builtin_assume_aligned`.
175
- [extern_avx.h]($code.asset('./ extern_avx.h').language('c'))
176
- [extern_avx.c]($code.asset('./ extern_avx.c').language('c'))
177
- [memcpy_avx.c]($code.asset('./ memcpy_avx.c').language('c'))
175
+ [extern_avx.h]($code.asset('extern_avx.h').language('c'))
176
+ [extern_avx.c]($code.asset('extern_avx.c').language('c'))
177
+ [memcpy_avx.c]($code.asset('memcpy_avx.c').language('c'))
178
178
179
179
[]($section.id("cerberus"))
180
180
Checking C code validity with Cerberus does not imply absence of compiler miscompilations.
181
- [cerberus_install.sh]($code.asset('./ cerberus_install.sh').language('bash'))
182
- [extern_miscompilation.h]($code.asset('./ extern_miscompilation.h').language('c'))
183
- [extern_miscompilation.c]($code.asset('./ extern_miscompilation.c').language('c'))
184
- [ptr_provenance_miscompilation.c]($code.asset('./ ptr_provenance_miscompilation.c').language('c'))
181
+ [cerberus_install.sh]($code.asset('cerberus_install.sh').language('bash'))
182
+ [extern_miscompilation.h]($code.asset('extern_miscompilation.h').language('c'))
183
+ [extern_miscompilation.c]($code.asset('extern_miscompilation.c').language('c'))
184
+ [ptr_provenance_miscompilation.c]($code.asset('ptr_provenance_miscompilation.c').language('c'))
185
185
186
186
[]($section.id("cheri"))
187
187
CHERI usage is left as task for the reader. Useful links are `https://github.com/CTSRD-CHERI/cheribuild`,
188
188
`https://github.com/CTSRD-CHERI/cheri-c-programming` and `https://github.com/capablevms/cheri-examples`.
189
189
190
190
[]($section.id("seq_pts"))
191
191
**Sequence Points** in simple case and with storage lifetime extension.
192
- [sequence_points.c]($code.asset('./ sequence_points.c').language('c'))
192
+ [sequence_points.c]($code.asset('sequence_points.c').language('c'))
193
193
194
194
[]($section.id("bitfields"))
195
195
**Bit-fields** should not be used unless for non-portable code regarding
0 commit comments