* */
| 281 | * |
| 282 | */ |
| 283 | FunctionInvocation * |
| 284 | FunctionInvocation::make_random_binary_ptr_comparison(CGContext &cg_context) |
| 285 | { |
| 286 | eBinaryOps op = rnd_flipcoin(50) ? eCmpEq : eCmpNe; |
| 287 | ERROR_GUARD(NULL); |
| 288 | SafeOpFlags *flags = SafeOpFlags::make_random_binary(get_int_type(), NULL, NULL, sOpBinary, op); |
| 289 | ERROR_GUARD(NULL); |
| 290 | |
| 291 | FunctionInvocation *fi = FunctionInvocationBinary::CreateFunctionInvocationBinary(cg_context, op, flags); |
| 292 | const Type* type = Type::choose_random_pointer_type(); |
| 293 | ERROR_GUARD_AND_DEL1(NULL, fi); |
| 294 | |
| 295 | Effect lhs_eff_accum; |
| 296 | CGContext lhs_cg_context(cg_context, cg_context.get_effect_context(), &lhs_eff_accum); |
| 297 | lhs_cg_context.flags |= NO_DANGLING_PTR; |
| 298 | Expression *lhs = Expression::make_random(lhs_cg_context, type, 0, true); |
| 299 | ERROR_GUARD_AND_DEL1(NULL, fi); |
| 300 | cg_context.merge_param_context(lhs_cg_context, true); |
| 301 | |
| 302 | // now focus on RHS ... |
| 303 | enum eTermType tt = MAX_TERM_TYPES; |
| 304 | // if LHS is const, there is no need for RHS to be const as well |
| 305 | if (lhs->term_type == eConstant) { |
| 306 | tt = eVariable; |
| 307 | } |
| 308 | Expression *rhs = 0; |
| 309 | |
| 310 | // If we are guaranteed that the LHS will be evaluated before the RHS, |
| 311 | // or if the LHS is pure (not merely side-effect-free), |
| 312 | // then we can generate the RHS under the original effect context. |
| 313 | if (IsOrderedStandardFunc(op)) { // lhs_eff_accum.is_pure()) JYTODO: purity needs to be redefined |
| 314 | // although we don't need care about other side effect, we do |
| 315 | // need to pass in NO_DANGLING_PTR flag |
| 316 | unsigned int old_flag = cg_context.flags; |
| 317 | cg_context.flags |= NO_DANGLING_PTR; |
| 318 | rhs = Expression::make_random(cg_context, type, 0, true, false, tt); |
| 319 | cg_context.flags = old_flag; |
| 320 | } else { |
| 321 | // Otherwise, the RHS must be generated under the combined effect |
| 322 | // of the original effect and the LHS effect. |
| 323 | Effect rhs_eff_context(cg_context.get_effect_context()); |
| 324 | rhs_eff_context.add_effect(lhs_eff_accum); |
| 325 | Effect rhs_eff_accum; |
| 326 | |
| 327 | CGContext rhs_cg_context(cg_context, rhs_eff_context, &rhs_eff_accum); |
| 328 | rhs_cg_context.flags |= NO_DANGLING_PTR; |
| 329 | rhs = Expression::make_random(rhs_cg_context, type, 0, true, false, tt); |
| 330 | cg_context.merge_param_context(rhs_cg_context, true); |
| 331 | } |
| 332 | ERROR_GUARD_AND_DEL2(NULL, fi, lhs); |
| 333 | |
| 334 | // typecast, if needed. |
| 335 | rhs->check_and_set_cast(&lhs->get_type()); |
| 336 | |
| 337 | // TODO: fix `rhs' for eLShift and eRShift and ... |
| 338 | // Currently, the "fix" is handled in `FunctionInvocationBinary::Output'. |
| 339 | fi->param_value.push_back(lhs); |
| 340 | fi->param_value.push_back(rhs); |
nothing calls this directly
no test coverage detected