commit fcccb4783b405a27d6073534e181cb77efd4d477
parent ca57b304fd16a00b5ccf4fb7a703fc4d6eb0296b
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 3 Jan 2021 10:26:02 -0500
gen: allocate string for cast
Diffstat:
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/rt/abort.ha b/rt/abort.ha
@@ -1,9 +1,11 @@
export @noreturn @symbol("rt.abort") fn _abort(msg: str) void = {
- const prefix = "Abort: ", newline = "\n";
- // XXX: This causes const to fall off, we should catch that (may need
- // spec update)
+ // XXX: these implicit casts call const to fall off because const types
+ // are assignable from non-const types. This should not transit pointer
+ // secondaries. Write should be updated to *const void, but not before
+ // the compiler catches the error.
+ const prefix = "Abort: ";
write(2, prefix: *const char, len(prefix));
write(2, msg: *const char, len(msg));
- write(2, newline: *const char, 1z);
+ write(2, "\n": *const char, 1z);
kill(getpid(), SIGABRT);
};
diff --git a/src/gen.c b/src/gen.c
@@ -596,9 +596,10 @@ gen_expr_cast(struct gen_context *ctx,
if (to->storage == TYPE_STORAGE_POINTER
&& to->pointer.referent->storage == TYPE_STORAGE_CHAR
&& from->storage == TYPE_STORAGE_STRING) {
- gen_temp(ctx, &in, &qbe_long, "cast.in.%d");
- qval_address(&in);
+ alloc_temp(ctx, &in, from, "cast.in.%d");
+ in.indirect = false;
gen_expression(ctx, expr->cast.value, &in);
+ in.type = &qbe_long;
qval_deref(&in);
gen_load(ctx, &result, &in, false);
gen_store(ctx, out, &result);