aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-11-23 18:45:45 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-11-23 11:45:45 -0700
commit70c70369ce868fd8b049f710c01a899e502f6f68 (patch)
treee911138371a57dd5587cf3a3cc4e7882f5327607 /gcc/tree.c
parentdb1d09b049a9388c481ff76aa00fe74734cce1c8 (diff)
downloadgcc-70c70369ce868fd8b049f710c01a899e502f6f68.zip
gcc-70c70369ce868fd8b049f710c01a899e502f6f68.tar.gz
gcc-70c70369ce868fd8b049f710c01a899e502f6f68.tar.bz2
PR tree-optimization/87756 - missing unterminated argument warning using address of a constant character
gcc/ChangeLog: PR tree-optimization/87756 * expr.c (string_constant): Synthesize a string literal from the address of a constant character. * tree.c (build_string_literal): Add an argument. * tree.h (build_string_literal): Same. gcc/testsuite/ChangeLog: PR tree-optimization/87756 * gcc.dg/builtin-memchr-2.c: New test. * gcc.dg/builtin-memchr-3.c: Same. * gcc.dg/warn-sprintf-no-nul-2.c: Same. From-SVN: r266418
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 39a9246..1e19a0b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -11517,25 +11517,28 @@ build_alloca_call_expr (tree size, unsigned int align, HOST_WIDE_INT max_size)
}
}
-/* Create a new constant string literal and return a char* pointer to it.
- The STRING_CST value is the LEN characters at STR. */
+/* Create a new constant string literal consisting of elements of type
+ ELTYPE and return a tree node representing char* pointer to it as
+ an ADDR_EXPR (ARRAY_REF (ELTYPE, ...)). The STRING_CST value is
+ the LEN bytes at STR (the representation of the string, which may
+ be wide). */
+
tree
-build_string_literal (int len, const char *str)
+build_string_literal (int len, const char *str,
+ tree eltype /* = char_type_node */)
{
- tree t, elem, index, type;
-
- t = build_string (len, str);
- elem = build_type_variant (char_type_node, 1, 0);
- index = build_index_type (size_int (len - 1));
- type = build_array_type (elem, index);
+ tree t = build_string (len, str);
+ tree index = build_index_type (size_int (len - 1));
+ eltype = build_type_variant (eltype, 1, 0);
+ tree type = build_array_type (eltype, index);
TREE_TYPE (t) = type;
TREE_CONSTANT (t) = 1;
TREE_READONLY (t) = 1;
TREE_STATIC (t) = 1;
- type = build_pointer_type (elem);
+ type = build_pointer_type (eltype);
t = build1 (ADDR_EXPR, type,
- build4 (ARRAY_REF, elem,
+ build4 (ARRAY_REF, eltype,
t, integer_zero_node, NULL_TREE, NULL_TREE));
return t;
}