aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index fb613da..ae28445 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14398,3 +14398,24 @@ fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE_INT off)
return fold_build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (ptr),
ptr, size_int (off));
}
+
+/* Return a char pointer for a C string if it is a string constant
+ or sum of string constant and integer constant. */
+
+const char *
+c_getstr (tree src)
+{
+ tree offset_node;
+
+ src = string_constant (src, &offset_node);
+ if (src == 0)
+ return 0;
+
+ if (offset_node == 0)
+ return TREE_STRING_POINTER (src);
+ else if (!tree_fits_uhwi_p (offset_node)
+ || compare_tree_int (offset_node, TREE_STRING_LENGTH (src) - 1) > 0)
+ return 0;
+
+ return TREE_STRING_POINTER (src) + tree_to_uhwi (offset_node);
+}