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

Method make_random_binary

src/SafeOpFlags.cpp:188–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188SafeOpFlags*
189SafeOpFlags::make_random_binary(const Type *rv_type, const Type *op1_type, const Type *op2_type,
190 SafeOpKind op_kind, eBinaryOps bop)
191{
192 DEPTH_GUARD_BY_TYPE_RETURN_WITH_FLAG(dtSafeOpFlags, op_kind, NULL);
193 SafeOpFlags *flags = new SafeOpFlags();
194 assert("new SafeOpFlags fail!");
195 bool rv_is_float = return_float_type(rv_type, op1_type, op2_type, bop);
196
197 // floating point is always signed
198 if (rv_is_float) {
199 if (op_kind == sOpBinary) {
200 assert(FunctionInvocation::BinaryOpWorksForFloat(bop) && "Invalid binary op");
201 }
202 flags->op1_ = true;
203 }
204 else {
205 flags->op1_ = rnd_flipcoin(SafeOpsSignedProb);
206 }
207 ERROR_GUARD_AND_DEL1(NULL, flags);
208
209 if (op_kind == sOpBinary) {
210 if (rv_is_float)
211 flags->op2_ = true;
212 else
213 flags->op2_ = rnd_flipcoin(SafeOpsSignedProb);
214 ERROR_GUARD_AND_DEL1(NULL, flags);
215 }
216 else {
217 flags->op2_ = flags->op1_;
218 }
219
220 // ISSUE: in the old code, is_func is always true
221 // Probably need to be fixed later.
222 flags->is_func_ = true;
223
224 MspSafeOpSizeFilter *filter = new MspSafeOpSizeFilter(bop);
225 Probabilities::register_extra_filter(pSafeOpsSizeProb, filter);
226
227 if (rv_is_float) {
228 assert(CGOptions::enable_float());
229 flags->op_size_ = sFloat;
230 }
231 else {
232 flags->op_size_ = (SafeOpSize)rnd_upto(MAX_SAFE_OP_SIZE-1, SAFE_OPS_SIZE_PROB_FILTER);
233 }
234 Probabilities::unregister_extra_filter(pSafeOpsSizeProb, filter);
235 ERROR_GUARD_AND_DEL2(NULL, flags, filter);
236
237 //Probabilities::unregister_extra_filter(pSafeOpsSizeProb, filter);
238 delete filter;
239 return flags;
240}
241
242SafeOpFlags *
243SafeOpFlags::clone() const

Callers

nothing calls this directly

Calls 2

rnd_flipcoinFunction · 0.85
rnd_uptoFunction · 0.85

Tested by

no test coverage detected