Skip to content

Commit

Permalink
Merge pull request #1142 from utwente-fmt/cast-fixes
Browse files Browse the repository at this point in the history
Fix for #1141
  • Loading branch information
pieter-bos authored Jan 25, 2024
2 parents 3ad6fea + 0bf3c78 commit 91ba3d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/col/vct/col/typerules/CoercionUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ case object CoercionUtils {
case (TNull(), JavaTClass(target, _)) => CoerceNullJavaClass(target)
case (TNull(), TAnyClass()) => CoerceNullAnyClass()
case (TNull(), TPointer(target)) => CoerceNullPointer(target)
case (TNull(), CTPointer(target)) => CoerceNullPointer(target)
case (TNull(), TEnum(target)) => CoerceNullEnum(target)

case (CTArray(_, innerType), TArray(element)) if element == innerType =>
Expand Down
1 change: 1 addition & 0 deletions src/rewrite/vct/rewrite/lang/LangCToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ case class LangCToCol[Pre <: Generation](rw: LangSpecificToCol[Pre]) extends Laz
}
NewPointerArray(rw.dispatch(t1), size)(ArrayMallocFailed(inv))(c.o)
case CCast(CInvocation(CLocal("__vercors_malloc"), _, _, _), _) => throw UnsupportedMalloc(c)
case CCast(n@Null(), t) if t.asPointer.isDefined => rw.dispatch(n)
case _ => throw UnsupportedCast(c)
}

Expand Down
19 changes: 19 additions & 0 deletions test/main/vct/test/integration/examples/CSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,23 @@ class CSpec extends VercorsSpec {
assert(sum[2] == 2);
}
"""

vercors should verify using silicon in "Casting null to pointers" c
"""
#include <stdlib.h>
struct nested {
struct nested *inner;
};
void main() {
int *ip = NULL;
double *dp = NULL;
struct nested *np = NULL;
np = (struct nested*) NULL;
np = (struct nested*) malloc(sizeof(struct nested));
np->inner = NULL;
np->inner = (struct nested*) NULL;
}
"""
}

0 comments on commit 91ba3d0

Please sign in to comment.