Bug 84228 - Bogus -Wstringop-truncation warning with -g
Summary: Bogus -Wstringop-truncation warning with -g
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Marek Polacek
URL:
Keywords: diagnostic
Depends on:
Blocks: Wstringop-truncation
  Show dependency treegraph
 
Reported: 2018-02-06 09:50 UTC by Marek Polacek
Modified: 2019-01-09 23:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2018-02-06 09:50:06 UTC
char *strncpy (char *, const char *, __SIZE_TYPE__);
struct S
{
  char arr[64];
};

int
foo (struct S *p1, const char *a)
{
  if (a)
    goto err;
  strncpy (p1->arr, a, sizeof p1->arr);
  p1->arr[3] = '\0';
err:
  return 0;
}

$ ./cc1 -quiet t.c -Wstringop-truncation -O2 -g
t.c: In function ‘foo’:
t.c:12:3: warning: ‘strncpy’ specified bound 64 equals destination size [-Wstringop-truncation]
   strncpy (p1->arr, a, sizeof p1->arr);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the warning is gone without -g.
Comment 1 Marek Polacek 2018-02-06 09:50:38 UTC
I have a fix.
Comment 2 Marek Polacek 2018-02-06 13:26:26 UTC
Author: mpolacek
Date: Tue Feb  6 13:25:54 2018
New Revision: 257411

URL: https://gcc.gnu.org/viewcvs?rev=257411&root=gcc&view=rev
Log:
	PR tree-optimization/84228
	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Skip debug statements.

	* c-c++-common/Wstringop-truncation-3.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/Wstringop-truncation-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-strlen.c
Comment 3 Marek Polacek 2018-02-06 13:27:26 UTC
Fixed.