[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-03-07 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

Martin Sebor  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #18 from Martin Sebor  ---
Fixed with r258339 on trunk.  For GCC 9 I'll look into something more
sophisticated.

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-03-07 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #17 from Martin Sebor  ---
Author: msebor
Date: Wed Mar  7 19:30:31 2018
New Revision: 258339

URL: https://gcc.gnu.org/viewcvs?rev=258339=gcc=rev
Log:
PR tree-optimization/84468 - bogus -Wstringop-truncation despite assignment
after conditional strncpy

gcc/ChangeLog:

PR tree-optimization/84468
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Consider successor
basic block when looking for nul assignment.

gcc/testsuite/ChangeLog:

PR tree-optimization/84468
* g++.dg/warn/Wstringop-truncation-2.C: New test.
* gcc.dg/Wstringop-truncation.c: New test.
* gcc.dg/Wstringop-truncation-2.c: New test.


Added:
trunk/gcc/testsuite/g++.dg/warn/Wstringop-truncation-2.C
trunk/gcc/testsuite/gcc.dg/Wstringop-truncation-2.c
trunk/gcc/testsuite/gcc.dg/Wstringop-truncation.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/warn/Wstringop-truncation-1.C
trunk/gcc/tree-ssa-strlen.c

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-03-06 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1

--- Comment #16 from Richard Biener  ---
I still say simply walk to the next VDEF...

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |8.0

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-27 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #15 from Romain Geissler  ---
Hi,

This latest patch seems to fix the occurences I have in my own code. Thanks ;)

Cheers,
Romain

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-26 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #14 from Martin Sebor  ---
(In reply to Romain Geissler from comment #13)

Ah, right.  It's not skipping over debug statements.  That's easier to fix than
pr84561.  This should do it:

Index: gcc/tree-ssa-strlen.c
===
--- gcc/tree-ssa-strlen.c   (revision 257963)
+++ gcc/tree-ssa-strlen.c   (working copy)
@@ -1856,8 +1856,21 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi
  avoid the truncation warning.  */
   gsi_next_nondebug ();
   gimple *next_stmt = gsi_stmt (gsi);
+  if (!next_stmt)
+{
+  /* When there is no statement in the same basic block check
+the immediate successor block.  */
+  if (basic_block bb = gimple_bb (stmt))
+   {
+ basic_block nextbb
+   = EDGE_COUNT (bb->succs) ? EDGE_SUCC (bb, 0)->dest : NULL;
+ gimple_stmt_iterator it = gsi_start_bb (nextbb);
+ gsi_next_nondebug ();
+ next_stmt = gsi_stmt (it);
+   }
+}

-  if (!gsi_end_p (gsi) && is_gimple_assign (next_stmt))
+  if (next_stmt && is_gimple_assign (next_stmt))
 {
   tree lhs = gimple_assign_lhs (next_stmt);
   tree_code code = TREE_CODE (lhs);

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-25 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #13 from Romain Geissler  ---
Hi,

It looks like that the code in #comment 11 works when you build just with -O2,
but not when you add debug symbols: -O2 -g. Do we have a way to ignore debug
statements when looking for the next statement in the next basic block ?

Cheers,
Romain

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-25 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #12 from Martin Sebor  ---
Yes, all the relevant tests pass with the patch.  There is no warning for
either the test case in comment #0 or the one in comment #11.  The change from
v1 of the patch is just the addition of test for null to avoid the ICE.

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-25 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #11 from Romain Geissler  ---
Hi,

Indeed this version of the patch doesn't have any segv. However it seems that
it doesn't fix anymore the initial bug report. Does it actually passes the new
tests you introduced in your patch ?

Unless I am mistaken (I am pretty sure I have applied the patch), the following
code extracted from your tests still emit a warning with -O2

a, q->a, sizeof p->a - 1);/* { dg-bogus
"\\\[-Wstringop-truncation" } */

  p->a[sizeof p->a - 1] = 0;
}
EOF

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #10 from Martin Sebor  ---
Thanks, I can reproduce it with that test case.  Checking for the basic block
being null fixes the SEGV for me.  Let me retest this and post an update for
review.

Index: gcc/tree-ssa-strlen.c
===
--- gcc/tree-ssa-strlen.c   (revision 257963)
+++ gcc/tree-ssa-strlen.c   (working copy)
@@ -1856,8 +1856,20 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi
  avoid the truncation warning.  */
   gsi_next_nondebug ();
   gimple *next_stmt = gsi_stmt (gsi);
+  if (!next_stmt)
+{
+  /* When there is no statement in the same basic block check
+the immediate successor block.  */
+  if (basic_block bb = gimple_bb (stmt))
+   {
+ basic_block nextbb
+   = EDGE_COUNT (bb->succs) ? EDGE_SUCC (bb, 0)->dest : NULL;
+ gimple_stmt_iterator it = gsi_start_bb (nextbb);
+ next_stmt = gsi_stmt (it);
+   }
+}

-  if (!gsi_end_p (gsi) && is_gimple_assign (next_stmt))
+  if (next_stmt && is_gimple_assign (next_stmt))
 {
   tree lhs = gimple_assign_lhs (next_stmt);
   tree_code code = TREE_CODE (lhs);

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-24 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #9 from Romain Geissler  ---
Ok I was able to strip down the ICE to this very simple reproducer:

<

static char keyword[4];

static void f (void) { strncpy(keyword, "if  ", 4); }
EOF

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-24 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #8 from Romain Geissler  ---
I am currently testing a little variant of your patch (check that "nextbb" if
not NULL before trying to use it):

Index: gcc/tree-ssa-strlen.c
===
--- gcc/tree-ssa-strlen.c   (revision 257796)
+++ gcc/tree-ssa-strlen.c   (working copy)
@@ -1851,8 +1851,21 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi
  avoid the truncation warning.  */
   gsi_next_nondebug ();
   gimple *next_stmt = gsi_stmt (gsi);
+  if (!next_stmt)
+{
+  /* When there is no statement in the same basic block check
+the immediate successor block.  */
+  basic_block bb = gimple_bb (stmt);
+  basic_block nextbb
+   = EDGE_COUNT (bb->succs) ? EDGE_SUCC (bb, 0)->dest : NULL;
+  if (nextbb)
+{
+  gimple_stmt_iterator it = gsi_start_bb (nextbb);
+  next_stmt = gsi_stmt (it);
+}
+}

-  if (!gsi_end_p (gsi) && is_gimple_assign (next_stmt))
+  if (next_stmt && is_gimple_assign (next_stmt))
 {
   tree lhs = gimple_assign_lhs (next_stmt);
   tree_code code = TREE_CODE (lhs);


If it doesn't work, I will provide you with the translation unit.

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #7 from Martin Sebor  ---
Thanks for the early heads up!  Can you please attach the translation unit for
the kernel file that GCC faults on?

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-24 Thread romain.geissler at amadeus dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #6 from Romain Geissler  ---
Hi,

Tried to apply this patch on top of current trunk. During my build process, I
bootstrap a complete Linux/binutils/glibc/gcc toolchain following the Linux
From Scratch guidelines.

Without the patch, the bootstrap works fine. With the patch, the bootstrap
fails when using a newly built gcc 8, I try to build the Linux headers. Here
are the logs I have:

+ cd /workdir/src/linux-2.6.32.23
+ make mrproper
+ make INSTALL_HDR_PATH=dest headers_install
  CHK include/linux/version.h
  UPD include/linux/version.h
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/basic/hash
  HOSTCC  scripts/unifdef
In file included from
/home/jenkins/workspace/OTF_Toolchain_release_4.0-YQJ6EBM33XTPWHNNQSFSZFEGBOIWUEOX32S2OZLINN43UBSUZTJA/output/build/temporary-system/install/include/string.h:630,
 from scripts/unifdef.c:72:
scripts/unifdef.c: In function 'Mpass':
scripts/unifdef.c:377:28: internal compiler error: Segmentation fault
 static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }

^~~

scripts/unifdef.c:377:28: internal compiler error: Aborted
gcc: internal compiler error: Aborted signal terminated program cc1
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
scripts/Makefile.host:118: recipe for target 'scripts/unifdef' failed
make[1]: *** [scripts/unifdef] Error 4
Makefile:1089: recipe for target '__headers' failed
make: *** [__headers] Error 2


I expect that you would be able to reproduce the same error by downloading the
Linux headers
(https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.23.tar.gz) and then:

make mrproper
make INSTALL_HDR_PATH=dest headers_install


This file is actually pretty simple. See
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/scripts/unifdef.c?h=v2.6.32.23#n377

...
static void Pelif (void) { print(); ignoreoff(); state(IS_PASS_MIDDLE); }
...
static void Mpass (void) { strncpy(keyword, "if  ", 4); Pelif(); }
...

Maybe the fact that the instruction that follows strncpy is a function call
makes gcc seg faults ?

Cheers,
Romain

[Bug tree-optimization/84468] [8 Regression] bogus -Wstringop-truncation despite assignment after conditional strncpy

2018-02-19 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch
Summary|[gcc 8] Inconsistent|[8 Regression] bogus
   |-Wstringop-truncation   |-Wstringop-truncation
   |warnings with -O2   |despite assignment after
   ||conditional strncpy

--- Comment #5 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-02/msg01141.html