+2018-08-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * valarith.c (value_subscripted_rvalue): If an array is not in
+ memory, and we don't know the upper bound, then we can't know that
+ the requested element exists or not.
+
2018-08-08 Simon Marchi <simon.marchi@ericsson.com>
* target.c (str_comma_list_concat_elem): Fix typo in comment.
+2018-08-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.base/vla-optimized-out.exp: Add new test.
+
2018-08-09 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.base/vla-optimized-out-o3.exp: Delete.
gdb_test "p sizeof (a)" \
" = $sizeof_result" \
"printed size of optimized out vla"
+
+ # At lower optimisation levels, the upper bound of the array is
+ # still defined, it's just the loctaion that tells GDB the array
+ # is optimised out. In that case, when we access an element that
+ # is within the bounds of the array an answer of '<optimized out>'
+ # is reasonable.
+ #
+ # At higher optimisation levels, the array bounds themselves have
+ # been removed. As such GDB can't be expected to know if the
+ # array contains _any_ elements at all. It seems reasonable in
+ # that case to reply with 'no such vector element'.
+ gdb_test "p a\[0\]" \
+ "(= <optimized out>|no such vector element)" \
+ "print out of range element of vla (0)"
+
+ gdb_test "p a\[6\]" \
+ "no such vector element" \
+ "print out of range element of vla (6)"
+
+ gdb_test "p a\[0xffffffff\]" \
+ "no such vector element" \
+ "print out of range element of vla (0xffffffff)"
}
foreach {test_prefix options} \
ULONGEST elt_size = type_length_units (elt_type);
ULONGEST elt_offs = elt_size * (index - lowerbound);
- if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
- && elt_offs >= type_length_units (array_type)))
+ if (index < lowerbound
+ || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
+ && elt_offs >= type_length_units (array_type))
+ || (VALUE_LVAL (array) != lval_memory
+ && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)))
{
if (type_not_associated (array_type))
error (_("no such vector element (vector not associated)"));