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

Function make_random_array_control

src/StatementFor.cpp:132–155  ·  view source on GitHub ↗

* Randomly determine the parameters for an array-travering loop */

Source from the content-addressed store, hash-verified

130 * Randomly determine the parameters for an array-travering loop
131 */
132static unsigned int
133make_random_array_control(unsigned int bound, int &init, int &limit, int &incr, eBinaryOps &test_op, eAssignOps &incr_op, bool is_signed)
134{
135 // choose either increment or decrement
136 test_op = is_signed ? (rnd_flipcoin(50) ? eCmpLe : eCmpGe) : eCmpLe;
137 if (test_op == eCmpLe) {
138 // increment, start near index 0
139 init = pure_rnd_flipcoin(50) ? 0 : pure_rnd_upto(bound/2);
140 limit = bound;
141 incr_op = eAddAssign;
142 incr = pure_rnd_flipcoin(50) ? 1 : pure_rnd_upto(bound/4);
143 if (incr == 0) incr = 1;
144 bound = ((bound - init) / incr) * incr + init;
145 } else {
146 // decrement, start near last index
147 init = pure_rnd_flipcoin(50) ? (bound) : (bound - pure_rnd_upto(bound/2));
148 limit = pure_rnd_flipcoin(50) ? 0 : pure_rnd_upto(bound/2);
149 incr_op = eSubAssign;
150 incr = pure_rnd_flipcoin(50) ? 1 : pure_rnd_upto(bound/4);
151 if (incr == 0) incr = 1;
152 bound = init;
153 }
154 return bound;
155}
156
157const Variable*
158StatementFor::make_iteration(CGContext& cg_context, StatementAssign*& init, Expression*& test, StatementAssign*& incr, unsigned int& bound)

Callers 1

make_iterationMethod · 0.85

Calls 3

rnd_flipcoinFunction · 0.85
pure_rnd_flipcoinFunction · 0.85
pure_rnd_uptoFunction · 0.85

Tested by

no test coverage detected