spcl / perf-taint

Taint-based program analysis framework for empirical performance modeling.
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Fixing issues with unreachable function #22

Open mcopik opened 4 years ago

mcopik commented 4 years ago

We need to hijack a return from a function to commit results from it. However, there are problems when return from main is rerouted to a different routine, like in MILC:

void normal_exit()
{
  exit(0);
}
int main()
{
  ...
  normal_exit();
}

Running simplifycfg works on MILC, turning the return from main into an unreachable, but not on all examples of the problem.

#include <cmath>
#include <cstdlib>

#include "ExtraPInstrumenter.hpp"

// Reproduces a bug scenario where return from function is unreachable.
// Running `simplify-cfg` pass is necessary to turn return into unreachable
// code and putting loop commit calls correctly before the exit.

void exit_program()
{
  exit(0);
}

int main(int argc, char ** argv)
{
  int x1 EXTRAP = atoi(argv[1]);
  int x2 EXTRAP = 2*atoi(argv[2]);
  register_variable(&x1, VARIABLE_NAME(x1));
  register_variable(&x2, VARIABLE_NAME(x2));

  int sum = 0;
  for(int i = x1; i < x2; i++)
    ++sum;

  exit_program();
  return 0;
}