@@ -177,6 +177,18 @@ TEST_CASE(
177
177
from_integer (init_expr_value, signedbv_typet{init_expr_size}),
178
178
output_type);
179
179
REQUIRE (result_with_signed_init_type == result);
180
+
181
+ // Check that replicating a pointer_value is same as unsigned_bv.
182
+ const pointer_typet pointer_type{bool_typet{}, output_size};
183
+ const auto result_with_pointer_type = duplicate_per_byte (
184
+ from_integer (init_expr_value, signedbv_typet{init_expr_size}),
185
+ pointer_type);
186
+ auto pointer_typed_expected =
187
+ from_integer (output_expected_value, unsignedbv_typet{output_size});
188
+ // Forcing the type to be pointer_typet otherwise from_integer fails when
189
+ // the init value is not 0 (NULL).
190
+ pointer_typed_expected.type () = pointer_type;
191
+ REQUIRE (result_with_pointer_type == pointer_typed_expected);
180
192
}
181
193
}
182
194
@@ -212,6 +224,21 @@ TEST_CASE(
212
224
replicate_expression (casted_init_expr, output_type, replication_count);
213
225
214
226
REQUIRE (result == expected);
227
+
228
+ // Check that replicating a pointer_value is same as unsigned_bv modulo a
229
+ // typecast outside.
230
+ const pointer_typet pointer_type{bool_typet{}, output_size};
231
+ const auto pointer_typed_result =
232
+ duplicate_per_byte (init_expr, pointer_type);
233
+ const auto pointer_unsigned_corr_type = unsignedbv_typet{output_size};
234
+ const auto pointer_init_expr =
235
+ typecast_exprt::conditional_cast (init_expr, pointer_unsigned_corr_type);
236
+ const auto pointer_expected = typecast_exprt::conditional_cast (
237
+ replicate_expression (
238
+ pointer_init_expr, pointer_unsigned_corr_type, replication_count),
239
+ pointer_type);
240
+
241
+ REQUIRE (pointer_typed_result == pointer_expected);
215
242
}
216
243
}
217
244
@@ -312,6 +339,53 @@ TEST_CASE(
312
339
}
313
340
}
314
341
342
+ TEST_CASE (
343
+ " expr_initializer on variable-bit pointer type" ,
344
+ " [core][util][expr_initializer]" )
345
+ {
346
+ auto test = expr_initializer_test_environmentt::make ();
347
+ const std::size_t input_type_size = GENERATE (3 , 8 , 16 , 20 );
348
+ SECTION (
349
+ " Testing with expected type as unsigned_bv of size " +
350
+ std::to_string (input_type_size))
351
+ {
352
+ typet input_type = pointer_typet{bool_typet{}, input_type_size};
353
+ SECTION (" nondet_initializer works" )
354
+ {
355
+ const auto result = nondet_initializer (input_type, test.loc , test.ns );
356
+ REQUIRE (result.has_value ());
357
+ const auto expected = side_effect_expr_nondett{
358
+ pointer_typet{bool_typet{}, input_type_size}, test.loc };
359
+ REQUIRE (result.value () == expected);
360
+ const auto expr_result =
361
+ expr_initializer (input_type, test.loc , test.ns , exprt (ID_nondet));
362
+ REQUIRE (expr_result == result);
363
+ }
364
+ SECTION (" zero_initializer works" )
365
+ {
366
+ const auto result = zero_initializer (input_type, test.loc , test.ns );
367
+ REQUIRE (result.has_value ());
368
+ auto expected =
369
+ from_integer (0 , pointer_typet{bool_typet{}, input_type_size});
370
+ REQUIRE (result.value () == expected);
371
+ const auto expr_result = expr_initializer (
372
+ input_type, test.loc , test.ns , constant_exprt (ID_0, char_type ()));
373
+ REQUIRE (expr_result == result);
374
+ }
375
+ SECTION (" expr_initializer calls duplicate_per_byte" )
376
+ {
377
+ const exprt init_value =
378
+ from_integer (0x0A , unsignedbv_typet{config.ansi_c .char_width });
379
+ const auto result =
380
+ expr_initializer (input_type, test.loc , test.ns , init_value);
381
+ REQUIRE (result.has_value ());
382
+ const auto expected = duplicate_per_byte (
383
+ init_value, pointer_typet{bool_typet{}, input_type_size});
384
+ REQUIRE (result.value () == expected);
385
+ }
386
+ }
387
+ }
388
+
315
389
TEST_CASE (
316
390
" expr_initializer on c_enum and c_enum_tag" ,
317
391
" [core][util][expr_initializer]" )
0 commit comments