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

Method create_random_array

src/VariableSelector.cpp:1318–1358  ·  view source on GitHub ↗

* create an array of random type, non-qualifier, with random initial value, in a random block (or as global) */

Source from the content-addressed store, hash-verified

1316 * create an array of random type, non-qualifier, with random initial value, in a random block (or as global)
1317 */
1318ArrayVariable*
1319VariableSelector::create_random_array(const CGContext& cg_context)
1320{
1321 bool as_global = CGOptions::global_variables() && rnd_flipcoin(25);
1322 ERROR_GUARD(NULL);
1323 string name;
1324 Block* blk = 0;
1325 Function* func = cg_context.get_current_func();
1326 if (as_global) {
1327 name = RandomGlobalName();
1328 }
1329 else {
1330 name = RandomLocalName();
1331 size_t index = rnd_upto(func->stack.size());
1332 ERROR_GUARD(NULL);
1333 blk = func->stack[index];
1334 blk = expand_block_for_goto(blk, cg_context);
1335 }
1336 const Type* type = 0;
1337 do {
1338 // don't make life complicated, restrict local variables to non-volatile
1339 type = as_global ? Type::choose_random_nonvoid() : Type::choose_random_nonvoid_nonvolatile();
1340 ERROR_GUARD(NULL);
1341 } while (type->is_const_struct_union() || !cg_context.accept_type(type));
1342 CVQualifiers qfer;
1343 qfer.add_qualifiers(false, false);
1344
1345 Expression* init = Constant::make_random(type);
1346 ArrayVariable* av = ArrayVariable::CreateArrayVariable(cg_context, blk, name, type, init, &qfer, NULL);
1347 AllVars.push_back(av);
1348
1349 // make the points-to fact known to DFA
1350 FactMgr* fm = get_fact_mgr(&cg_context);
1351 if (as_global) {
1352 fm->add_new_var_fact_and_update_inout_maps(NULL, av);
1353 cg_context.get_current_func()->new_globals.push_back(av);
1354 } else {
1355 fm->add_new_var_fact_and_update_inout_maps(blk, av);
1356 }
1357 return av;
1358}
1359
1360/*
1361 * select a random array variable, or generate a new one if none available

Callers

nothing calls this directly

Calls 11

rnd_flipcoinFunction · 0.85
RandomGlobalNameFunction · 0.85
RandomLocalNameFunction · 0.85
rnd_uptoFunction · 0.85
get_fact_mgrFunction · 0.85
get_current_funcMethod · 0.80
sizeMethod · 0.80
is_const_struct_unionMethod · 0.80
accept_typeMethod · 0.80
add_qualifiersMethod · 0.80

Tested by

no test coverage detected