Bug 46635 - c-family/c-common.c uses BITS_PER_UNIT in lieu of TYPE_PRECISION (char_type_node)
Summary: c-family/c-common.c uses BITS_PER_UNIT in lieu of TYPE_PRECISION (char_type_n...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: internal-improvement, wrong-code
Depends on:
Blocks: 46633
  Show dependency treegraph
 
Reported: 2010-11-24 05:36 UTC by Jorn Wolfgang Rennecke
Modified: 2024-04-03 22:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2010-11-24 05:36:47 UTC

    
Comment 1 Jorn Wolfgang Rennecke 2010-11-24 15:49:22 UTC
As Joseph S. Myers bentioned in comment 1 of PR46633, if
TREE_STRING_LENGTH is considered to be measured in BITS_PER_UNIT
rather than TYPE_PRECISION (char_type_node), fix_string_type actually
has one BITS_PER_UNIT uses too few rather than three to many.

The only other place I came up with in c-common also requires even more
BITS_PER_UNIT:

@@ -8541,8 +8544,14 @@ fold_offsetof_1 (tree expr, tree stop_re
 tree
 fold_offsetof (tree expr, tree stop_ref)
 {
+  tree size = fold_offsetof_1 (expr, stop_ref);
+
+  /* Convert in case a char is more than one unit.  */
+  size
+    = size_binop (CEIL_DIV_EXPR, size,
+                 size_int (TYPE_PRECISION (char_type_node) / BITS_PER_UNIT));
   /* Convert back from the internal sizetype to size_t.  */
-  return convert (size_type_node, fold_offsetof_1 (expr, stop_ref));
+  return convert (size_type_node, size);
 }

 /* Warn for A ?: C expressions (with B omitted) where A is a boolean
Comment 2 Eric Gallager 2019-10-08 04:11:33 UTC
(In reply to Jorn Wolfgang Rennecke from comment #1)
> As Joseph S. Myers bentioned in comment 1 of PR46633, 

(this is the last bug open blocking that one, btw)
Comment 3 Andrew Pinski 2024-04-02 22:21:06 UTC
Confirmed.

in fold_offsetof, we still have:
```
    case COMPONENT_REF:
...
      off = size_binop_loc (input_location, PLUS_EXPR, DECL_FIELD_OFFSET (t),
                            size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t))
                                      / BITS_PER_UNIT));

```

and:
```
    case ARRAY_REF:
...
      off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
```