MCPcopy Create free account
hub / github.com/csmith-project/csmith / select_array

Method select_array

src/VariableSelector.cpp:1363–1399  ·  view source on GitHub ↗

* select a random array variable, or generate a new one if none available */

Source from the content-addressed store, hash-verified

1361 * select a random array variable, or generate a new one if none available
1362 */
1363ArrayVariable*
1364VariableSelector::select_array(const CGContext &cg_context)
1365{
1366 const Block* b = cg_context.get_current_block();
1367 vector<Variable*> vars = find_all_visible_vars(b);
1368 vector<ArrayVariable*> array_vars;
1369 size_t i, len;
1370 for (i=0; i<vars.size(); i++) {
1371 if (!vars[i]->isArray)
1372 continue;
1373
1374 ArrayVariable* av = dynamic_cast<ArrayVariable*>(vars[i]);
1375 assert(av);
1376 if (av->collective != 0)
1377 continue;
1378
1379 if (!cg_context.get_effect_context().is_read_partially(av) &&
1380 !cg_context.get_effect_context().is_written_partially(av) &&
1381 (cg_context.get_effect_context().is_side_effect_free() || !av->is_volatile()) &&
1382 !av->is_const() &&
1383 !cg_context.is_nonwritable(av) &&
1384 !av->type->is_const_struct_union()) {
1385
1386 if (CGOptions::strict_volatile_rule() && av->is_volatile())
1387 continue;
1388 array_vars.push_back(av);
1389 }
1390 }
1391 len = array_vars.size();
1392 if (len == 0) {
1393 return create_random_array(cg_context);
1394 }
1395 if (len == 1) return array_vars[0];
1396 size_t index = rnd_upto(len);
1397 ERROR_GUARD(NULL);
1398 return array_vars[index];
1399}
1400
1401/* given a collective array, create a member out of induction variables in the context */
1402ArrayVariable*

Callers

nothing calls this directly

Calls 10

rnd_uptoFunction · 0.85
get_current_blockMethod · 0.80
sizeMethod · 0.80
is_read_partiallyMethod · 0.80
is_written_partiallyMethod · 0.80
is_side_effect_freeMethod · 0.80
is_nonwritableMethod · 0.80
is_const_struct_unionMethod · 0.80
is_volatileMethod · 0.45
is_constMethod · 0.45

Tested by

no test coverage detected