X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=ast.c;h=2b4a456ebb08e5e388d79bbe9a910d49c51d1a9e;hb=7a5bb207782c890852cdb00b731fda29ad0ce45b;hp=6e14bbc2184c8d8e7805495773b997c17d8aba0f;hpb=29db4a44edb5cce12197ae1e25129d38f70e0225;p=xonotic%2Fgmqcc.git diff --git a/ast.c b/ast.c index 6e14bbc..2b4a456 100644 --- a/ast.c +++ b/ast.c @@ -724,9 +724,12 @@ ast_ternary* ast_ternary_new(lex_ctx ctx, ast_expression *cond, ast_expression * void ast_ternary_delete(ast_ternary *self) { - ast_unref(self->cond); - ast_unref(self->on_true); - ast_unref(self->on_false); + /* the if()s are only there because computed-gotos can set them + * to NULL + */ + if (self->cond) ast_unref(self->cond); + if (self->on_true) ast_unref(self->on_true); + if (self->on_false) ast_unref(self->on_false); ast_expression_delete((ast_expression*)self); mem_d(self); } @@ -826,14 +829,17 @@ void ast_switch_delete(ast_switch *self) mem_d(self); } -ast_label* ast_label_new(lex_ctx ctx, const char *name) +ast_label* ast_label_new(lex_ctx ctx, const char *name, bool undefined) { ast_instantiate(ast_label, ctx, ast_label_delete); ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen); - self->name = util_strdup(name); - self->irblock = NULL; - self->gotos = NULL; + self->expression.vtype = TYPE_NOEXPR; + + self->name = util_strdup(name); + self->irblock = NULL; + self->gotos = NULL; + self->undefined = undefined; return self; } @@ -2868,6 +2874,11 @@ bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_valu size_t i; ir_value *dummy; + if (self->undefined) { + compile_error(ast_ctx(self), "internal error: ast_label never defined"); + return false; + } + *out = NULL; if (lvalue) { compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");