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 + + * 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 * 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 + + * gcc.dg/merge-all-constants-1.c: New test. + 2006-06-20 Janis Johnson 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. */