Skip to content

Commit

Permalink
fix some memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Jan 23, 2024
1 parent 628a81a commit be900e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/shady/passes/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ OptPass simplify;
bool simplify(SHADY_UNUSED const CompilerConfig* config, Module** m) {
Module* src = *m;

IrArena* a = new_ir_arena(get_arena_config(get_module_arena(*m)));
IrArena* a = get_module_arena(src);
*m = new_module(a, get_module_name(*m));
Context ctx = { .todo = false };
ctx.rewriter = create_rewriter(src, *m, (RewriteNodeFn) process),
Expand All @@ -121,5 +121,5 @@ Module* cleanup(SHADY_UNUSED const CompilerConfig* config, Module* const src) {
todo |= simplify(config, &m);
r++;
} while (todo);
return m;
return import(config, m);
}
13 changes: 7 additions & 6 deletions src/shady/passes/opt_demote_alloca.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ static const Node* process(Context* ctx, const Node* old) {
const Node* otail = get_let_tail(old);
const Node* ninstruction = rewrite_node(r, oinstruction);
AllocaInfo** found_info = find_value_dict(const Node*, AllocaInfo*, ctx->alloca_info, oinstruction);
AllocaInfo* info = NULL;
if (found_info) {
const Node* ovar = first(get_abstraction_params(otail));
insert_dict(const Node*, AllocaInfo*, ctx->alloca_info, ovar, found_info);
info = *found_info;
insert_dict(const Node*, AllocaInfo*, ctx->alloca_info, ovar, info);
}
Nodes oparams = otail->payload.case_.params;
Nodes ntypes = unwrap_multiple_yield_types(r->dst_arena, ninstruction->type);
Expand All @@ -190,8 +192,8 @@ static const Node* process(Context* ctx, const Node* old) {
new_params[i] = var(r->dst_arena, ntypes.nodes[i], oparams.nodes[i]->payload.var.name);
register_processed(r, oparams.nodes[i], new_params[i]);
}
if (found_info)
(*found_info)->bound = new_params[0];
if (info)
info->bound = new_params[0];
const Node* nbody = rewrite_node(r, otail->payload.case_.body);
const Node* tail = case_(r->dst_arena, nodes(r->dst_arena, oparams.count, new_params), nbody);
return let(a, ninstruction, tail);
Expand Down Expand Up @@ -268,14 +270,13 @@ bool compare_node(const Node**, const Node**);

bool opt_demote_alloca(SHADY_UNUSED const CompilerConfig* config, Module** m) {
Module* src = *m;
ArenaConfig aconfig = get_arena_config(get_module_arena(src));
IrArena* a = new_ir_arena(aconfig);
IrArena* a = get_module_arena(src);
Module* dst = new_module(a, get_module_name(src));
Context ctx = {
.rewriter = create_rewriter(src, dst, (RewriteNodeFn) process),
.config = config,
.arena = new_arena(),
.alloca_info = new_dict(const Node, AllocaInfo, (HashFn) hash_node, (CmpFn) compare_node),
.alloca_info = new_dict(const Node*, AllocaInfo*, (HashFn) hash_node, (CmpFn) compare_node),
.todo = false
};
ctx.rewriter.config.rebind_let = true;
Expand Down

0 comments on commit be900e4

Please sign in to comment.