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

Method select_must_use_var

src/VariableSelector.cpp:1458–1497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1456}
1457
1458const Variable*
1459VariableSelector::select_must_use_var(Effect::Access access, CGContext &cg_context, const Type* type, const CVQualifiers* qfer)
1460{
1461 if (cg_context.rw_directive == NULL) return NULL;
1462
1463 const Variable* var = 0;
1464 VariableSet& vars = (access == Effect::READ) ? cg_context.rw_directive->must_read_vars : cg_context.rw_directive->must_write_vars;
1465 eMatchType mt = (access == Effect::READ) ? eFlexible : eDerefExact;
1466 for (size_t i=0; i<vars.size(); i++) {
1467 const Variable* v = vars[i];
1468 if (v->is_visible(cg_context.get_current_block())) {
1469 if (type->match(v->type, mt) && (!qfer || qfer->match(v->qfer))) {
1470 int deref_level = v->type->get_indirect_level() - type->get_indirect_level();
1471 // for LHS, make sure the array type is not constant after dereference
1472 if (access == Effect::WRITE && v->qfer.is_const_after_deref(deref_level)) {
1473 continue;
1474 }
1475
1476 if (v->isArray) {
1477 const ArrayVariable* av = dynamic_cast<const ArrayVariable*>(v);
1478 var = VariableSelector::itemize_array(cg_context, av);
1479 } else {
1480 var = v;
1481 }
1482 }
1483 else if (0) {//var = v->match_field(type, mt)) { // JYTODO: match a field of array of structs
1484 if (v->isArray) {
1485 //var = VariableSelector::select_random_array_var(var, cg_context.ivs);
1486 }
1487 }
1488 }
1489 if (var) {
1490 if (rnd_flipcoin(75)) {
1491 vars.erase(vars.begin() + i);
1492 }
1493 break;
1494 }
1495 }
1496 return var;
1497}
1498
1499ArrayVariable*
1500VariableSelector::create_mutated_array_var(const ArrayVariable* av, const vector<const Expression*>& new_indices)

Callers

nothing calls this directly

Calls 8

rnd_flipcoinFunction · 0.85
sizeMethod · 0.80
is_visibleMethod · 0.80
get_current_blockMethod · 0.80
beginMethod · 0.80
matchMethod · 0.45
get_indirect_levelMethod · 0.45
is_const_after_derefMethod · 0.45

Tested by

no test coverage detected