@@ -123,22 +123,54 @@ \subsection{Variables}
123
123
{\var {x}\texttt {.upper\_ bound }}
124
124
{\var {T}}}
125
125
\item
126
- If \var {x} has an array type with a known number of elements \var {n}
127
- such that the variable is being converted implicitly to a pointer
128
- type, the bounds are \boundsinfer {\var {x}}{\boundscount {\var {n}}}.
129
- \item
130
- Otherwise \var {x} has \boundsnone .
126
+ If \var {x} has an array type, the rules depend on whether \var {x} is a parameter
127
+ variable. Typechecking in C treats a parameter variable with the type `` array of \var {T}''
128
+ as though it has the type `` pointer to \var {T}'' . It does not enforce
129
+ at function calls that actual arguments have the required dimension size. This means
130
+ that the declared outermost bounds cannot be trusted for parameters with unchecked
131
+ array types. In contrast, local variables and externally-scoped variables are allocated
132
+ space for their declared types. Declared dimension information for them can be trusted
133
+ regardless of whether they have checked or unchecked array types. Checking of bounds
134
+ declarations for checked arrays enforces that actual arguments meet the required
135
+ dimension size.
136
+ \begin {itemize }
137
+ \item If
138
+ \begin {itemize }
139
+ \item \var {x} is a local variable or an externally scoped variable
140
+ \item or \var {x} is a parameter variable with a checked array type
141
+ \end {itemize }
142
+ and \var {x} has a known number of elements \var {n}, then
143
+ \boundsinfer {\var {x}}{\boundscount {\var {n}}}.
144
+ \item Otherwise, the bounds are the result of the analysis in
145
+ Section~\ref {section:extent-definition } for this occurrence of \var {x}.
146
+ \end {itemize }
147
+ \item Otherwise \var {x} has \boundsnone .
131
148
\end {itemize }
132
149
150
+ \subsection {Address-of expressions }
133
151
134
- \subsection { Addresses of variables }
135
-
136
- A variable with type \ var {T} whose address is taken is considered to be
137
- an array of one element:
152
+ There are three kinds of address-of expressions:
153
+ \begin { itemize }
154
+ \item Address of a variable ( \texttt { \& \ var {x} }): a variable \var {x} with type \var {T}
155
+ whose address is taken is considered to be an array of one element:
138
156
139
157
\boundsinfer {\texttt {\& \var {x} }}
140
158
{\boundsrel {\texttt {\& \var {x} }}{\texttt {\& \var {x} + 1 }}{\var {T}}}.
141
-
159
+
160
+ \item Address of a pointer dereference operation ({\texttt {\& *\var {e} }}):
161
+ The address-of operation and the pointer dereference operation cancel.
162
+ The bounds are the bounds of the underlying expression.
163
+ If \boundsinfer {\var {e}}{\var {bounds-exp}}, then
164
+ \boundsinfer {\texttt {\& *\var {e} }}{\var {bounds-exp}}.
165
+
166
+ \item Address-of a subscripting expression (\texttt {\& \var {e1}[\var {e2}] }):
167
+ This is the same as taking the address of a pointer dereference operation.
168
+ According to the C semantics, \texttt {\var {e1}[\var {e2}] } is equivalent
169
+ to \texttt {*(\var {e1} + \var {e2}) }. If
170
+ \boundsinfer {\var {e1} + \var {e2}}{\var {bounds-exp}}, then
171
+ \boundsinfer {\texttt {\& \var {e1}[\var {e2}] }}{\var {bounds-exp}}.
172
+ \end {itemize }
173
+
142
174
\subsection {Function calls }
143
175
\label {section:inferring-bounds-for-function-calls }
144
176
0 commit comments