Bug 87052 - STRING_CST printing incomplete in Gimple dumps
Summary: STRING_CST printing incomplete in Gimple dumps
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Martin Sebor
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-08-21 23:57 UTC by Martin Sebor
Modified: 2018-08-24 21:49 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-08-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2018-08-21 23:57:43 UTC
STRING_CST nodes with embedded nuls are formatted in Gimple dumps only up to the first nul.  Characters beyond the first nul are not printed.  This makes the dumps incomplete (and raises the question of whether the code is even correct.)  This has recently been exacerbated by transforming braced-list initialized constant character arrays into STRING_CSTs (r263511).

$ cat f.c && gcc  -O2 -S -Wall -fdump-tree-gimple=/dev/stdout f.c
void f (char *d)
{
  const char a[3] = "\000ab";

  __builtin_strcpy (d, a);
}

void g (char *d)
{
  const char a[] = { 0, 'a', 'b', 'b' };

  __builtin_strcpy (d, a);
}
f (char * d)
{
  const char a[3];

  try
    {
      a = "";
      __builtin_strcpy (d, &a);
    }
  finally
    {
      a = {CLOBBER};
    }
}


g (char * d)
{
  const char a[4];

  try
    {
      a = "";
      __builtin_strcpy (d, &a);
    }
  finally
    {
      a = {CLOBBER};
    }
}
Comment 1 Martin Sebor 2018-08-22 02:57:15 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01324.html
Comment 2 Martin Sebor 2018-08-22 16:43:30 UTC
Patch committed in r263781.
Comment 3 Martin Sebor 2018-08-22 16:43:30 UTC
Author: msebor
Date: Wed Aug 22 16:42:56 2018
New Revision: 263781

URL: https://gcc.gnu.org/viewcvs?rev=263781&root=gcc&view=rev
Log:
PR middle-end/87052 - STRING_CST printing incomplete in Gimple dumps

gcc/testsuite/ChangeLog:

	PR middle-end/87052
	* gcc.dg/pr87052.c: New test.
	* gcc.dg/tree-ssa/dump-3.c: Adjust.

gcc/ChangeLog:

	PR middle-end/87052
	* tree-pretty-print.c (pretty_print_string): Add argument.
	(dump_generic_node): Call to pretty_print_string with string size.

Added:
    trunk/gcc/testsuite/gcc.dg/pr87052.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/dump-3.c
    trunk/gcc/tree-pretty-print.c
Comment 4 Martin Sebor 2018-08-24 21:49:57 UTC
Done in r263781.