diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-12-06 11:00:52 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-12-06 11:00:52 +0100 |
commit | ecfc0e07377346c6307556496db882f4dcfb2846 (patch) | |
tree | 99d502275be360882a398a94722abe70416306a9 /gcc | |
parent | e65b09d461d2a4f37fb55d6dcd2e94b1f444daea (diff) | |
download | gcc-ecfc0e07377346c6307556496db882f4dcfb2846.zip gcc-ecfc0e07377346c6307556496db882f4dcfb2846.tar.gz gcc-ecfc0e07377346c6307556496db882f4dcfb2846.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/c-parser.cc | 9 | ||||
-rw-r--r-- | gcc/c/c-typeck.cc | 39 | ||||
-rw-r--r-- | gcc/fold-const.cc | 3 | ||||
-rw-r--r-- | gcc/gimple-fold.cc | 4 | ||||
-rw-r--r-- | gcc/gimplify.cc | 3 | ||||
-rw-r--r-- | gcc/tree-pretty-print.cc | 6 |
6 files changed, 22 insertions, 42 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index a45e9f9..5226169 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -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); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 29a88aa..d84cb30 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -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; diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 1e8ae1a..2e18553 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -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 ())); } } diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 3c0abf2..a3b9082 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -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) { diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index aa99c0a..5078763 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -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); } diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index 1582a4e..54c9564 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -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) |