Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pavelkryukov opened this issue Feb 24, 2018 · 8 comments
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@pavelkryukov
Copy link

pavelkryukov commented Feb 24, 2018

Bugzilla Link 36505
Version unspecified
OS Windows NT
Attachments Example of always-true false positive with calls to a non-pure function
CC @EugeneZelenko,@Xazax-hun

Extended Description

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.

@pavelkryukov
Copy link
Author

Issue is reproducable in Clang-Tidy 6.0.0

@pavelkryukov
Copy link
Author

Still there in Clang-Tidy 7.0.0

@pavelkryukov
Copy link
Author

Reproduced with Clang-Tidy 9.0.1

@pavelkryukov
Copy link
Author

Same thing for Clang-Tidy 10.
Godbolt example: https://godbolt.org/z/w7PggB

@pavelkryukov
Copy link
Author

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

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@pavelkryukov
Copy link
Author

@EugeneZelenko @Xazax-hun I’ll try to get more attention, as wrong fix-it can be generated because of this.

@FabianWolff
Copy link
Member

This is unrelated to #54011 and even intended to some extent, I believe: Almost every function call might have side effects (and misc-redundant-expression does not look into the called function), but taking this into account would prevent many legitimate warnings (arising from typos etc.) from firing, so the false positives here are tolerated.

Instead, to fix your example, I'd focus on the assignments. I've opened D122535 to this end.

@pavelkryukov
Copy link
Author

Thank you!

mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
…ant-expression` check

Fixes llvm/llvm-project#35853.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants