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

Method make_random_array_loop

src/StatementFor.cpp:295–329  ·  view source on GitHub ↗

generate loop traversing array(s) */

Source from the content-addressed store, hash-verified

293
294/* generate loop traversing array(s) */
295StatementFor *
296StatementFor::make_random_array_loop(const CGContext &cg_context)
297{
298 // select the number of arrays to manipulate, default maximum = 4;
299 unsigned int aryno = rnd_upto(CGOptions::max_array_num_in_loop());
300 // choose arrays to manipulate, create new ones if necessary
301 VariableSet must_reads, must_writes;
302 for (size_t i=0; i<aryno; i++) {
303 const ArrayVariable* av = VariableSelector::select_array(cg_context);
304 // random access choice: 0 = must read, 1 = must write, 2 = both
305 int access = rnd_upto(3);
306 if (access == 0 || access == 2) {
307 add_variable_to_set(must_reads, (const Variable*)av);
308 }
309 if (access == 1 || access == 2) {
310 add_variable_to_set(must_writes, (const Variable*)av);
311 }
312 }
313 // create read/write directive from existing context and incoming directives
314 VariableSet all_must_reads, all_must_writes, no_reads, no_writes;
315 if (cg_context.rw_directive) {
316 combine_variable_sets(cg_context.rw_directive->must_read_vars, must_reads, all_must_reads);
317 combine_variable_sets(cg_context.rw_directive->must_write_vars, must_writes, all_must_writes);
318 no_reads = cg_context.rw_directive->no_read_vars;
319 no_writes = cg_context.rw_directive->no_write_vars;
320 } else {
321 all_must_reads = must_reads;
322 all_must_writes = must_writes;
323 }
324 RWDirective rwd(no_reads, no_writes, all_must_reads, all_must_writes);
325 // create CGContext for loop
326 CGContext loop_cg_context(cg_context, &rwd, NULL, 0);
327 StatementFor* sf = make_random(loop_cg_context);
328 return sf;
329}
330
331void
332StatementFor::post_loop_analysis(CGContext& cg_context, vector<const Fact*>& pre_facts, Effect& pre_effect)

Callers

nothing calls this directly

Calls 3

rnd_uptoFunction · 0.85
add_variable_to_setFunction · 0.85
combine_variable_setsFunction · 0.85

Tested by

no test coverage detected