File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed
jbmc/regression/jbmc-strings/CharAtConstantEvaluation Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Main {
2
+ public void constantCharAt () {
3
+ StringBuilder sb = new StringBuilder ("abc" );
4
+ char c = sb .charAt (1 );
5
+ assert c == 'b' ;
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ Main.class
3
+ --function Main.constantCharAt --show-vcc
4
+ ^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5
+ ^EXIT=0$
6
+ ^SIGNAL=0$
7
+ --
8
+ --
Original file line number Diff line number Diff line change @@ -235,6 +235,45 @@ bool simplify_exprt::simplify_function_application(exprt &expr)
235
235
expr = from_integer (is_prefix ? 1 : 0 , expr.type ());
236
236
return false ;
237
237
}
238
+ else if (func_id == ID_cprover_string_char_at_func)
239
+ {
240
+ if (function_app.arguments ().at (1 ).id () != ID_constant)
241
+ {
242
+ return true ;
243
+ }
244
+
245
+ const auto &index = to_constant_expr (function_app.arguments ().at (1 ));
246
+
247
+ const refined_string_exprt &s =
248
+ to_string_expr (function_app.arguments ().at (0 ));
249
+
250
+ const auto char_seq_opt = try_get_string_data_array (s, ns);
251
+
252
+ if (!char_seq_opt)
253
+ {
254
+ return true ;
255
+ }
256
+
257
+ const array_exprt &char_seq = char_seq_opt->get ();
258
+
259
+ const auto i_opt = numeric_cast<std::size_t >(index);
260
+
261
+ if (!i_opt || *i_opt >= char_seq.operands ().size ())
262
+ {
263
+ return true ;
264
+ }
265
+
266
+ const auto &c = to_constant_expr (char_seq.operands ().at (*i_opt));
267
+
268
+ if (c.type () != expr.type ())
269
+ {
270
+ return true ;
271
+ }
272
+
273
+ expr = c;
274
+
275
+ return false ;
276
+ }
238
277
239
278
return true ;
240
279
}
You can’t perform that action at this time.
0 commit comments