Skip to content
Browse files

Zero pointer after deallocate

  • Loading branch information...
1 parent 888f950 commit 9ba8c5537d8a4ed8958e0b72a149523ff205a1a3 @nickg committed Dec 27, 2012
Showing with 36 additions and 11 deletions.
  1. +4 −4 src/cgen.c
  2. +20 −5 src/dump.c
  3. +12 −2 test/regress/access1.vhd
View
8 src/cgen.c
@@ -933,7 +933,7 @@ static void cgen_call_args(tree_t t, LLVMValueRef *args, cgen_ctx_t *ctx)
// If this is a scalar out or inout parameter then we need
// to pass a pointer rather than the value
- if (builtin == NULL) {
+ if ((builtin == NULL) || (i < tree_ports(decl))) {
tree_t port = tree_port(decl, i);
port_mode_t mode = tree_port_mode(port);
bool need_ptr = ((mode == PORT_OUT || mode == PORT_INOUT)
@@ -2474,9 +2474,9 @@ static void cgen_case(tree_t t, cgen_ctx_t *ctx)
static void cgen_builtin_pcall(ident_t builtin, LLVMValueRef *args)
{
if (icmp(builtin, "deallocate")) {
- LLVMBuildFree(builder, args[0]);
- // XXX: setting pointer to NULL broken until inout parameters work
- //LLVMBuildStore(builder, LLVMConstNull(LLVMTypeOf(args[0])), args[0]);
+ LLVMValueRef ptr = LLVMBuildLoad(builder, args[0], "");
+ LLVMBuildFree(builder, ptr);
+ LLVMBuildStore(builder, LLVMConstNull(LLVMTypeOf(ptr)), args[0]);
}
else
fatal("cannot generate code for builtin %s", istr(builtin));
View
25 src/dump.c
@@ -81,11 +81,8 @@ static void dump_expr(tree_t t)
{
switch (tree_kind(t)) {
case T_FCALL:
- {
- const char *name = istr(tree_ident(tree_ref(t)));
- printf("%s", name);
- dump_params(t);
- }
+ printf("%s", istr(tree_ident(tree_ref(t))));
+ dump_params(t);
break;
case T_LITERAL:
@@ -95,12 +92,25 @@ static void dump_expr(tree_t t)
case L_INT:
printf("%"PRIi64, l.i);
break;
+ case L_NULL:
+ printf("null");
+ break;
default:
assert(false);
}
}
break;
+ case T_NEW:
+ printf("new ");
+ dump_expr(tree_value(t));
+ break;
+
+ case T_ALL:
+ dump_expr(tree_value(t));
+ printf(".all");
+ break;
+
case T_AGGREGATE:
printf("(");
for (unsigned i = 0; i < tree_assocs(t); i++) {
@@ -489,6 +499,11 @@ static void dump_stmt(tree_t t, int indent)
printf("end for");
break;
+ case T_PCALL:
+ printf("%s", istr(tree_ident(tree_ref(t))));
+ dump_params(t);
+ break;
+
default:
cannot_dump(t, "stmt");
}
View
14 test/regress/access1.vhd
@@ -30,6 +30,16 @@ architecture test of access1 is
end if;
end procedure;
+ procedure list_free(l : inout list_ptr) is
+ variable tmp : list_ptr;
+ begin
+ while l /= null loop
+ tmp := l.all.link;
+ deallocate(l);
+ l := tmp;
+ end loop;
+ end procedure;
+
signal p1_done : boolean := false;
begin
@@ -46,7 +56,7 @@ begin
q.all := 6;
assert p.all = 6;
deallocate(p);
- --assert p = null;
+ assert p = null;
p1_done <= true;
wait;
end process;
@@ -61,7 +71,7 @@ begin
end loop;
list_print(l);
- --list_free(l);
+ list_free(l);
wait;
end process;

0 comments on commit 9ba8c55

Please sign in to comment.
Something went wrong with that request. Please try again.