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

Method SelectParentLocal

src/VariableSelector.cpp:965–1023  ·  view source on GitHub ↗

--------------------------------------------------------------

Source from the content-addressed store, hash-verified

963
964// --------------------------------------------------------------
965Variable *
966VariableSelector::SelectParentLocal(Effect::Access access,
967 const CGContext &cg_context,
968 const Type* type,
969 const CVQualifiers* qfer,
970 eMatchType mt,
971 const vector<const Variable*>& invalid_vars)
972{
973 DEPTH_GUARD_BY_TYPE_RETURN(dtSelectParentLocal, NULL);
974 // Select from the local variables of the parent OR any of its block stack.
975 Function& parent = *cg_context.get_current_func();
976 if (parent.stack.empty()) {
977 // We're choosing a local from a function whose body hasn't been built.
978 // This should never happen.
979 assert(!parent.stack.empty());
980 return 0;
981 }
982
983 unsigned int index = rnd_upto(parent.stack.size());
984 ERROR_GUARD(NULL);
985 Block *block = parent.stack[index];
986
987 // Should be "generate new block local"...
988 const Type *t = NULL;
989 if (block->local_vars.empty()) {
990 if (CGOptions::expand_struct()) {
991 Variable *var = VariableSelector::eager_create_local_struct(*block, access, cg_context, type, qfer, mt, invalid_vars);
992 ERROR_GUARD(NULL);
993 if (var)
994 return var;
995 }
996 const Type* t = Type::random_type_from_type(type, true, false);
997 ERROR_GUARD(NULL);
998 return GenerateNewParentLocal(*block, access, cg_context, t, qfer);
999 }
1000
1001 if (type && type->eType == eSimple && (type->simple_type != eVoid)) {
1002 t = get_int_type();
1003 }
1004 else {
1005 t = Type::random_type_from_type(type, true, false);
1006 ERROR_GUARD(NULL);
1007 }
1008
1009 Variable* var = choose_var(block->local_vars, access, cg_context, t, qfer, mt, invalid_vars);
1010 ERROR_GUARD(NULL);
1011 if (var == 0) {
1012#if 0
1013 if (CGOptions::expand_struct()) {
1014 var = VariableSelector::eager_create_local_struct(*block, access, cg_context, type, qfer, mt, invalid_vars);
1015 ERROR_GUARD(NULL);
1016 if (var)
1017 return var;
1018 }
1019#endif
1020 var = GenerateNewParentLocal(*block, access, cg_context, t, qfer);
1021 }
1022 return var;

Callers

nothing calls this directly

Calls 4

rnd_uptoFunction · 0.85
get_int_typeFunction · 0.85
get_current_funcMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected