public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95157] New: Missing -Wtautological-compare warning
@ 2020-05-15 22:13 simon.marchi at polymtl dot ca
  2020-05-16 16:40 ` [Bug c/95157] " harald at gigawatt dot nl
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: simon.marchi at polymtl dot ca @ 2020-05-15 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95157
           Summary: Missing -Wtautological-compare warning
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon.marchi at polymtl dot ca
  Target Milestone: ---

Using this code:

volatile short insn;

int main()
{
  if (insn < 0 && insn > 3) {
      return 1;
  } else {
      return 0;
  }
}


clang 11 warns, but gcc doesn't:

$ gcc-10 test.c -c -Wall
$ g++-10 test.c -c -Wall
$ clang-11 test.c -c -Wall 
test.c:5:16: warning: overlapping comparisons always evaluate to false
[-Wtautological-overlap-compare]
  if (insn < 0 && insn > 3) {
      ~~~~~~~~~^~~~~~~~~~~
1 warning generated.
$ clang++-11 test.c -c -Wall
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is
deprecated [-Wdeprecated]
test.c:5:16: warning: overlapping comparisons always evaluate to false
[-Wtautological-overlap-compare]
  if (insn < 0 && insn > 3) {
      ~~~~~~~~~^~~~~~~~~~~
1 warning generated.


I think -Wtautological-compare should trigger here.

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

* [Bug c/95157] Missing -Wtautological-compare warning
  2020-05-15 22:13 [Bug c/95157] New: Missing -Wtautological-compare warning simon.marchi at polymtl dot ca
@ 2020-05-16 16:40 ` harald at gigawatt dot nl
  2020-05-16 16:44 ` simon.marchi at polymtl dot ca
  2020-05-26 21:26 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: harald at gigawatt dot nl @ 2020-05-16 16:40 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #1 from Harald van Dijk <harald at gigawatt dot nl> ---
For your test case, this seems like a bug in clang to me. The idea of volatile
is that the variable might change in ways the compiler cannot tell. The
compiler must read insn twice (assuming the first insn < 0 is true) and must
not assume the second read has no side effects or produces the same value as
the first read. If the two reads of insn can produce different values, it is
possible for insn < 0 && insn > 3 to be true.

However, if volatile is removed, the warning is correct, and GCC does not warn
in that case either.

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

* [Bug c/95157] Missing -Wtautological-compare warning
  2020-05-15 22:13 [Bug c/95157] New: Missing -Wtautological-compare warning simon.marchi at polymtl dot ca
  2020-05-16 16:40 ` [Bug c/95157] " harald at gigawatt dot nl
@ 2020-05-16 16:44 ` simon.marchi at polymtl dot ca
  2020-05-26 21:26 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: simon.marchi at polymtl dot ca @ 2020-05-16 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Simon Marchi <simon.marchi at polymtl dot ca> ---
Ah, good point!

So yeah, please consider the test case without `volatile`.

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

* [Bug c/95157] Missing -Wtautological-compare warning
  2020-05-15 22:13 [Bug c/95157] New: Missing -Wtautological-compare warning simon.marchi at polymtl dot ca
  2020-05-16 16:40 ` [Bug c/95157] " harald at gigawatt dot nl
  2020-05-16 16:44 ` simon.marchi at polymtl dot ca
@ 2020-05-26 21:26 ` mpolacek at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-26 21:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-05-26
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2020-05-26 21:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 22:13 [Bug c/95157] New: Missing -Wtautological-compare warning simon.marchi at polymtl dot ca
2020-05-16 16:40 ` [Bug c/95157] " harald at gigawatt dot nl
2020-05-16 16:44 ` simon.marchi at polymtl dot ca
2020-05-26 21:26 ` mpolacek 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).