public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests
@ 2023-10-03 18:49 dcb314 at hotmail dot com
  2023-10-03 18:53 ` [Bug c/111684] enhancement: gcc doesn't warn about " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2023-10-03 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111684
           Summary: enhancement: gcc doesn't detect pointless tests
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Given this C++ code:

extern void g( int);

void
f( int n)
{
    if (n <= 10)
        g( n);
    else if (n > 10)
        g( 10 - n);
}

gcc doesn't have much to say:

$ ~/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra  oct3d.cc
$ 

This might be implemented as a simple extension of the Wduplicated-cond code.

Here is cppcheck finding the problem:

oct3d.cc:11:13: style: Expression is always true because 'else if' condition is
opposite to previous condition at line 9. [multiCondition]
 else if (n > 10)
            ^
oct3d.cc:9:8: note: first condition
 if (n <= 10)
       ^
oct3d.cc:11:13: note: else if condition is opposite to first condition
 else if (n > 10)
            ^
$ 

So these two problems in gcc trunk might be detected:

trunk.year/gcc/ada/sysdep.c:424:26: style: Expression is always true because
'else if' condition is opposite to previous condition at line 416.
[multiCondition]

trunk.year/libsanitizer/sanitizer_common/sanitizer_allocator_primary64.h:547:27:
style: Expression is always true because 'else if' condition is opposite to
previous condition at line 538. [multiCondition]

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

* [Bug c/111684] enhancement: gcc doesn't warn about pointless tests
  2023-10-03 18:49 [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests dcb314 at hotmail dot com
@ 2023-10-03 18:53 ` pinskia at gcc dot gnu.org
  2023-10-03 18:55 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-03 18:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|enhancement: gcc doesn't    |enhancement: gcc doesn't
                   |detect pointless tests      |warn about pointless tests
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note GCC does detect the pointless just does not warn about it.

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

* [Bug c/111684] enhancement: gcc doesn't warn about pointless tests
  2023-10-03 18:49 [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests dcb314 at hotmail dot com
  2023-10-03 18:53 ` [Bug c/111684] enhancement: gcc doesn't warn about " pinskia at gcc dot gnu.org
@ 2023-10-03 18:55 ` pinskia at gcc dot gnu.org
  2023-10-03 20:38 ` dcb314 at hotmail dot com
  2023-10-04  7:27 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-03 18:55 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Blocks|                            |87403


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

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

* [Bug c/111684] enhancement: gcc doesn't warn about pointless tests
  2023-10-03 18:49 [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests dcb314 at hotmail dot com
  2023-10-03 18:53 ` [Bug c/111684] enhancement: gcc doesn't warn about " pinskia at gcc dot gnu.org
  2023-10-03 18:55 ` pinskia at gcc dot gnu.org
@ 2023-10-03 20:38 ` dcb314 at hotmail dot com
  2023-10-04  7:27 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2023-10-03 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
I've had a quick look at the linux-6.6-rc4 kernel code 
and found about a dozen examples of this problem, so there 
would be some customers for a solution.

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

* [Bug c/111684] enhancement: gcc doesn't warn about pointless tests
  2023-10-03 18:49 [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2023-10-03 20:38 ` dcb314 at hotmail dot com
@ 2023-10-04  7:27 ` dcb314 at hotmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2023-10-04  7:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to David Binderman from comment #2)
> I've had a quick look at the linux-6.6-rc4 kernel code 
> and found about a dozen examples of this problem, so there 
> would be some customers for a solution.

A full look suggests there are about 30 examples. Surprising.

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

end of thread, other threads:[~2023-10-04  7:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03 18:49 [Bug c/111684] New: enhancement: gcc doesn't detect pointless tests dcb314 at hotmail dot com
2023-10-03 18:53 ` [Bug c/111684] enhancement: gcc doesn't warn about " pinskia at gcc dot gnu.org
2023-10-03 18:55 ` pinskia at gcc dot gnu.org
2023-10-03 20:38 ` dcb314 at hotmail dot com
2023-10-04  7:27 ` dcb314 at hotmail dot com

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).