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

Method make_random

src/Block.cpp:123–200  ·  view source on GitHub ↗

* */

Source from the content-addressed store, hash-verified

121 *
122 */
123Block *
124Block::make_random(CGContext &cg_context, bool looping)
125{
126 //static int bid = 0;
127 DEPTH_GUARD_BY_TYPE_RETURN(dtBlock, NULL);
128
129 Function *curr_func = cg_context.get_current_func();
130 assert(curr_func);
131
132 Block *b = new Block(cg_context.get_current_block(), CGOptions::max_block_size());
133 b->func = curr_func;
134 b->looping = looping;
135 // if there are induction variables, we are in a loop that traverses array(s)
136 b->in_array_loop = !(cg_context.iv_bounds.empty());
137 //b->stm_id = bid++;
138
139 // Push this block onto the variable scope stack.
140 curr_func->stack.push_back(b);
141 curr_func->blocks.push_back(b);
142
143 // record global facts at this moment so that subsequent statement
144 // inside the block doesn't ruin it
145 FactMgr* fm = get_fact_mgr_for_func(curr_func);
146 fm->set_fact_in(b, fm->global_facts);
147 Effect pre_effect = cg_context.get_accum_effect();
148
149 unsigned int max = BlockProbability(*b);
150 if (Error::get_error() != SUCCESS) {
151 curr_func->stack.pop_back();
152 delete b;
153 return NULL;
154 }
155 unsigned int i;
156 if (b->stm_id == 1)
157 BREAK_NOP; // for debugging
158 for (i = 0; i <= max; ++i) {
159 Statement *s = Statement::make_random(cg_context);
160 // In the exhaustive mode, Statement::make_random could return NULL;
161 if (!s)
162 break;
163 b->stms.push_back(s);
164 if (s->must_return()) {
165 break;
166 }
167 }
168
169 if (Error::get_error() != SUCCESS) {
170 curr_func->stack.pop_back();
171 delete b;
172 return NULL;
173 }
174
175 // append nested loop if some must-read/write variables hasn't been accessed
176 if (b->need_nested_loop(cg_context) && cg_context.blk_depth < CGOptions::max_blk_depth()) {
177 b->append_nested_loop(cg_context);
178 }
179
180 // perform DFA analysis after creation

Callers

nothing calls this directly

Calls 10

get_fact_mgr_for_funcFunction · 0.85
BlockProbabilityFunction · 0.85
get_current_funcMethod · 0.80
get_current_blockMethod · 0.80
set_fact_inMethod · 0.80
get_accum_effectMethod · 0.80
need_nested_loopMethod · 0.80
append_nested_loopMethod · 0.80
must_returnMethod · 0.45

Tested by

no test coverage detected