1

I am trying to find any possible path in my program by LLVM. Right now I can find paths from entry to exit BB of all functions in my code. However that's not what I need. What I need is extending CFG (maybe by inlining function calls?!) to have a CFG for entire source code and find paths in this extended CFG. I was thinking of using -inline pass first to inline all functions first and then run my pathfinder pass but as I observed -inline works only for functions which are explicitly mentioned inline in code(cpp file). I can't go through hundreds of functions and add inline to all of them. I also need to guarantee that all calls are inlined and no call is missed. I'm not sure that inlining is my only option or even that is an option. Any thought on this is appreciated.

**obviously there is no recursive call in my source code.

Nhome
  • 303
  • 2
  • 3
  • 12

1 Answers1

-4

Not entirely sure what you are asking, however you could use just about any program language to parse the source.cpp and source.h to find function declaration/definition and add the inline based on some rule.

Basically you will treat the source.cpp as a .txt and use any api of your preference to get the files as a char *. Have it search for ( then search for parameters and a closing ).

// FindFunctions.cpp
#include "..."
...

char * AddFuncDecChars( _In_ char * file, char * stringToBeInserted)
{
    //Find possible functions with `()`.
    int[] PossFuncs = FindParenths(File);
    // Check to see if space delimited block followed by another block or
    // multiple space delimited blocks with commas.
    int[] VerifiedParens HasSpaceDelimWithPossibleCommas( PossFuncs, 
    File);
    char * Change InsertStringToFunc( File, VerifiedParen,
    stringToBeInserted);
    return Change;
} 

Also inline has to have definition in the header not cpp so might have to add that to headers by taking in a .h and .cpp pair.

marshal craft
  • 439
  • 5
  • 18
  • Also apparently Visual studio can optimize across modules. Might be something to consider. – marshal craft May 20 '16 at 05:14
  • OP is looking for a _properly_ parsed solution using [llvm](http://llvm.org/), not a dirty hack that fails to parse plenty of valid C++ function calls. How does your solution attempt deal with, for example, nested function calls, overloaded operators, functions called from ctor initializer lists, …? – mindriot May 20 '16 at 07:39
  • @mindriot I thank you for providing a comment as is recommended upon down casting a answer. The question cleary asks for 'all possible' paths in a c++ program which apparently consists of many modules. Apparently at least according to the OP LLVM doesn't handle this (at least how I interpret the question). I assume the ask-er has tested the methodology with a small program and inlining the functions makes it possible to utilize LLVM to analyze the entire program. – marshal craft May 21 '16 at 04:56
  • Also I intended my code as pseudo c++. For example how you use `file` with out knowing the size? I am not expert with the c++ standard however I do believe using parenthesis will be necessary in parsing for function declarations and definitions in order to add the inline attribute and move definitions to headers. This ISN'T intended to mimic the compiler. All that is needed here is to alter source code and in that alter text files. Due to build environment, we can not make assumptions about much such as parsing for return type or attributes already used, parameter declaration etc. – marshal craft May 21 '16 at 05:09