c-common.c (c_apply_type_quals_to_decl): Don't crash when `restrict' is applied to...
authorMark Mitchell <mark@markmitchell.com>
Wed, 21 Oct 1998 09:59:32 +0000 (09:59 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 21 Oct 1998 09:59:32 +0000 (09:59 +0000)
* 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
gcc/c-common.c

index 1d65b6d88c9fa919494dedf40a42adaf20a73146..9799e65f9c2e0935ab189d192156d4344d6ab20b 100644 (file)
@@ -1,3 +1,8 @@
+Wed Oct 21 09:58:51 1998  Mark Mitchell  <mark@markmitchell.com>
+
+       * 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  <mark@markmitchell.com>
 
        * invoke.texi: Document -flang-isoc9x.
index 4aaeb3c78182a95c04d701942b915c69f71503d5..508a8c2e59913b145c119149e90e23749d615a7e 100644 (file)
@@ -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));
+           }
        }
     }
 }