[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [creduce-dev] reduction using dynamic information



OK, I pushed a new pass that does pretty much the same as we discussed. The pass has some simple analysis that is able to reduce the number of trivial transformations. For example, given "foo(a+1, a+1)", we only need to insert printf for one of these "a+1".

Furthermore, the pass tries to avoid transformations on the control-code injected by C-Reduce. For example, the pass won't insert printf for "!__creduce_printed_1" that appears in "if (!__creduce_printed_1)". This extra work is actually quite important. Without it, it's almost certain that we would end up repeatedly rewriting the first occurrence of "!__creudce_printed_1", because "--counter=1" would always result in valid transformation.

The examples below demonstrate how to use the pass. In these examples, I pass "1" to the counter, but you can image that any valid counter value would also work.

$ cat foo.c
int foo() {
  int a = 1;
  return a+1;
}

* insert code that prints the value of the candidate expression

$ clang_delta --transformation=expression-detector --counter=1 foo.c
int printf(const char *format, ...);
int foo() {
  int a = 1;
  {
  int __creduce_expr_tmp_1 = a+1;
  static int __creduce_printed_1 = 0;
  if (!__creduce_printed_1) {
    printf("creduce_value(%d)\n", __creduce_expr_tmp_1);
    __creduce_printed_1 = 1;
  }

  return __creduce_expr_tmp_1;
  }
}


* replace the designated expression by a passed value

$ clang_delta --transformation=expression-detector --counter=1 --replacement=123 foo.c
int foo() {
  int a = 1;
  return 123;
}

* insert code that checks if the candidate expression equals to the referenced value

$ clang_delta --transformation=expression-detector --counter=1 --check-reference=123 foo.c
void abort(void);
int foo() {
  int a = 1;
  {
  int __creduce_expr_tmp_1 = a+1;
  static int __creduce_checked_1 = 0;
  if (!__creduce_checked_1) {
    if (__creduce_expr_tmp_1 != 123) abort();
    __creduce_checked_1 = 1;
  }

  return __creduce_expr_tmp_1;
  }
}


I am sure there are bugs in this new pass. I am just hoping there wouldn't be too many.

- Yang