From 6946bc60bfa14c6d48e3a1b655384502e84c591c Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Wed, 21 Oct 1998 09:59:32 +0000 Subject: [PATCH] c-common.c (c_apply_type_quals_to_decl): Don't crash when `restrict' is applied to a non-pointer variable. * c-common.c (c_apply_type_quals_to_decl): Don't crash when `restrict' is applied to a non-pointer variable. From-SVN: r23213 --- gcc/ChangeLog | 5 +++++ gcc/c-common.c | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1d65b6d88c9..9799e65f9c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +Wed Oct 21 09:58:51 1998 Mark Mitchell + + * c-common.c (c_apply_type_quals_to_decl): Don't crash when + `restrict' is applied to a non-pointer variable. + Wed Oct 21 09:18:58 1998 Mark Mitchell * invoke.texi: Document -flang-isoc9x. diff --git a/gcc/c-common.c b/gcc/c-common.c index 4aaeb3c7818..508a8c2e599 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -3037,26 +3037,34 @@ c_apply_type_quals_to_decl (type_quals, decl) TREE_SIDE_EFFECTS (decl) = 1; TREE_THIS_VOLATILE (decl) = 1; } - if ((type_quals & TYPE_QUAL_RESTRICT) && flag_strict_aliasing) + if (type_quals & TYPE_QUAL_RESTRICT) { - /* No two restricted pointers can point at the same thing. - However, a restricted pointer can point at the same thing as - an unrestricted pointer, if that unrestricted pointer is - based on the restricted pointer. So, we make the alias set - for the restricted pointer a subset of the alias set for the - type pointed to by the type of the decl. */ - - int pointed_to_alias_set - = get_alias_set (TREE_TYPE (TREE_TYPE (decl))); - - if (!pointed_to_alias_set) - /* It's not legal to make a subset of alias set zero. */ - ; - else + if (!TREE_TYPE (decl) + || !POINTER_TYPE_P (TREE_TYPE (decl)) + || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl)))) + error ("invalid use of `restrict'"); + else if (flag_strict_aliasing) { - DECL_POINTER_ALIAS_SET (decl) = new_alias_set (); - record_alias_subset (pointed_to_alias_set, - DECL_POINTER_ALIAS_SET (decl)); + /* No two restricted pointers can point at the same thing. + However, a restricted pointer can point at the same thing + as an unrestricted pointer, if that unrestricted pointer + is based on the restricted pointer. So, we make the + alias set for the restricted pointer a subset of the + alias set for the type pointed to by the type of the + decl. */ + + int pointed_to_alias_set + = get_alias_set (TREE_TYPE (TREE_TYPE (decl))); + + if (!pointed_to_alias_set) + /* It's not legal to make a subset of alias set zero. */ + ; + else + { + DECL_POINTER_ALIAS_SET (decl) = new_alias_set (); + record_alias_subset (pointed_to_alias_set, + DECL_POINTER_ALIAS_SET (decl)); + } } } }