MCPcopy Create free account
hub / github.com/Samsung/UTopia / genFuzzVarAssign

Method genFuzzVarAssign

lib/generation/ProtobufMutator.cpp:76–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76std::string ProtobufMutator::genFuzzVarAssign(FuzzInput &FuzzingInput) {
77 std::string Code;
78 // Use intermediate LocalVar for handling pointers
79 auto LocalVarName = FuzzingInput.getProtoVarName();
80 auto FuzzVarName = FuzzingInput.getFuzzVarName();
81 const auto *MutationType = FuzzingInput.getFTGType().getRealType();
82
83 assert(MutationType && "Unexpected Program State");
84
85 // LocalVar declaration
86 Code += SrcGenerator::genDeclStmt(*MutationType, LocalVarName);
87
88 // Copy mutation result to LocalVar
89 if (MutationType->isPointerType()) {
90 Code += copyMutationPointerType(*MutationType, FuzzingInput);
91 } else if (MutationType->isEnumType()) {
92 Code += copyMutationEnumType(*MutationType, FuzzingInput);
93 } else if (MutationType->isPrimitiveType()) {
94 Code += copyMutationPrimitiveType(*MutationType, FuzzingInput);
95 } else {
96 assert(false && "Unsupported mutation type");
97 }
98
99 // Copy LocalVar to FuzzVar
100 auto &FuzzVarType = FuzzingInput.getFTGType();
101 if (&FuzzVarType == MutationType) {
102 Code += SrcGenerator::genAssignStmt(FuzzVarName, LocalVarName);
103 } else { // FuzzVar is pointer type
104 auto PtrVarName = LocalVarName;
105 auto TypeStr = SrcGenerator::genTypeStr(*MutationType);
106 const auto *TypePtr = &FuzzVarType;
107 while (MutationType != TypePtr) {
108 Code += SrcGenerator::genAssignStmt(TypeStr + "* " + PtrVarName + "p",
109 "&" + PtrVarName);
110 TypePtr = TypePtr->getPointeeType();
111 PtrVarName += "p";
112 TypeStr += "*";
113 }
114 Code += SrcGenerator::genAssignStmt(FuzzVarName, PtrVarName);
115 }
116 return Code;
117}
118
119std::string ProtobufMutator::copyMutationPointerType(const Type &MutationType,
120 const FuzzInput &Input) {

Callers

nothing calls this directly

Calls 7

getProtoVarNameMethod · 0.80
getFuzzVarNameMethod · 0.80
getRealTypeMethod · 0.80
isPointerTypeMethod · 0.80
isEnumTypeMethod · 0.80
isPrimitiveTypeMethod · 0.80
getPointeeTypeMethod · 0.80

Tested by

no test coverage detected