public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104680] New: identical inner condition not detected
@ 2022-02-24 16:38 dcb314 at hotmail dot com
  2022-02-24 16:41 ` [Bug c/104680] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: dcb314 at hotmail dot com @ 2022-02-24 16:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104680

            Bug ID: 104680
           Summary: identical inner condition not detected
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

For this C++ code, with a identical inner condition:

extern void g( int);

void f( int n)
{
        if (n > 31)
        {
                if (n > 31)
                {
                        g( 2 * n);
                }
        }
        else
                g( n);
}

g++ currently has nothing to say:

$ /home/dcb/gcc/results/bin/g++ -c -g -O2 -Wall -Wextra -Wduplicated-branches
feb24e.cc
$ 

cppcheck managed to find the problem, usually a result of
sloppy cut'n'paste:

feb24e.cc:8:9: warning: Identical inner 'if' condition is always true.
[identicalInnerCondition]
  if (n > 31)
        ^
feb24e.cc:6:8: note: outer condition: n>31
 if (n > 31)
       ^
feb24e.cc:8:9: note: identical inner condition: n>31
  if (n > 31)
        ^
Here is a list of all the places in the gcc source code where this
problem occurs:

trunk.git/gcc/config/avr/avr.cc:8674:22: warning: Identical inner 'if'
condition is always true. [identicalInnerCondition]
trunk.git/gcc/config/mn10300/mn10300.cc:888:8: warning: Identical inner 'if'
condition is always true. [identicalInnerCondition]
trunk.git/gcc/d/expr.cc:689:17: warning: Identical inner 'if' condition is
always true. [identicalInnerCondition]
trunk.git/libffi/src/m32r/ffi.c:66:15: warning: Identical inner 'if' condition
is always true. [identicalInnerCondition]
trunk.git/liboffloadmic/runtime/offload_engine.cpp:113:13: warning: Identical
inner 'if' condition is always true. [identicalInnerCondition]
trunk.git/zlib/contrib/minizip/zip.c:1212:26: warning: Identical inner 'if'
condition is always true. [identicalInnerCondition]

There are also 67 cases of this in the current linux kernel,
so it looks like it might be a real problem.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-03-03 17:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 16:38 [Bug c/104680] New: identical inner condition not detected dcb314 at hotmail dot com
2022-02-24 16:41 ` [Bug c/104680] " pinskia at gcc dot gnu.org
2022-03-03 14:18 ` [Bug analyzer/104680] " dmalcolm at gcc dot gnu.org
2022-03-03 14:18 ` dmalcolm at gcc dot gnu.org
2022-03-03 14:19 ` dmalcolm at gcc dot gnu.org
2022-03-03 14:20 ` dmalcolm at gcc dot gnu.org
2022-03-03 14:20 ` dmalcolm at gcc dot gnu.org
2022-03-03 14:20 ` dmalcolm at gcc dot gnu.org
2022-03-03 14:26 ` [Bug c/104680] " dmalcolm at gcc dot gnu.org
2022-03-03 14:33 ` jakub at gcc dot gnu.org
2022-03-03 17:13 ` egallager at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).