Use new RAW_DATA_{U,S}CHAR_ELT macros in the middle-end and C FE
During the patch review of the C++ #embed optimization, Jason asked for a macro for the common ((const unsigned char *) RAW_DATA_POINTER (value))[i] and ditto with signed char patterns which appear in a lot of places. In the just committed patch I've added +#define RAW_DATA_UCHAR_ELT(NODE, I) \ + (((const unsigned char *) RAW_DATA_POINTER (NODE))[I]) +#define RAW_DATA_SCHAR_ELT(NODE, I) \ + (((const signed char *) RAW_DATA_POINTER (NODE))[I]) macros for that in tree.h. The following patch is just a cleanup to use those macros where appropriate. 2024-12-06 Jakub Jelinek <jakub@redhat.com> gcc/ * gimplify.cc (gimplify_init_ctor_eval): Use RAW_DATA_UCHAR_ELT macro. * gimple-fold.cc (fold_array_ctor_reference): Likewise. * tree-pretty-print.cc (dump_generic_node): Use RAW_DATA_UCHAR_ELT and RAW_DATA_SCHAR_ELT macros. * fold-const.cc (fold): Use RAW_DATA_UCHAR_ELT macro. gcc/c/ * c-parser.cc (c_parser_get_builtin_args, c_parser_expression, c_parser_expr_list): Use RAW_DATA_UCHAR_ELT macro. * c-typeck.cc (digest_init): Use RAW_DATA_UCHAR_ELT and RAW_DATA_SCHAR_ELT macros. (add_pending_init, maybe_split_raw_data): Use RAW_DATA_UCHAR_ELT macro.
This commit is contained in:
parent
e65b09d461
commit
ecfc0e0737
6 changed files with 22 additions and 42 deletions
|
@ -10811,8 +10811,7 @@ c_parser_get_builtin_args (c_parser *parser, const char *bname,
|
|||
for (unsigned int i = 0; i < (unsigned) RAW_DATA_LENGTH (value); i++)
|
||||
{
|
||||
expr.value = build_int_cst (integer_type_node,
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (value))[i]);
|
||||
RAW_DATA_UCHAR_ELT (value, i));
|
||||
vec_safe_push (cexpr_list, expr);
|
||||
}
|
||||
c_parser_consume_token (parser);
|
||||
|
@ -13751,8 +13750,7 @@ c_parser_expression (c_parser *parser)
|
|||
tree val = embed->value;
|
||||
unsigned last = RAW_DATA_LENGTH (val) - 1;
|
||||
next.value = build_int_cst (TREE_TYPE (val),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (val))[last]);
|
||||
RAW_DATA_UCHAR_ELT (val, last));
|
||||
next.original_type = integer_type_node;
|
||||
c_parser_consume_token (parser);
|
||||
}
|
||||
|
@ -13881,8 +13879,7 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
|
|||
&& RAW_DATA_POINTER (value)[i] == 0)
|
||||
*literal_zero_mask |= 1U << (idx + 1);
|
||||
expr.value = build_int_cst (integer_type_node,
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (value))[i]);
|
||||
RAW_DATA_UCHAR_ELT (value, i));
|
||||
vec_safe_push (ret, expr.value);
|
||||
if (orig_types)
|
||||
vec_safe_push (orig_types, expr.original_type);
|
||||
|
|
|
@ -9379,15 +9379,13 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
|
|||
&& TYPE_PRECISION (type) == CHAR_BIT)
|
||||
for (unsigned int i = 0;
|
||||
i < (unsigned) RAW_DATA_LENGTH (inside_init); ++i)
|
||||
if (((const signed char *) RAW_DATA_POINTER (inside_init))[i] < 0)
|
||||
if (RAW_DATA_SCHAR_ELT (inside_init, i) < 0)
|
||||
warning_at (init_loc, OPT_Wconversion,
|
||||
"conversion from %qT to %qT changes value from "
|
||||
"%qd to %qd",
|
||||
integer_type_node, type,
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (inside_init))[i],
|
||||
((const signed char *)
|
||||
RAW_DATA_POINTER (inside_init))[i]);
|
||||
RAW_DATA_UCHAR_ELT (inside_init, i),
|
||||
RAW_DATA_SCHAR_ELT (inside_init, i));
|
||||
return inside_init;
|
||||
}
|
||||
|
||||
|
@ -10593,8 +10591,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
tree origtype = p->origtype;
|
||||
if (start == 1)
|
||||
p->value = build_int_cst (TREE_TYPE (v),
|
||||
*(const unsigned char *)
|
||||
RAW_DATA_POINTER (v));
|
||||
RAW_DATA_UCHAR_ELT (v, 0));
|
||||
else
|
||||
{
|
||||
p->value = v;
|
||||
|
@ -10614,9 +10611,8 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
}
|
||||
else
|
||||
v = build_int_cst (TREE_TYPE (v),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (v))[plen
|
||||
- end]);
|
||||
RAW_DATA_UCHAR_ELT (v, plen
|
||||
- end));
|
||||
add_pending_init (loc, epurpose, v, origtype,
|
||||
implicit, braced_init_obstack);
|
||||
}
|
||||
|
@ -10650,8 +10646,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
unsigned int l = RAW_DATA_LENGTH (p->value) - 1;
|
||||
p->value
|
||||
= build_int_cst (TREE_TYPE (p->value),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (p->value))[l]);
|
||||
RAW_DATA_UCHAR_ELT (p->value, l));
|
||||
}
|
||||
p->purpose = size_binop (PLUS_EXPR, p->purpose,
|
||||
bitsize_int (len));
|
||||
|
@ -10698,13 +10693,10 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
RAW_DATA_LENGTH (last->value) -= l;
|
||||
RAW_DATA_POINTER (last->value) += l;
|
||||
if (RAW_DATA_LENGTH (last->value) == 1)
|
||||
{
|
||||
const unsigned char *s
|
||||
= ((const unsigned char *)
|
||||
RAW_DATA_POINTER (last->value));
|
||||
last->value
|
||||
= build_int_cst (TREE_TYPE (last->value), *s);
|
||||
}
|
||||
last->value
|
||||
= build_int_cst (TREE_TYPE (last->value),
|
||||
RAW_DATA_UCHAR_ELT (last->value,
|
||||
0));
|
||||
last->purpose
|
||||
= size_binop (PLUS_EXPR, last->purpose,
|
||||
bitsize_int (l));
|
||||
|
@ -10718,8 +10710,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
> cnt);
|
||||
RAW_DATA_LENGTH (value) -= cnt;
|
||||
const unsigned char *s
|
||||
= ((const unsigned char *) RAW_DATA_POINTER (value)
|
||||
+ RAW_DATA_LENGTH (value));
|
||||
= &RAW_DATA_UCHAR_ELT (value, RAW_DATA_LENGTH (value));
|
||||
unsigned int o = RAW_DATA_LENGTH (value);
|
||||
for (r = p; cnt--; ++o, ++s)
|
||||
{
|
||||
|
@ -10731,8 +10722,7 @@ add_pending_init (location_t loc, tree purpose, tree value, tree origtype,
|
|||
}
|
||||
if (RAW_DATA_LENGTH (value) == 1)
|
||||
value = build_int_cst (TREE_TYPE (value),
|
||||
*((const unsigned char *)
|
||||
RAW_DATA_POINTER (value)));
|
||||
RAW_DATA_UCHAR_ELT (value, 0));
|
||||
}
|
||||
}
|
||||
if (!implicit)
|
||||
|
@ -11662,8 +11652,7 @@ maybe_split_raw_data (tree value, tree *raw_data)
|
|||
return value;
|
||||
*raw_data = value;
|
||||
value = build_int_cst (integer_type_node,
|
||||
*(const unsigned char *)
|
||||
RAW_DATA_POINTER (*raw_data));
|
||||
RAW_DATA_UCHAR_ELT (*raw_data, 0));
|
||||
++RAW_DATA_POINTER (*raw_data);
|
||||
--RAW_DATA_LENGTH (*raw_data);
|
||||
return value;
|
||||
|
|
|
@ -14001,8 +14001,7 @@ fold (tree expr)
|
|||
- wi::to_offset (CONSTRUCTOR_ELT (op0, idx)->index));
|
||||
gcc_checking_assert (o < RAW_DATA_LENGTH (val));
|
||||
return build_int_cst (TREE_TYPE (val),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (val))[o.to_uhwi ()]);
|
||||
RAW_DATA_UCHAR_ELT (val, o.to_uhwi ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8389,9 +8389,7 @@ fold_array_ctor_reference (tree type, tree ctor,
|
|||
return NULL_TREE;
|
||||
*suboff += access_index.to_uhwi () * BITS_PER_UNIT;
|
||||
unsigned o = (access_index - wi::to_offset (elt->index)).to_uhwi ();
|
||||
return build_int_cst (TREE_TYPE (val),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (val))[o]);
|
||||
return build_int_cst (TREE_TYPE (val), RAW_DATA_UCHAR_ELT (val, o));
|
||||
}
|
||||
if (!size && TREE_CODE (val) != CONSTRUCTOR)
|
||||
{
|
||||
|
|
|
@ -5533,8 +5533,7 @@ gimplify_init_ctor_eval (tree object, vec<constructor_elt, va_gc> *elts,
|
|||
tree init
|
||||
= build2 (INIT_EXPR, TREE_TYPE (cref), cref,
|
||||
build_int_cst (TREE_TYPE (value),
|
||||
((const unsigned char *)
|
||||
RAW_DATA_POINTER (value))[i]));
|
||||
RAW_DATA_UCHAR_ELT (value, i)));
|
||||
gimplify_and_add (init, pre_p);
|
||||
ggc_free (init);
|
||||
}
|
||||
|
|
|
@ -2625,11 +2625,9 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
|
|||
{
|
||||
if (TYPE_UNSIGNED (TREE_TYPE (node))
|
||||
|| TYPE_PRECISION (TREE_TYPE (node)) > CHAR_BIT)
|
||||
pp_decimal_int (pp, ((const unsigned char *)
|
||||
RAW_DATA_POINTER (node))[i]);
|
||||
pp_decimal_int (pp, RAW_DATA_UCHAR_ELT (node, i));
|
||||
else
|
||||
pp_decimal_int (pp, ((const signed char *)
|
||||
RAW_DATA_POINTER (node))[i]);
|
||||
pp_decimal_int (pp, RAW_DATA_SCHAR_ELT (node, i));
|
||||
if (i == RAW_DATA_LENGTH (node) - 1U)
|
||||
break;
|
||||
else if (i == 9 && RAW_DATA_LENGTH (node) > 20)
|
||||
|
|
Loading…
Add table
Reference in a new issue