Download Bound-T User Manual - Bound
Transcript
Local variables in calls When there are assertions on variable values in a call context, and some of these variables occur in the call's actual parameter expressions, the parameterpassing mechanism of the call translates the asserted bounds on the caller's variables into bounds on the callee's (formal) parameters. For example, consider an Ada call of the form Send_Nulls (N => K + 1); where N is a formal parameter to Send_Nulls and K is a local variable in the caller. Assume that the code for the caller keeps the caller's variable K in register r6, but the code for Send_Nulls expects the parameter N to be passed (by value) in register r0, and that we assert call to "Send_Nulls" variable "K" 4; end call; The result is to assert that r6 at the call has the value 4 and so r0, representing the parameter N of Send_Nulls, has the value 4 + 1 = 5 on entry to this invocation of Send_Nulls. Do not assert foreign local variables in calls Take care to assert callspecific bounds only on global variables or variables that are local to the caller or formal parameters of the caller. Assertions on the value of a variable that is local to other subprograms (such as the callee) will probably not work correctly, because BoundT translates the variable name to a machinelevel local variable reference (such as a stack offset or a register reference). BoundT then applies this machinelevel reference in the caller, so that the assertion in fact bounds an unrelated local variable of the caller. In particular, do not use the callee's formal parameter names in a callcontext assertion. For example, assume that the formal parameter N of Send_Nulls (see the example in the preceding subsection) is passed via the stack and not in register r0 as assumed above. Now, although the above assertion on K for the call to Send_Nulls has the effect of bounding the formal parameter N, it cannot be written as follows: call to "Send_Nulls" variable "N" 5; end call; Wrong! Since the symbol table maps N to “the first stacked parameter”, this (wrong) assertion in fact bounds the value of the first stacked parameter of the caller, which probably has nothing to do with K or N. You can break this rule only if you are sure that the formal parameter is mapped to a statically addressed memory location or a statically named register so that the machinelevel parameter reference points to the same physical storage location when interpreted in the caller and in the callee. 2.11 Assertions on variable invariance Why? When BoundT analyses the computations in a subprogram or a loop it is often important to know if some part of the code, such as the loop body or a call, can change the value of a certain variable, or whether the variable is invariant (unchanged) over that code. BoundT tries to detect invariant variables automatically but this analysis, like many others in BoundT, is not complete and can miss some invariances. This can cause some other analysis to fail. For 24 Writing Assertions BoundT Assertion Language