Skip to content

Commit

Permalink
test: Don't double decr vars in fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Dec 16, 2024
1 parent 2eb2d63 commit 3a3f5b9
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 38 deletions.
33 changes: 24 additions & 9 deletions src/main/resources/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ int numSccs = 0;
struct FreeCell *freeList = NULL;

/** For dropping objects that never get assigned anywhere */
void drop(Common *obj, void (*decrRC)(void *)) {
obj->rc ++;
void drop(Common *obj, void (*decrRC)(void *))
{
obj->rc++;
decrRC(obj);
}

Expand Down Expand Up @@ -135,25 +136,39 @@ void collectFreeList()

void processAllPCRs()
{
for (int scc = 0; scc < numSccs; scc ++)
for (int scc = 0; scc < numSccs; scc++)
{
markGrayAllPCRs(pcrBuckets[scc]);
scanAllPCRs(pcrBuckets[scc]);
for (struct PCR *curr = pcrBuckets[scc]; curr != NULL; curr = curr->next)
{
curr->markGray(curr->obj);
}
for (struct PCR *curr = pcrBuckets[scc]; curr != NULL; curr = curr->next)
{
curr->scan(curr->obj);
}
if (freeList != NULL)
{
fprintf(stderr, "Free list should be null\n");
exit(1);
}
collectWhiteAllPCRs(pcrBuckets[scc]);
struct PCR *curr = pcrBuckets[scc];
while (curr != NULL)
{
curr->collectWhite(curr->obj);
struct PCR *next = curr->next;
free(curr);
curr = next;
}
pcrBuckets[scc] = NULL;
collectFreeList();
}
}

// From https://stackoverflow.com/a/14783909/11882002
static inline u_int64_t rdtscp() {
u_int64_t rax,rdx;
static inline u_int64_t rdtscp()
{
u_int64_t rax, rdx;
u_int32_t aux;
asm volatile ( "rdtscp\n" : "=a" (rax), "=d" (rdx), "=c" (aux) : : );
asm volatile("rdtscp\n" : "=a"(rax), "=d"(rdx), "=c"(aux) : :);
return (rdx << 32) + rax;
}
9 changes: 2 additions & 7 deletions src/main/scala/fred/AST.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package fred

case class Span(start: Int, end: Int) {
override def toString =
if (start == -1 && end == -1) "(:)" else s"($start:$end)"
}
case class Span(start: Int, end: Int)

object Span {

/** A dummy span to use for generated code */
def synth = Span(-1, -1)
}

case class Spanned[T](value: T, span: Span) {
override def toString: String = value.toString
}
case class Spanned[T](value: T, span: Span)

case class ParsedFile(typeDefs: List[TypeDef], fns: List[FnDef])

Expand Down
14 changes: 11 additions & 3 deletions src/main/scala/fred/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ object Compiler {
.getResourceAsStream(RuntimeHeader)
val io = ProcessIO(
in => {
in.write(runtimeHeader.readAllBytes())
in.write(generated.getBytes())
// in.write(runtimeHeader.readAllBytes())
// TODO removing #include runtime.h is a horrendous hack
in.write(generated.replaceAll("#include \"runtime.h\"", "").getBytes())
// in.write(generated.replaceAll("#include \"runtime.h\"", "").getBytes())
in.close()
},
out => print(String(out.readAllBytes())),
Expand All @@ -88,9 +89,16 @@ object Compiler {
val extraIncludes =
if (settings.includeMemcheck) "-I /usr/include/valgrind" else ""

assert(s"gcc $extraIncludes -o $outExe -x c -".run(io).exitValue() == 0)
assert(s"gcc -g -I ${includesFolder()} $extraIncludes -o $outExe -x c -".run(io).exitValue() == 0)
File(outExe).setExecutable(true)

runtimeHeader.close()
}

/** Path to the folder with header files to include */
private def includesFolder(): String = {
val runtimeFile = this.getClass().getClassLoader()
.getResource(RuntimeHeader).toURI()
java.nio.file.Paths.get(runtimeFile).getParent().toString()
}
}
Loading

0 comments on commit 3a3f5b9

Please sign in to comment.