commit 053ef92b0de5f1c375d29e6bd579a7c44bbc80ae
parent a93efed598c6baf3a6b5c00b3efac19d1f2ec710
Author: Eyal Sawady <ecs@d2evs.net>
Date: Mon, 8 Mar 2021 15:10:17 -0500
Fix type assertions to tagged unions
We need to route those through gen_cast_to_tagged, because _from_tagged
treats them as casts rather than selecting the appropriate member.
Diffstat:
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -1218,10 +1218,6 @@ gen_cast_from_tagged(struct gen_context *ctx,
return;
}
- if (type_dealias(to)->storage == STORAGE_TAGGED) {
- assert(0); // TODO
- }
-
const struct type *tagged = expr->cast.value->result;
struct qbe_value object = {0}, offs = {0}, temp = {0};
alloc_temp(ctx, &object, tagged, "from.tagged.%d");
@@ -1267,7 +1263,8 @@ gen_expr_cast(struct gen_context *ctx,
}
const struct type *to = expr->result, *from = expr->cast.value->result;
- if (type_dealias(to)->storage == STORAGE_TAGGED) {
+ if (type_dealias(to)->storage == STORAGE_TAGGED
+ && expr->cast.kind == C_CAST) {
gen_cast_to_tagged(ctx, expr, out, from);
return;
} else if (type_dealias(from)->storage == STORAGE_TAGGED) {
@@ -1275,6 +1272,8 @@ gen_expr_cast(struct gen_context *ctx,
return;
}
+ assert(expr->cast.kind == C_CAST);
+
to = type_dealias(to), from = type_dealias(from);
if (to->storage == from->storage && to->size == from->size) {
gen_expression(ctx, expr->cast.value, out);
@@ -1317,10 +1316,6 @@ gen_expr_cast(struct gen_context *ctx,
}
gen_expression(ctx, expr->cast.value, &in);
- if (expr->cast.kind == C_ASSERTION) {
- gen_type_assertion(ctx, expr, &in);
- }
-
// Used for various casts
enum qbe_instr op;
struct qbe_value ptr = {0}, offs = {0}, len = {0};