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

Method is_eligible_var

src/VariableSelector.cpp:235–299  ·  view source on GitHub ↗

* check if a variable is eligible to be selected based on current context and * read/write + volatile + const rules */

Source from the content-addressed store, hash-verified

233 * read/write + volatile + const rules
234 */
235bool
236VariableSelector::is_eligible_var(const Variable* var, int deref_level, Effect::Access access, const CGContext& cg_context)
237{
238 const Variable* coll = var->get_collective();
239 FactMgr* fm = get_fact_mgr(&cg_context);
240 if (coll != var) {
241 CGContext cg_tmp(cg_context);
242 if (!cg_tmp.read_indices(var, fm->global_facts)) {
243 return false;
244 }
245 var = coll;
246 }
247 const Effect &effect_context = cg_context.get_effect_context();
248 bool is_const = var->is_const_after_deref(deref_level);
249 bool is_volatile = var->is_volatile_after_deref(deref_level) || var->is_volatile();
250
251 // ISSUE: generating "strictly conforming" programs.
252 //
253 // We cannot read or write a volatile if the current effect context
254 // already has a side-effect.
255 //
256 // TODO: is this too strong for what we want? Need a cmd-line option?
257 if (is_volatile && !effect_context.is_side_effect_free()) {
258 return false;
259 }
260 // ISSUE: generating "strictly conforming" programs.
261 //
262 // We can neither read nor write a variable that is being written in
263 // the current effect context.
264 if (((access == Effect::READ) || (access == Effect::WRITE))
265 && (effect_context.is_written_partially(var))) {
266 return false;
267 }
268 // ISSUE: generating "strictly conforming" programs.
269 //
270 // We cannot write a variable that is being read in the current effect context.
271 // JYTODO: this is too restrictive, with dereference, var is not the variable
272 // being written, but the pointed variable. Nevertheless, we excluded var here
273 if ((access == Effect::WRITE && deref_level==0) && effect_context.is_read_partially(var)) {
274 return false;
275 }
276 // ISSUE: generating correct C programs.
277 //
278 // We cannot write `const' variables.
279 if ((access == Effect::WRITE) && is_const) {
280 return false;
281 }
282 // ISSUE: generating "interesting" C programs.
283 //
284 // We cannot read a variable if the current code-generation context
285 // says that we should not.
286 if ((access == Effect::READ) &&
287 (cg_context.is_nonreadable(var) ||
288 (FactUnion::is_nonreadable_field(var, fm->global_facts)))) {
289 return false;
290 }
291 // ISSUE: generating "interesting" C programs.
292 //

Callers

nothing calls this directly

Calls 11

get_fact_mgrFunction · 0.85
read_indicesMethod · 0.80
is_side_effect_freeMethod · 0.80
is_written_partiallyMethod · 0.80
is_read_partiallyMethod · 0.80
is_nonreadableMethod · 0.80
is_nonwritableMethod · 0.80
get_collectiveMethod · 0.45
is_const_after_derefMethod · 0.45
is_volatileMethod · 0.45

Tested by

no test coverage detected