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

Method select

src/VariableSelector.cpp:1171–1229  ·  view source on GitHub ↗

-------------------------------------------------------------- Select or Create a new variable visible to this scope (new var may be global, or local to one of the function's blocks)

Source from the content-addressed store, hash-verified

1169// Select or Create a new variable visible to this scope (new var may be
1170// global, or local to one of the function's blocks)
1171Variable *
1172VariableSelector::select(Effect::Access access,
1173 const CGContext &cg_context,
1174 const Type* type,
1175 const CVQualifiers* qfer,
1176 const vector<const Variable*>& invalid_vars,
1177 eMatchType mt, eVariableScope scope)
1178{
1179 DEPTH_GUARD_BY_TYPE_RETURN_WITH_FLAG(dtSelectVariable, scope, NULL);
1180 VariableSelectFilter filter(cg_context);
1181 if (scope == MAX_VAR_SCOPE) {
1182 scope = VariableSelectionProbability(scope, &filter);
1183 }
1184 ERROR_GUARD(NULL);
1185 Variable *var = 0;
1186 var_created = false;
1187
1188 // Note that many of the functions that select `var' can return null, if
1189 // they cannot find a suitable variable. So we loop.
1190 switch (scope) {
1191 case eGlobal:
1192 var = SelectGlobal(access, cg_context, type, qfer, mt, invalid_vars);
1193 break;
1194 case eParentLocal:
1195 // ...a local var from one of its blocks.
1196 var = SelectParentLocal(access, cg_context, type, qfer, mt, invalid_vars);
1197 break;
1198 case eParentParam:
1199 // ...one of the function's parameters.
1200 var = SelectParentParam(access, cg_context, type, qfer, mt, invalid_vars);
1201 break;
1202 case eNewValue:
1203 // Must decide where to put the new variable (global or parent
1204 // local)?
1205 var = GenerateNewVariable(access, cg_context, type, qfer);
1206 if (CGOptions::expand_struct())
1207 Error::set_error(ERROR);
1208 break;
1209 case MAX_VAR_SCOPE:
1210 assert (0);
1211 }
1212 ERROR_GUARD(NULL);
1213 if (var && !cg_context.get_effect_context().is_side_effect_free()) {
1214 assert(!var->is_volatile());
1215 }
1216 // record statistics
1217 if (var) {
1218 if (var_created) {
1219 const Type* t = var->type;
1220 Bookkeeper::use_new_var_cnt++;
1221 Bookkeeper::record_vars_with_bitfields(t);
1222 incr_counter(Bookkeeper::struct_depth_cnts, t->get_struct_depth());
1223 if (t->eType == eUnion) Bookkeeper::union_var_cnt++;
1224 } else {
1225 Bookkeeper::use_old_var_cnt++;
1226 }
1227 }
1228 return var;

Callers

nothing calls this directly

Calls 5

incr_counterFunction · 0.85
is_side_effect_freeMethod · 0.80
get_struct_depthMethod · 0.80
is_volatileMethod · 0.45

Tested by

no test coverage detected