From 4ce39e4fc1de9536de7dedfe91b6dee38dec76ae Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 1 Oct 2026 01:04:30 +0200 Subject: WIP sym + cgen --- src/prc1/tmp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/prc1/tmp.c') diff --git a/src/prc1/tmp.c b/src/prc1/tmp.c index a08716b..96b2208 100644 --- a/src/prc1/tmp.c +++ b/src/prc1/tmp.c @@ -4,12 +4,13 @@ #include #include #include +#include const struct stentry *tmp_create(struct fn *fn, const struct type *t) { - static const char fmt[] = "__tmp%zu"; + static const char fmt[] = "__tmp%zu", path[] = "(temporary)"; int r = snprintf(NULL, 0, fmt, fn->ntmps); - char *s = NULL, *tname = NULL; + char *s = NULL, *tname = NULL, *pathdup = NULL; struct tmp *tmp; if (!(tname = type_name(t))) @@ -19,13 +20,15 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t) fprintf(stderr, "%s: snprintf(3) failed\n", __func__); goto failure; } - else if (!(s = malloc(r + 1))) + else if (!(s = malloc(r + 1)) + || !(pathdup = malloc(strlen(path) + 1))) { perror("malloc(3)"); goto failure; } snprintf(s, r + 1, fmt, fn->ntmps++); + strcpy(pathdup, path); if (!(tmp = malloc(sizeof *tmp))) { @@ -39,7 +42,7 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t) { .type = ID, .s = s, - .loc.f = "(temporary)" + .loc.f = pathdup }, .e = @@ -66,5 +69,6 @@ const struct stentry *tmp_create(struct fn *fn, const struct type *t) failure: free(s); free(tname); + free(pathdup); return NULL; } -- cgit v1.2.3