From 9d0332ae309e24d7eaaf154ba030d67132013d26 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 3 Dec 2012 11:38:55 +0900 Subject: [PATCH] Make alaising a def to a larger type an internal error. It really doesn't seem wise to allow the compiler to do so as it would overwrite unrelated defs. The only time such a thing is valid is the return statement (silly vm design), and that's read-only. --- tools/qfcc/include/def.h | 4 +--- tools/qfcc/source/def.c | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/include/def.h b/tools/qfcc/include/def.h index 2637e761f..5ff4b7afd 100644 --- a/tools/qfcc/include/def.h +++ b/tools/qfcc/include/def.h @@ -117,14 +117,12 @@ def_t *new_def (const char *name, struct type_s *type, /** Create a def that aliases another def. Aliasing a def to the same type is useless, but not checked. Aliasing a - def to a type larger than the def's type is a bad idea as another def may - be overwritten via the alias, but is not checked. + def to a type larger than the def's type will generate an internal error. \param def The def to be aliased. \param type The type of the alias. \return The def aliasing \a def. - \todo Check for type size? \todo Make aliasing to the same type a no-op? */ def_t *alias_def (def_t *def, struct type_s *type); diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index 3d16fa020..87d7a0388 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -149,13 +149,14 @@ alias_def (def_t *def, type_t *type) { def_t *alias; - if (def->alias) { expr_t e; e.file = def->file; e.line = def->line; internal_error (&e, "aliasing an alias def"); } + if (type_size (type) > type_size (def->type)) + internal_error (0, "aliasing a def to a larger type"); ALLOC (16384, def_t, defs, alias); alias->return_addr = __builtin_return_address (0); alias->offset = def->offset;