Skip to content

Commit

Permalink
Insert valgrind checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Dec 3, 2024
1 parent 43ae6dc commit 28b309a
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 53 deletions.
263 changes: 228 additions & 35 deletions broken.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "memcheck.h"
#include "runtime.h"

enum OptT0_kind { SomeT0_tag, NoneT0_tag };
Expand All @@ -19,7 +20,11 @@ struct T0 {
int addedPCR;
enum T0_kind kind;
void (*print)();
struct OptT0* f1;
struct OptT0* f3;
struct OptT0* f0;
struct OptT0* f4;
struct OptT0* f2;
union {
struct { };
};
Expand All @@ -40,7 +45,7 @@ void $print_OptT0(struct OptT0* this);
void $print_T0(struct T0* this);
struct OptT0* new$SomeT0(struct T0* value);
struct OptT0* new$NoneT0();
struct T0* new$T0(struct OptT0* f0);
struct T0* new$T0(struct OptT0* f0, struct OptT0* f1, struct OptT0* f2, struct OptT0* f3, struct OptT0* f4);
int main();
void $free_OptT0(struct OptT0* this) {
fprintf(stderr, "Freeing OptT0\n");
Expand Down Expand Up @@ -86,7 +91,11 @@ void $decr_T0(struct T0* this) {
if (--this->rc == 0) {
switch (this->kind) {
case T0_tag:
$decr_OptT0(this->f1);
$decr_OptT0(this->f3);
$decr_OptT0(this->f0);
$decr_OptT0(this->f4);
$decr_OptT0(this->f2);
break;
}
removePCR((void *) this, 0);
Expand Down Expand Up @@ -117,8 +126,16 @@ void $markGray_T0(struct T0* this) {
this->color = kGray;
switch (this->kind) {
case T0_tag:
this->f1->rc --;
$markGray_OptT0(this->f1);
this->f3->rc --;
$markGray_OptT0(this->f3);
this->f0->rc --;
$markGray_OptT0(this->f0);
this->f4->rc --;
$markGray_OptT0(this->f4);
this->f2->rc --;
$markGray_OptT0(this->f2);
break;
}
}
Expand Down Expand Up @@ -146,7 +163,11 @@ void $scan_T0(struct T0* this) {
this->color = kWhite;
switch (this->kind) {
case T0_tag:
$scan_OptT0(this->f1);
$scan_OptT0(this->f3);
$scan_OptT0(this->f0);
$scan_OptT0(this->f4);
$scan_OptT0(this->f2);
break;
}
}
Expand All @@ -168,8 +189,16 @@ void $scanBlack_T0(struct T0* this) {
this->color = kBlack;
switch (this->kind) {
case T0_tag:
this->f1->rc ++;
$scanBlack_OptT0(this->f1);
this->f3->rc ++;
$scanBlack_OptT0(this->f3);
this->f0->rc ++;
$scanBlack_OptT0(this->f0);
this->f4->rc ++;
$scanBlack_OptT0(this->f4);
this->f2->rc ++;
$scanBlack_OptT0(this->f2);
break;
}
}
Expand Down Expand Up @@ -197,7 +226,11 @@ void $collectWhite_T0(struct T0* this) {
this->color = kBlack;
switch (this->kind) {
case T0_tag:
$collectWhite_OptT0(this->f1);
$collectWhite_OptT0(this->f3);
$collectWhite_OptT0(this->f0);
$collectWhite_OptT0(this->f4);
$collectWhite_OptT0(this->f2);
break;
}
fprintf(stderr, "Removing T0\n");
Expand Down Expand Up @@ -227,9 +260,21 @@ void $print_T0(struct T0* this) {
switch (this->kind) {
case T0_tag:
printf("T0 {");
printf("f1=");
$print_OptT0(this->f1);
printf(", ");
printf("f3=");
$print_OptT0(this->f3);
printf(", ");
printf("f0=");
$print_OptT0(this->f0);
printf(", ");
printf("f4=");
$print_OptT0(this->f4);
printf(", ");
printf("f2=");
$print_OptT0(this->f2);
printf(", ");
printf("}");
break;
}
Expand All @@ -254,55 +299,203 @@ struct OptT0* new$NoneT0() {
$res->kind = NoneT0_tag;
return $res;
}
struct T0* new$T0(struct OptT0* f0) {
struct T0* new$T0(struct OptT0* f0, struct OptT0* f1, struct OptT0* f2, struct OptT0* f3, struct OptT0* f4) {
struct T0* $res = malloc(sizeof (struct T0));
$res->rc = 0;
$res->color = kBlack;
$res->addedPCR = 0;
$res->print = $print_T0;
$res->kind = T0_tag;
$res->f1 = f1;
$res->f1->rc ++;
$res->f3 = f3;
$res->f3->rc ++;
$res->f0 = f0;
$res->f0->rc ++;
$res->f4 = f4;
$res->f4->rc ++;
$res->f2 = f2;
$res->f2->rc ++;
return $res;
}
int main() {
struct T0* vT0_0 = new$T0(new$NoneT0());
vT0_0->rc ++;
struct T0* vT0_2 = new$T0(new$NoneT0());
vT0_2->rc ++;
struct T0* vT0_1 = new$T0(new$NoneT0());
vT0_1->rc ++;
struct T0* vT0_6 = new$T0(new$NoneT0());
vT0_6->rc ++;
struct T0* vT0_5 = new$T0(new$NoneT0());
struct T0* vT0_5 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_5->rc ++;
struct T0* vT0_3 = new$T0(new$NoneT0());
vT0_3->rc ++;
struct T0* vT0_4 = new$T0(new$NoneT0());
struct T0* vT0_12 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_12->rc ++;
struct T0* vT0_11 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_11->rc ++;
struct T0* vT0_0 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_0->rc ++;
struct T0* vT0_4 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_4->rc ++;
struct OptT0* oldValue$0 = vT0_5->f0;
vT0_5->f0 = new$SomeT0(vT0_6);
vT0_5->f0->rc ++;
struct T0* vT0_3 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_3->rc ++;
struct T0* vT0_7 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_7->rc ++;
struct T0* vT0_9 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_9->rc ++;
struct T0* vT0_6 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_6->rc ++;
struct T0* vT0_10 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_10->rc ++;
struct T0* vT0_8 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_8->rc ++;
struct T0* vT0_1 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_1->rc ++;
struct T0* vT0_2 = new$T0(new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0(), new$NoneT0());
vT0_2->rc ++;
struct OptT0* oldValue$0 = vT0_1->f1;
vT0_1->f1 = new$SomeT0(vT0_8);
vT0_1->f1->rc ++;
$decr_OptT0(oldValue$0);
struct OptT0* oldValue$1 = vT0_0->f0;
vT0_0->f0 = new$SomeT0(vT0_0);
vT0_0->f0->rc ++;
struct OptT0* oldValue$1 = vT0_12->f2;
vT0_12->f2 = new$SomeT0(vT0_12);
vT0_12->f2->rc ++;
$decr_OptT0(oldValue$1);
struct OptT0* oldValue$2 = vT0_3->f0;
vT0_3->f0 = new$SomeT0(vT0_5);
vT0_3->f0->rc ++;
struct OptT0* oldValue$2 = vT0_11->f2;
vT0_11->f2 = new$SomeT0(vT0_3);
vT0_11->f2->rc ++;
$decr_OptT0(oldValue$2);
vT0_3->f0;
vT0_0->f0;
vT0_5->f0;
int ret$3 = 0;
$decr_T0(vT0_4);
$decr_T0(vT0_3);
$decr_T0(vT0_5);
$decr_T0(vT0_6);
$decr_T0(vT0_1);
$decr_T0(vT0_2);
$decr_T0(vT0_0);
struct OptT0* oldValue$3 = vT0_5->f0;
vT0_5->f0 = new$SomeT0(vT0_8);
vT0_5->f0->rc ++;
$decr_OptT0(oldValue$3);
struct OptT0* oldValue$4 = vT0_6->f0;
vT0_6->f0 = new$SomeT0(vT0_8);
vT0_6->f0->rc ++;
$decr_OptT0(oldValue$4);
struct OptT0* oldValue$5 = vT0_9->f2;
vT0_9->f2 = new$SomeT0(vT0_9);
vT0_9->f2->rc ++;
$decr_OptT0(oldValue$5);
struct OptT0* oldValue$6 = vT0_6->f2;
vT0_6->f2 = new$SomeT0(vT0_8);
vT0_6->f2->rc ++;
$decr_OptT0(oldValue$6);
struct OptT0* oldValue$7 = vT0_2->f2;
vT0_2->f2 = new$SomeT0(vT0_0);
vT0_2->f2->rc ++;
$decr_OptT0(oldValue$7);
struct OptT0* oldValue$8 = vT0_0->f1;
vT0_0->f1 = new$SomeT0(vT0_7);
vT0_0->f1->rc ++;
$decr_OptT0(oldValue$8);
struct OptT0* oldValue$9 = vT0_7->f2;
vT0_7->f2 = new$SomeT0(vT0_5);
vT0_7->f2->rc ++;
$decr_OptT0(oldValue$9);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
struct OptT0* oldValue$10 = vT0_8->f1;
vT0_8->f1 = new$SomeT0(vT0_2);
vT0_8->f1->rc ++;
$decr_OptT0(oldValue$10);
struct OptT0* oldValue$11 = vT0_4->f2;
vT0_4->f2 = new$SomeT0(vT0_5);
vT0_4->f2->rc ++;
$decr_OptT0(oldValue$11);
struct OptT0* oldValue$12 = vT0_10->f1;
vT0_10->f1 = new$SomeT0(vT0_11);
vT0_10->f1->rc ++;
$decr_OptT0(oldValue$12);
struct OptT0* oldValue$13 = vT0_12->f1;
vT0_12->f1 = new$SomeT0(vT0_0);
vT0_12->f1->rc ++;
$decr_OptT0(oldValue$13);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
struct OptT0* oldValue$14 = vT0_1->f2;
vT0_1->f2 = new$SomeT0(vT0_10);
vT0_1->f2->rc ++;
$decr_OptT0(oldValue$14);
struct OptT0* oldValue$15 = vT0_4->f1;
vT0_4->f1 = new$SomeT0(vT0_6);
vT0_4->f1->rc ++;
$decr_OptT0(oldValue$15);
struct OptT0* oldValue$16 = vT0_10->f2;
vT0_10->f2 = new$SomeT0(vT0_5);
vT0_10->f2->rc ++;
$decr_OptT0(oldValue$16);
struct OptT0* oldValue$17 = vT0_2->f1;
vT0_2->f1 = new$SomeT0(vT0_12);
vT0_2->f1->rc ++;
$decr_OptT0(oldValue$17);
struct OptT0* oldValue$18 = vT0_12->f0;
vT0_12->f0 = new$SomeT0(vT0_11);
vT0_12->f0->rc ++;
$decr_OptT0(oldValue$18);
struct OptT0* oldValue$19 = vT0_2->f4;
vT0_2->f4 = new$SomeT0(vT0_1);
vT0_2->f4->rc ++;
$decr_OptT0(oldValue$19);
; $decr_T0(vT0_1);
struct OptT0* oldValue$20 = vT0_5->f1;
vT0_5->f1 = new$SomeT0(vT0_7);
vT0_5->f1->rc ++;
$decr_OptT0(oldValue$20);
; $decr_T0(vT0_7);
struct OptT0* oldValue$21 = vT0_0->f4;
vT0_0->f4 = new$SomeT0(vT0_2);
vT0_0->f4->rc ++;
$decr_OptT0(oldValue$21);
struct OptT0* oldValue$22 = vT0_3->f4;
vT0_3->f4 = new$SomeT0(vT0_12);
vT0_3->f4->rc ++;
$decr_OptT0(oldValue$22);
struct OptT0* oldValue$23 = vT0_4->f3;
vT0_4->f3 = new$SomeT0(vT0_12);
vT0_4->f3->rc ++;
$decr_OptT0(oldValue$23);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
struct OptT0* oldValue$24 = vT0_12->f4;
vT0_12->f4 = new$SomeT0(vT0_5);
vT0_12->f4->rc ++;
$decr_OptT0(oldValue$24);
; $decr_T0(vT0_12);
struct OptT0* oldValue$25 = vT0_9->f1;
vT0_9->f1 = new$SomeT0(vT0_11);
vT0_9->f1->rc ++;
$decr_OptT0(oldValue$25);
; $decr_T0(vT0_9);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
; $decr_T0(vT0_11);
struct OptT0* oldValue$26 = vT0_5->f2;
vT0_5->f2 = new$SomeT0(vT0_4);
vT0_5->f2->rc ++;
$decr_OptT0(oldValue$26);
; $decr_T0(vT0_5);
struct OptT0* oldValue$27 = vT0_4->f4;
vT0_4->f4 = new$SomeT0(vT0_6);
vT0_4->f4->rc ++;
$decr_OptT0(oldValue$27);
; $decr_T0(vT0_4);
; $decr_T0(vT0_6);
struct OptT0* oldValue$28 = vT0_3->f1;
vT0_3->f1 = new$SomeT0(vT0_10);
vT0_3->f1->rc ++;
$decr_OptT0(oldValue$28);
; $decr_T0(vT0_10);
struct OptT0* oldValue$29 = vT0_8->f2;
vT0_8->f2 = new$SomeT0(vT0_8);
vT0_8->f2->rc ++;
$decr_OptT0(oldValue$29);
; $decr_T0(vT0_8);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
; $decr_T0(vT0_8);
struct OptT0* oldValue$30 = vT0_0->f2;
vT0_0->f2 = new$SomeT0(vT0_2);
vT0_0->f2->rc ++;
$decr_OptT0(oldValue$30);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
; $decr_T0(vT0_0);
; $decr_T0(vT0_2);
struct OptT0* oldValue$31 = vT0_3->f2;
vT0_3->f2 = new$SomeT0(vT0_3);
vT0_3->f2->rc ++;
$decr_OptT0(oldValue$31);
; $decr_T0(vT0_3);
processAllPCRs(); VALGRIND_DO_LEAK_CHECK;
; $decr_T0(vT0_3);
int ret$32 = 0;
processAllPCRs();
return ret$3;
return ret$32;
}
5 changes: 3 additions & 2 deletions src/main/scala/fred/Translator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ object Translator {
case td: TypeDef if !lhs.isInstanceOf[SetFieldExpr] =>
s"drop((void *) $lhsTranslated, (void *) ${Decrementer.name(td)});"
case _ => lhs match {
case _: SetFieldExpr => ""
case _ => s"$lhsTranslated;"
case _: SetFieldExpr => ""
case call: FnCall if call.fnName.value == "c" => ""
case _ => s"$lhsTranslated;"
}
}
(s"$setup\n$execLhs", rhsTranslated, teardown)
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/snapshot/exec/basic-cycle.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/test/resources/snapshot/exec/contrived-needs-sorting.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/test/resources/snapshot/gen/set-field-sfdu29.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 28b309a

Please sign in to comment.