From 0e81cf78f893661f0f64329afc8e2897a152b254 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 5 May 2017 16:21:02 +0100 Subject: [PATCH] Fix crash building IEEE library from non-clean tree #321 --- HISTORY.md | 2 +- src/common.c | 5 +++++ src/common.h | 3 ++- src/eval.c | 2 +- src/lib.c | 9 ++++++++- src/lib.h | 3 ++- src/nvc.c | 6 +++++- 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index fa9e40af..16fdf676 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ ## master -- Nothing yet +- Fix crash when build IEEE library from non-clean tree ## 1.2 - 2017-05-04 - Compile time evaluation now uses vcode diff --git a/src/common.c b/src/common.c index 11ffa270..8edce973 100644 --- a/src/common.c +++ b/src/common.c @@ -799,6 +799,11 @@ void loc_read(loc_t *loc, fbuf_t *f, ident_rd_ctx_t ctx) loc->last_column = merged & 0xfff; } +char *vcode_file_name(ident_t unit_name) +{ + return xasprintf("_%s.vcode", istr(unit_name)); +} + void intern_strings(void) { builtin_i = ident_new("builtin"); diff --git a/src/common.h b/src/common.h index 351509a7..62ce1d56 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2013-2016 Nick Gasson +// Copyright (C) 2013-2017 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -56,6 +56,7 @@ int64_t rebase_index(type_t array_type, int dim, int64_t value); bool loc_eq(const loc_t *a, const loc_t *b); void loc_write(const loc_t *loc, fbuf_t *f, ident_wr_ctx_t ctx); void loc_read(loc_t *loc, fbuf_t *f, ident_rd_ctx_t ctx); +char *vcode_file_name(ident_t unit_name); const char *fmt_time_r(char *buf, size_t len, uint64_t t); const char *fmt_time(uint64_t t); diff --git a/src/eval.c b/src/eval.c index f3683a22..916d47fe 100644 --- a/src/eval.c +++ b/src/eval.c @@ -105,7 +105,7 @@ static void eval_load_vcode(lib_t lib, tree_t unit, eval_flags_t flags) if (flags & EVAL_VERBOSE) notef("loading vcode for %s", istr(unit_name)); - char *name LOCAL = xasprintf("_%s.vcode", istr(unit_name)); + char *name LOCAL = vcode_file_name(unit_name); fbuf_t *f = lib_fbuf_open(lib, name, FBUF_IN); if (f == NULL) { if (flags & EVAL_WARN) diff --git a/src/lib.c b/src/lib.c index 8c5019da..58913794 100644 --- a/src/lib.c +++ b/src/lib.c @@ -1,5 +1,5 @@ // -// Copyright (C) 2011-2015 Nick Gasson +// Copyright (C) 2011-2017 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -787,3 +787,10 @@ void lib_mkdir(lib_t lib, const char *name) && (errno != EEXIST)) fatal_errno("mkdir: %s", name); } + +void lib_delete(lib_t lib, const char *name) +{ + assert(lib != NULL); + if (remove(lib_file_path(lib, name)) != 0 && errno != ENOENT) + fatal_errno("remove: %s", name); +} diff --git a/src/lib.h b/src/lib.h index 629bbec1..f14c80ab 100644 --- a/src/lib.h +++ b/src/lib.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2011-2016 Nick Gasson +// Copyright (C) 2011-2017 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -46,6 +46,7 @@ const char *lib_enum_search_paths(void **token); void lib_add_search_path(const char *path); bool lib_stat(lib_t lib, const char *name, lib_mtime_t *mt); void lib_add_map(const char *name, const char *path); +void lib_delete(lib_t lib, const char *name); lib_t lib_work(void); void lib_set_work(lib_t lib); diff --git a/src/nvc.c b/src/nvc.c index 79b4c16d..931d834e 100644 --- a/src/nvc.c +++ b/src/nvc.c @@ -161,6 +161,10 @@ static int analyse(int argc, char **argv) } for (int i = 0; i < n_units; i++) { + // Delete any stale vcode to prevent problems in constant folding + char *vcode LOCAL = vcode_file_name(tree_ident(units[i])); + lib_delete(lib_work(), vcode); + simplify(units[i], 0); bounds_check(units[i]); } @@ -176,7 +180,7 @@ static int analyse(int argc, char **argv) || (kind == T_PACKAGE && pack_needs_cgen(units[i])); if (need_cgen) { vcode_unit_t vu = lower_unit(units[i]); - char *name LOCAL = xasprintf("_%s.vcode", istr(tree_ident(units[i]))); + char *name LOCAL = vcode_file_name(tree_ident(units[i])); fbuf_t *fbuf = lib_fbuf_open(lib_work(), name, FBUF_OUT); vcode_write(vu, fbuf); fbuf_close(fbuf); -- 2.39.2