This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] [Ada] Make middle-end string literals NUL terminated
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>, Eric Botcazou <ebotcazou at adacore dot com>, Arnaud Charlet <charlet at adacore dot com>
- Date: Tue, 31 Jul 2018 12:07:29 +0000
- Subject: [PATCH] [Ada] Make middle-end string literals NUL terminated
Hi!
This fixes a couple STRING_CST that are not explicitly NUL terminated.
These were caught in a new check in varasm.c I am currently working on.
Having a NUL terminated string does not change the binary output, but it
makes things easier for he middle-end.
Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?
Thanks
Bernd.
2018-07-31 Bernd Edlinger <bernd.edlinger@hotmail.de>
* gcc-interface/trans.c (gnat_to_gnu): Make string literal properly
NUL terminated.
* gcc-interface/utils2.c (expand_sloc): Likewise.
diff -pur gcc/ada/gcc-interface/trans.c gcc/ada/gcc-interface/trans.c
--- gcc/ada/gcc-interface/trans.c 2018-07-17 10:10:04.000000000 +0200
+++ gcc/ada/gcc-interface/trans.c 2018-07-31 11:16:27.350728886 +0200
@@ -6079,7 +6079,7 @@ gnat_to_gnu (Node_Id gnat_node)
where GCC will want to treat it as a C string. */
string[i] = 0;
- gnu_result = build_string (length, string);
+ gnu_result = build_string (length + 1, string);
/* Strings in GCC don't normally have types, but we want
this to not be converted to the array type. */
diff -pur gcc/ada/gcc-interface/utils2.c gcc/ada/gcc-interface/utils2.c
--- gcc/ada/gcc-interface/utils2.c 2017-12-21 07:57:41.000000000 +0100
+++ gcc/ada/gcc-interface/utils2.c 2018-07-31 11:44:01.517117923 +0200
@@ -1844,7 +1844,7 @@ expand_sloc (Node_Id gnat_node, tree *fi
}
const int len = strlen (str);
- *filename = build_string (len, str);
+ *filename = build_string (len + 1, str);
TREE_TYPE (*filename) = build_array_type (char_type_node,
build_index_type (size_int (len)));
*line = build_int_cst (NULL_TREE, line_number);