Пример #1
0
bool llvm::slicing::handleCall(Function &F, FunctionStaticSlicer &ss,
		const CallInst *CI) {

  const char *ass_file = getenv("SLICE_ASSERT_FILE");
  const char *ass_line = getenv("SLICE_ASSERT_LINE");
  const ConstantExpr *fileArg = dyn_cast<ConstantExpr>(CI->getArgOperand(1));
  //const ConstantInt *lineArg = dyn_cast<ConstantInt>(CI->getArgOperand(2));
  const ConstantInt *lineArg = dyn_cast<ConstantInt>(CI->getArgOperand(1));

  if (ass_file && ass_line) {
    if (fileArg && fileArg->getOpcode() == Instruction::GetElementPtr &&
	lineArg) {
      const GlobalVariable *strVar =
	dyn_cast<GlobalVariable>(fileArg->getOperand(0));
      assert(strVar && strVar->hasInitializer());
      const ConstantDataArray *str =
	dyn_cast<ConstantDataArray>(strVar->getInitializer());
      assert(str && str->isCString());
      /* trim the NUL terminator */
      StringRef fileArgStr = str->getAsString().drop_back(1);
      const int ass_line_int = atoi(ass_line);

      errs() << "ASSERT at " << fileArgStr << ":" << lineArg->getValue() << "\n";

      if (fileArgStr.equals(ass_file) && lineArg->equalsInt(ass_line_int)) {
	errs() << "\tMATCH\n";
	goto count;
      }
    }
    ss.addSkipAssert(CI);
    return false;
  }

count:
#ifdef DEBUG_INITCRIT
        errs() << "    adding\n";
#endif
  ss.addInitialCriterion(CI,
      Pointee(F.getParent()->getGlobalVariable("__ai_init_functions", true), -1));
  // Add all the arguments of the call instruction
  for( int i = 0; i< CI->getNumArgOperands(); i++){
    ss.addInitialCriterion(CI, Pointee(CI->getArgOperand(i), -1));
  }
  return true;
}
Пример #2
0
static bool handleAssert(Function &F, FunctionStaticSlicer &ss,
    const CallInst *CI) {

  const char *ass_file = getenv("SLICE_ASSERT_FILE");
  const char *ass_line = getenv("SLICE_ASSERT_LINE");
  const ConstantExpr *fileArg = dyn_cast<ConstantExpr>(CI->getArgOperand(1));
  const ConstantInt *lineArg = dyn_cast<ConstantInt>(CI->getArgOperand(2));

  if (ass_file && ass_line) {
    if (fileArg && fileArg->getOpcode() == Instruction::GetElementPtr &&
        lineArg) {
      const GlobalVariable *strVar =
        dyn_cast<GlobalVariable>(fileArg->getOperand(0));
      assert(strVar && strVar->hasInitializer());
      const ConstantArray *str =
        dyn_cast<ConstantArray>(strVar->getInitializer());
      assert(str && str->isCString());
      /* trim the NUL terminator */
      StringRef tmpStr(str->getAsString());
      StringRef fileArgStr = tmpStr.substr(0,tmpStr.size() - 1);
      const int ass_line_int = atoi(ass_line);

      errs() << "ASSERT at " << fileArgStr << ":" << lineArg->getValue() << "\n";

      if (fileArgStr.equals(ass_file) && lineArg->equalsInt(ass_line_int)) {
        errs() << "\tMATCH\n";
        goto count;
      }
    }
    ss.addSkipAssert(CI);
    return false;
  }

count:
#ifdef DEBUG_INITCRIT
  errs() << "    adding\n";
#endif
  ss.addInitialCriterion(CI,
      F.getParent()->getGlobalVariable("__ai_init_functions", true));
  return true;
}