Skip to content

Commit

Permalink
frontends: llvm: include function source code end line (#1357)
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <david@adalogics.com>
  • Loading branch information
DavidKorczynski authored Jan 12, 2024
1 parent 8561a29 commit 3966c06
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typedef struct fuzzFuncWrapper {
std::string FunctionSourceFile;
std::string LinkageType;
int FunctionLinenumber;
unsigned int FunctionLinenumberEnd;
size_t FunctionDepth;
std::string ReturnType;
size_t ArgCount;
Expand Down Expand Up @@ -151,6 +152,7 @@ template <> struct yaml::MappingTraits<FuzzerFunctionWrapper> {
io.mapRequired("functionSourceFile", Func.FunctionSourceFile);
io.mapRequired("linkageType", Func.LinkageType);
io.mapRequired("functionLinenumber", Func.FunctionLinenumber);
io.mapRequired("functionLinenumberEnd", Func.FunctionLinenumberEnd);
io.mapRequired("functionDepth", Func.FunctionDepth);
io.mapRequired("returnType", Func.ReturnType);
io.mapRequired("argCount", Func.ArgCount);
Expand Down Expand Up @@ -276,7 +278,8 @@ struct FuzzIntrospector : public ModulePass {

// FuzzerFunctionList wrapAllFunctions(Module &M);
std::string getFunctionFilename(Function *F);
int getFunctionLinenumber(Function *F);
int getFunctionLinenumberBeginning(Function *F);
unsigned int getFunctionLinenumberEnd(Function *F);
std::string resolveTypeName(Type *t);
Function *value2Func(Value *Val);
bool isFunctionPointerType(Type *type);
Expand Down Expand Up @@ -549,7 +552,7 @@ StringRef FuzzIntrospector::removeDecSuffixFromName(StringRef FuncName) {
return FuncNameBeforeLastPeriod;
}

int FuzzIntrospector::getFunctionLinenumber(Function *F) {
int FuzzIntrospector::getFunctionLinenumberBeginning(Function *F) {
for (auto &I : instructions(*F)) {
const llvm::DebugLoc &DebugInfo = I.getDebugLoc();
if (DebugInfo) {
Expand All @@ -559,6 +562,20 @@ int FuzzIntrospector::getFunctionLinenumber(Function *F) {
return -1;
}

unsigned int FuzzIntrospector::getFunctionLinenumberEnd(Function *F) {
unsigned int MaxLineNumber = 0;

for (auto &I : instructions(*F)) {
const llvm::DebugLoc &DebugInfo = I.getDebugLoc();
if (DebugInfo) {
if (DebugInfo.getLine() > MaxLineNumber) {
MaxLineNumber = DebugInfo.getLine();
}
}
}
return MaxLineNumber;
}

// Return the path as a string to the file in which
// the function is implemented.
std::string FuzzIntrospector::getFunctionFilename(Function *F) {
Expand Down Expand Up @@ -1014,7 +1031,8 @@ FuzzerFunctionWrapper FuzzIntrospector::wrapFunction(Function *F) {

FuncWrap.FunctionName = removeDecSuffixFromName(F->getName());
FuncWrap.FunctionSourceFile = getFunctionFilename(F);
FuncWrap.FunctionLinenumber = getFunctionLinenumber(F);
FuncWrap.FunctionLinenumber = getFunctionLinenumberBeginning(F);
FuncWrap.FunctionLinenumberEnd = getFunctionLinenumberEnd(F);
FuncWrap.FunctionUses = 0;
for (User *U : F->users()) {
if (Instruction *Inst = dyn_cast<Instruction>(U)) {
Expand Down

0 comments on commit 3966c06

Please sign in to comment.