public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63357] New: Warn for P && P and P || P
@ 2014-09-24 10:26 mpolacek at gcc dot gnu.org
  2014-12-10  8:56 ` [Bug c/63357] " mpolacek at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-09-24 10:26 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63357
           Summary: Warn for P && P and P || P
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org

We probably should warn about (both C/C++):

int
foo (int a, int b)
{
  if (a && a)
    return 1;
  if (b || b)
    return 2;
  if (!a && !a)
    return 3;
  if (!b || !b)
    return 4;
  return 0;
}

See https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02080.html

I suggest this be called -Wredundant-op.  Better names?


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

* [Bug c/63357] Warn for P && P and P || P
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
@ 2014-12-10  8:56 ` mpolacek at gcc dot gnu.org
  2014-12-10  9:22 ` [Bug c/63357] Warn for P && P and P || P (same expression used multiple times in a condition) burnus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-10  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 64250 has been marked as a duplicate of this bug. ***


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
  2014-12-10  8:56 ` [Bug c/63357] " mpolacek at gcc dot gnu.org
@ 2014-12-10  9:22 ` burnus at gcc dot gnu.org
  2015-04-21  6:04 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2014-12-10  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Warn for P && P and P || P  |Warn for P && P and P || P
                   |                            |(same expression used
                   |                            |multiple times in a
                   |                            |condition)

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Augmented summary to make it better searchable. See also related PR64249.


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
  2014-12-10  8:56 ` [Bug c/63357] " mpolacek at gcc dot gnu.org
  2014-12-10  9:22 ` [Bug c/63357] Warn for P && P and P || P (same expression used multiple times in a condition) burnus at gcc dot gnu.org
@ 2015-04-21  6:04 ` mpolacek at gcc dot gnu.org
  2015-04-22 10:01 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-21  6:04 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |6.0

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have an untested patch.


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-04-21  6:04 ` mpolacek at gcc dot gnu.org
@ 2015-04-22 10:01 ` mpolacek at gcc dot gnu.org
  2015-04-24 12:11 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-22 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |61534

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch here
https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01137.html
But it's blocked until we resolve PR61534.


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2015-04-22 10:01 ` mpolacek at gcc dot gnu.org
@ 2015-04-24 12:11 ` mpolacek at gcc dot gnu.org
  2015-04-24 12:12 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-24 12:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Fri Apr 24 12:10:52 2015
New Revision: 222408

URL: https://gcc.gnu.org/viewcvs?rev=222408&root=gcc&view=rev
Log:
    PR c/63357
    * c-common.c (warn_logical_operator): Warn if the operands have the
    same expressions.

    * doc/invoke.texi: Update description of -Wlogical-op.

    * c-c++-common/Wlogical-op-1.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/Wlogical-op-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-04-24 12:11 ` mpolacek at gcc dot gnu.org
@ 2015-04-24 12:12 ` mpolacek at gcc dot gnu.org
  2023-02-24  8:56 ` dcb314 at hotmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-04-24 12:12 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.


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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2015-04-24 12:12 ` mpolacek at gcc dot gnu.org
@ 2023-02-24  8:56 ` dcb314 at hotmail dot com
  2023-02-24 10:49 ` manu at gcc dot gnu.org
  2023-02-24 14:23 ` dcb314 at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: dcb314 at hotmail dot com @ 2023-02-24  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

David Binderman <dcb314 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dcb314 at hotmail dot com

--- Comment #8 from David Binderman <dcb314 at hotmail dot com> ---
This could probably be extended to other operators.

Static analyser cppcheck can be made to say things like:

linux-6.2/drivers/spi/spi-sn-f-ospi.c:614:31: style: Same expression
'SPI_TX_OCTAL' found multiple times in chain of '|' operators.
[duplicateExpression]

Source code is

    ctlr->mode_bits = SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL
        | SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_OCTAL
        | SPI_MODE_0 | SPI_MODE_1 | SPI_LSB_FIRST;

If |, then probably also &.

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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-02-24  8:56 ` dcb314 at hotmail dot com
@ 2023-02-24 10:49 ` manu at gcc dot gnu.org
  2023-02-24 14:23 ` dcb314 at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2023-02-24 10:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to David Binderman from comment #8)
> This could probably be extended to other operators.

Please open a new PR mentioning this one.

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

* [Bug c/63357] Warn for P && P and P || P  (same expression used multiple times in a condition)
  2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-02-24 10:49 ` manu at gcc dot gnu.org
@ 2023-02-24 14:23 ` dcb314 at hotmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: dcb314 at hotmail dot com @ 2023-02-24 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Manuel López-Ibáñez from comment #9)
> Please open a new PR mentioning this one.

Done. See 108926.

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

end of thread, other threads:[~2023-02-24 14:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24 10:26 [Bug c/63357] New: Warn for P && P and P || P mpolacek at gcc dot gnu.org
2014-12-10  8:56 ` [Bug c/63357] " mpolacek at gcc dot gnu.org
2014-12-10  9:22 ` [Bug c/63357] Warn for P && P and P || P (same expression used multiple times in a condition) burnus at gcc dot gnu.org
2015-04-21  6:04 ` mpolacek at gcc dot gnu.org
2015-04-22 10:01 ` mpolacek at gcc dot gnu.org
2015-04-24 12:11 ` mpolacek at gcc dot gnu.org
2015-04-24 12:12 ` mpolacek at gcc dot gnu.org
2023-02-24  8:56 ` dcb314 at hotmail dot com
2023-02-24 10:49 ` manu at gcc dot gnu.org
2023-02-24 14:23 ` 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).