]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* c-typeck.c (c_sizeof): Fold result to c_size_type_node.
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 14 Nov 2000 09:47:13 +0000 (09:47 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 14 Nov 2000 09:47:13 +0000 (09:47 +0000)
        (c_sizeof_nowarn, c_alignof, c_alignof_expr): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37447 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c

index 38734a896e8561e6e9322b6e1945411e90c34842..f82e04a726b8c8b5fe3305b6cc3fffa03e26a688 100644 (file)
@@ -1,3 +1,8 @@
+2000-11-14  Richard Henderson  <rth@redhat.com>
+
+       * c-typeck.c (c_sizeof): Fold result to c_size_type_node.
+       (c_sizeof_nowarn, c_alignof, c_alignof_expr): Likewise.
+
 2000-11-13  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
 
        * loop.c (basic_induction_var): Revert accidental checkin.
index 6705440c3e2d283bc6db8e50fb13b29742d07f28..09f4089b5b361b4db99da6d0ed7e8a05430ee87f 100644 (file)
@@ -697,33 +697,38 @@ c_sizeof (type)
      tree type;
 {
   enum tree_code code = TREE_CODE (type);
+  tree size;
 
   if (code == FUNCTION_TYPE)
     {
       if (pedantic || warn_pointer_arith)
        pedwarn ("sizeof applied to a function type");
-      return size_one_node;
+      size = size_one_node;
     }
-  if (code == VOID_TYPE)
+  else if (code == VOID_TYPE)
     {
       if (pedantic || warn_pointer_arith)
        pedwarn ("sizeof applied to a void type");
-      return size_one_node;
+      size = size_one_node;
     }
-
-  if (code == ERROR_MARK)
-    return size_one_node;
-
-  if (!COMPLETE_TYPE_P (type))
+  else if (code == ERROR_MARK)
+    size = size_one_node;
+  else if (!COMPLETE_TYPE_P (type))
     {
       error ("sizeof applied to an incomplete type");
-      return size_zero_node;
+      size = size_zero_node;
     }
-
-  /* Convert in case a char is more than one unit.  */
-  return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
-                    size_int (TYPE_PRECISION (char_type_node)
-                              / BITS_PER_UNIT));
+  else
+    /* Convert in case a char is more than one unit.  */
+    size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
+                      size_int (TYPE_PRECISION (char_type_node)
+                                / BITS_PER_UNIT));
+
+  /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
+     TYPE_IS_SIZETYPE means that certain things (like overflow) will
+     never happen.  However, this node should really have type
+     `size_t', which is just a typedef for an ordinary integer type.  */
+  return fold (build1 (NOP_EXPR, c_size_type_node, size));
 }
 
 tree
@@ -731,17 +736,23 @@ c_sizeof_nowarn (type)
      tree type;
 {
   enum tree_code code = TREE_CODE (type);
+  tree size;
 
   if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
-    return size_one_node;
-
-  if (!COMPLETE_TYPE_P (type))
-    return size_zero_node;
-
-  /* Convert in case a char is more than one unit.  */
-  return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
-                    size_int (TYPE_PRECISION (char_type_node)
-                              / BITS_PER_UNIT));
+    size = size_one_node;
+  else if (!COMPLETE_TYPE_P (type))
+    size = size_zero_node;
+  else
+    /* Convert in case a char is more than one unit.  */
+    size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
+                      size_int (TYPE_PRECISION (char_type_node)
+                                / BITS_PER_UNIT));
+
+  /* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
+     TYPE_IS_SIZETYPE means that certain things (like overflow) will
+     never happen.  However, this node should really have type
+     `size_t', which is just a typedef for an ordinary integer type.  */
+  return fold (build1 (NOP_EXPR, c_size_type_node, size));
 }
 
 /* Compute the size to increment a pointer by.  */
@@ -775,20 +786,23 @@ c_alignof (type)
      tree type;
 {
   enum tree_code code = TREE_CODE (type);
+  tree t;
 
   if (code == FUNCTION_TYPE)
-    return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
-
-  if (code == VOID_TYPE || code == ERROR_MARK)
-    return size_one_node;
-
-  if (!COMPLETE_TYPE_P (type))
+    t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
+  else if (code == VOID_TYPE || code == ERROR_MARK)
+    t = size_one_node;
+  else if (code == ERROR_MARK)
+    t = size_one_node;
+  else if (!COMPLETE_TYPE_P (type))
     {
       error ("__alignof__ applied to an incomplete type");
-      return size_zero_node;
+      t = size_zero_node;
     }
+  else
+    t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
 
-  return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
+  return fold (build1 (NOP_EXPR, c_size_type_node, t));
 }
 \f
 /* Implement the __alignof keyword: Return the minimum required
@@ -800,20 +814,22 @@ tree
 c_alignof_expr (expr)
      tree expr;
 {
+  tree t;
+
   if (TREE_CODE (expr) == VAR_DECL)
-    return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
+    t = size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
  
-  if (TREE_CODE (expr) == COMPONENT_REF
-      && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
+  else if (TREE_CODE (expr) == COMPONENT_REF
+          && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
     {
       error ("`__alignof' applied to a bit-field");
-      return size_one_node;
+      t = size_one_node;
     }
   else if (TREE_CODE (expr) == COMPONENT_REF
       && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
-    return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
+    t = size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
  
-  if (TREE_CODE (expr) == INDIRECT_REF)
+  else if (TREE_CODE (expr) == INDIRECT_REF)
     {
       tree t = TREE_OPERAND (expr, 0);
       tree best = t;
@@ -833,6 +849,8 @@ c_alignof_expr (expr)
     }
   else
     return c_alignof (TREE_TYPE (expr));
+
+  return fold (build1 (NOP_EXPR, c_size_type_node, t));
 }
 
 /* Return either DECL or its known constant value (if it has one).  */