kaist-cp / cs420

KAIST CS420: Compiler Design (2023 Spring)
418 stars 27 forks source link

[Homework 2] The current reduce criteria lead to nonterminating programs #102

Closed Medowhill closed 4 years ago

Medowhill commented 4 years ago

Hi.

According to the C-Reduce document, it seems that exit code 0 means a reduced program is desirable.

Next we need an interestingness test: a program that returns 0 if a partially-reduced test case is desirable, and returns non-zero otherwise.

After the latest update, cargo run --bin fuzz exits with 102 when GCC fails or the created binary runs forever.

However, the current reduce criteria use the following to determine the exit code:

 ! cargo run --manifest-path $PROJECT_DIR/Cargo.toml --release --bin fuzz -- $FUZZ_ARG test_reduced.c

Therefore, when cargo run --bin fuzz exits with 102, a reduced program is considered as a desirable one. Actually, I got the following after reducing:

int main() {
  for (;;)
    ;
}

I believe that the following fix can resolve this issue:

--- a/tests/reduce-criteria-template.sh
+++ b/tests/reduce-criteria-template.sh
@@ -49,10 +50,16 @@ if
   grep 'excess elements in struct initializer' outa.txt ||\
   grep 'comparison between pointer and integer' outa.txt ||\
   ! gcc -O1 test_reduced.c > cc_out1.txt 2>&1 ||\
-  ! gcc -O2 test_reduced.c > cc_out2.txt 2>&1)
+  ! gcc -O2 test_reduced.c > cc_out2.txt 2>&1 ||\
+  ! cargo run --manifest-path $PROJECT_DIR/Cargo.toml --release -- --parse test_reduced.c >/dev/null 2>&1)
 then
   exit 1
 fi

-cargo run --manifest-path $PROJECT_DIR/Cargo.toml --release -- --parse test_reduced.c >/dev/null 2>&1 &&\
-! cargo run --manifest-path $PROJECT_DIR/Cargo.toml --release --bin fuzz -- $FUZZ_ARG test_reduced.c
+cargo run --manifest-path $PROJECT_DIR/Cargo.toml --release --bin fuzz -- $FUZZ_ARG test_reduced.c
+if [ "$?" = 101 ]
+then
+  exit 0
+else
+  exit 1
+fi

Thank you.

cmpark0126 commented 4 years ago

Great suggestion! I will fix it soon. Thank you :)

Medowhill commented 4 years ago

It has been fixed by the latest commit. Thank you!