You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bounds checking bounds-safe interfaces in unchecked scopes (#1169)
* Add LValuesAssignedChecked member to CheckedState
LValuesAssignedChecked contains AbstractSets representing lvalues expressions that have unchecked pointer type that were assigned a checked pointer during the current top-level statement (if the statement is in an unchecked scope). AbstractSets in LValuesAssignedChecked should have their bounds validated after checking the current statement.
* Add SkipBoundsValidation method
* Remove expected error for lvalue with a bounds-safe interface in an unchecked scope
* Put declaration of short int with declared bounds in a checked scope so it results in a warning
* Update unchecked pointer inverse test so there is a checked pointer with declared bounds
* Add tests for validating the bounds of an unchecked pointer with a bounds-safe interface
* Add test for assigning a checked array to p
* Add tests for an integer-typed variable with declared bounds
* Fix expected warning to work on both Windows and Linux
* Fix typo in comment
p=arr; // expected-error {{it is not possible to prove that the inferred bounds of 'p' imply the declared bounds of 'p' after assignment}} \
864
+
// expected-note {{the declared upper bounds use the variable 'i' and there is no relational information involving 'i' and any of the expressions used by the inferred upper bounds}} \
865
+
// expected-note {{(expanded) inferred bounds are 'bounds(arr, arr + 3)'}}
866
+
867
+
// In a checked scope, always validate the bounds of p.
868
+
_Checked {
869
+
i=1; // expected-error {{inferred bounds for 'p' are unknown after assignment}} \
870
+
// expected-note {{lost the value of the expression 'i' which is used in the (expanded) inferred bounds 'bounds(p, p + i)' of 'p'}}
871
+
872
+
++p; // expected-warning {{cannot prove declared bounds for 'p' are valid after increment}} \
873
+
// expected-note {{(expanded) inferred bounds are 'bounds(p - 1, p - 1 + i)'}}
874
+
}
875
+
876
+
// Non-pointer-typed values with declared bounds do not have their bounds
877
+
// validated in unchecked scopes.
878
+
short intt1 : byte_count(2) = (short int)arr; // expected-warning {{cast to smaller integer type 'short' from '_Array_ptr<int>'}}
879
+
t1= (short int)r; // expected-warning {{cast to smaller integer type 'short' from '_Array_ptr<int>'}}
880
+
881
+
// Non-pointer-typed values with declared bounds have their bounds
882
+
// validated in checked scopes.
883
+
_Checked {
884
+
short intt2 : byte_count(2) = (short int)r; // expected-error {{inferred bounds for 't2' are unknown after initialization}} \
0 commit comments