Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

misc-redundant-expression: expression with calls to a non-pure function is considered as always-true #35478

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR36505
Status NEW
Importance P enhancement
Reported by Pavel Kryukov (pavel.kryukov@phystech.edu)
Reported on 2018-02-24 04:45:22 -0800
Last modified on 2021-11-21 10:16:54 -0800
Version unspecified
Hardware PC Windows NT
CC alexfh@google.com, djasper@google.com, etienneb+llvm@google.com, eugene.zelenko@gmail.com, klimek@google.com, llvm-bugs@lists.llvm.org, xazax.hun@gmail.com
Fixed by commit(s)
Attachments ldfile.c (282 bytes, text/x-csrc)
Blocks
Blocked by
See also
Created attachment 19951
Example of always-true false positive with calls to a non-pure function

Clang-Tidy produces a false positive warning about always-true expression (misc-
redundant-expression check) if expression contains consequent calls to a non-
pure function which have different return values:

$> clang-tidy -checks='*' ldfile.c -- -Wall
15 warnings generated.
./ldfile.c:11:32: warning: logical expression is always true [misc-redundant-
expression]
    if ((token = yylex()) != 1 || (token = yylex()) != 2) {
                               ^
Suppressed 14 warnings (14 in non-user code).

$> clang ldfile.c -Wall -Wextra && ./a.out
false

The code is taken from GNU Binutils (/ld/ldfile.c) source file.
Quuxplusone commented 6 years ago

Attached ldfile.c (282 bytes, text/x-csrc): Example of always-true false positive with calls to a non-pure function

Quuxplusone commented 6 years ago

Issue is reproducable in Clang-Tidy 6.0.0

Quuxplusone commented 6 years ago

Still there in Clang-Tidy 7.0.0

Quuxplusone commented 4 years ago

Reproduced with Clang-Tidy 9.0.1

Quuxplusone commented 4 years ago
Same thing for Clang-Tidy 10.
Godbolt example: https://godbolt.org/z/w7PggB
Quuxplusone commented 3 years ago

Reproduced with Clang-Tidy 11.0.0: https://godbolt.org/z/6nWMMa

Quuxplusone commented 2 years ago

Reproduced with Clang-Tidy 13.0.0: https://godbolt.org/z/s5zcrzqhs

Quuxplusone commented 2 years ago

Reproduced with Clang-Tidy 13.0.0: https://godbolt.org/z/s5zcrzqhs