@@ -5,16 +5,39 @@ Implementation plans for ``-fbounds-safety``
5
5
.. contents ::
6
6
:local:
7
7
8
+ Gradual updates with experimental flag
9
+ ======================================
10
+
11
+ The feature will be implemented as a series of smaller PRs and we will guard our
12
+ implementation with an experimental flag ``-fexperimental-bounds-safety `` until
13
+ the usable model is fully available. Once the model is ready for use, we will
14
+ expose the flag ``-fbounds-safety ``.
15
+
16
+ Possible patch sets
17
+ -------------------
18
+
19
+ * External bounds annotations and the (late) parsing logic.
20
+ * Internal bounds annotations (wide pointers) and their parsing logic.
21
+ * Clang code generation for wide pointers with debug information.
22
+ * Pointer cast semantics involving bounds annotations (this could be divided
23
+ into multiple sub-PRs).
24
+ * CFG analysis for pairs of related pointer and count assignments and the likes.
25
+ * Bounds check expressions in AST and the Clang code generation (this could also
26
+ be divided into multiple sub-PRs).
27
+
28
+ Proposed implementation
29
+ =======================
30
+
8
31
External bounds annotations
9
- ===========================
32
+ ---------------------------
10
33
11
34
The bounds annotations are C type attributes appertaining to pointer types. If
12
35
an attribute is added to the position of a declaration attribute, e.g., ``int
13
36
*ptr __counted_by(size) ``, the attribute appertains to the outermost pointer
14
37
type of the declaration (``int * ``).
15
38
16
39
New sugar types
17
- ===============
40
+ ---------------
18
41
19
42
An external bounds annotation creates a type sugar of the underlying pointer
20
43
types. We will introduce a new sugar type, ``DynamicBoundsPointerType `` to
@@ -29,7 +52,7 @@ overloading. However, this design requires a separate logic to walk through the
29
52
entire type hierarchy to check type compatibility of bounds annotations.
30
53
31
54
Late parsing for C
32
- ==================
55
+ ------------------
33
56
34
57
A bounds annotation such as ``__counted_by(count) `` can be added to type of a
35
58
struct field declaration where count is another field of the same struct
@@ -43,7 +66,7 @@ same logic. This requires introducing late parsing logic for C/C++ type
43
66
attributes.
44
67
45
68
Internal bounds annotations
46
- ===========================
69
+ ---------------------------
47
70
48
71
``__indexable `` and ``__bidi_indexable `` alter pointer representations to be
49
72
equivalent to a struct with the pointer and the corresponding bounds fields.
@@ -65,7 +88,7 @@ operations returning wide pointers. Alternatively, a new ``TEK`` and an
65
88
expression emitter dedicated to wide pointers could be introduced.
66
89
67
90
Default bounds annotations
68
- ==========================
91
+ --------------------------
69
92
70
93
The model may implicitly add ``__bidi_indexable `` or ``__single `` depending on
71
94
the context of the declaration that has the pointer type. ``__bidi_indexable ``
@@ -79,7 +102,7 @@ This also requires the parser to reset the type of the declaration with the
79
102
newly created type with the right default attribute.
80
103
81
104
Promotion expression
82
- ====================
105
+ --------------------
83
106
84
107
A new expression will be introduced to represent the conversion from a pointer
85
108
with an external bounds annotation, such as ``__counted_by ``, to
@@ -88,7 +111,7 @@ CastExprs because it requires an extra subexpression(s) to provide the bounds
88
111
information necessary to create a wide pointer.
89
112
90
113
Bounds check expression
91
- =======================
114
+ -----------------------
92
115
93
116
Bounds checks are part of semantics defined in the ``-fbounds-safety `` language
94
117
model. Hence, exposing the bounds checks and other semantic actions in the AST
@@ -98,7 +121,7 @@ and has the additional sub-expressions that are necessary to perform the check
98
121
according to the kind.
99
122
100
123
Paired assignment check
101
- =======================
124
+ -----------------------
102
125
103
126
``-fbounds-safety `` enforces that variables or fields related with the same
104
127
external bounds annotation (e.g., ``buf `` and ``count `` related with
@@ -123,7 +146,7 @@ provides a linear view of statements within each ``CFGBlock`` (Clang
123
146
``CFGBlock `` represents a single basic block in a source-level CFG).
124
147
125
148
Bounds check optimizations
126
- ==========================
149
+ --------------------------
127
150
128
151
In ``-fbounds-safety ``, the Clang frontend emits run-time checks for every
129
152
memory dereference if the type system or analyses in the frontend couldn’t
@@ -229,27 +252,3 @@ solution.
229
252
230
253
``-fbounds-safety `` is not currently supported in C++, but we believe the
231
254
general approach would be applicable for future efforts.
232
-
233
- Upstreaming plan
234
- ================
235
-
236
- Gradual updates with experimental flag
237
- --------------------------------------
238
-
239
- The upstreaming will take place as a series of smaller PRs and we will guard our
240
- implementation with an experimental flag ``-fexperimental-bounds-safety `` until
241
- the usable model is fully upstreamed. Once the model is ready for use, we will
242
- expose the flag ``-fbounds-safety ``.
243
-
244
- Possible patch sets
245
- -------------------
246
-
247
- * External bounds annotations and the (late) parsing logic.
248
- * Internal bounds annotations (wide pointers) and their parsing logic.
249
- * Clang code generation for wide pointers with debug information.
250
- * Pointer cast semantics involving bounds annotations (this could be divided
251
- into multiple sub-PRs).
252
- * CFG analysis for pairs of related pointer and count assignments and the likes.
253
- * Bounds check expressions in AST and the Clang code generation (this could also
254
- be divided into multiple sub-PRs).
255
-
0 commit comments