summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-21 08:58:44 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2006-06-21 08:58:44 +0000
commit1fc5c8affbf852fa27e7781cb1e23b2892983d33 (patch)
treefd1af8dab866ad596acc77b89185aabb10394617
parent7a0c37debdedc3e121fb676f63c6d1cc4845859b (diff)
downloadgcc-1fc5c8affbf852fa27e7781cb1e23b2892983d33.tar.gz
* varasm.c (mergeable_string_section): Check for embedded NULs and
NUL termination in the first int_size_in_bytes (TREE_TYPE (decl)) rather than TREE_STRING_LENGTH bytes. * gcc.dg/merge-all-constants-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114842 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/merge-all-constants-1.c8
-rw-r--r--gcc/varasm.c9
4 files changed, 24 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f2db22542c6..de7420ff09a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2006-06-21 Jakub Jelinek <jakub@redhat.com>
+
+ * varasm.c (mergeable_string_section): Check for embedded NULs and
+ NUL termination in the first int_size_in_bytes (TREE_TYPE (decl))
+ rather than TREE_STRING_LENGTH bytes.
+
2006-06-21 Richard Guenther <rguenther@suse.de>
* ggc-page.c (extra_order_size_table): Add var_ann_d,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 461e04c811f..84dd8898d59 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2006-06-21 Jakub Jelinek <jakub@redhat.com>
+
+ * gcc.dg/merge-all-constants-1.c: New test.
+
2006-06-20 Janis Johnson <janis187@us.ibm.com>
PR c++/28113
diff --git a/gcc/testsuite/gcc.dg/merge-all-constants-1.c b/gcc/testsuite/gcc.dg/merge-all-constants-1.c
new file mode 100644
index 00000000000..5c9cd06e925
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/merge-all-constants-1.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-w -O2 -fmerge-all-constants" } */
+
+const char str1[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
+const char str2[38] = "0123456789abcdefghijklmnopqrstuvwxyz";
+const char str3[10] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+/* { dg-final { scan-assembler-not "\.rodata\.str" } } */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 71158ba860b..e5abd3e2d97 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -655,16 +655,20 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
{
+ HOST_WIDE_INT len;
+
if (HAVE_GAS_SHF_MERGE && flag_merge_constants
&& TREE_CODE (decl) == STRING_CST
&& TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
&& align <= 256
- && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
+ && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
+ && TREE_STRING_LENGTH (decl) >= len)
{
enum machine_mode mode;
unsigned int modesize;
const char *str;
- int i, j, len, unit;
+ HOST_WIDE_INT i;
+ int j, unit;
char name[30];
mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
@@ -676,7 +680,6 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
align = modesize;
str = TREE_STRING_POINTER (decl);
- len = TREE_STRING_LENGTH (decl);
unit = GET_MODE_SIZE (mode);
/* Check for embedded NUL characters. */