llvm-project
llvm-project copied to clipboard
-Winfinite-recursion confused by some tautological expressions
Consider code like:
void func1(int i) {
if (i || !i)
func1(i);
}
void func2(int i) {
if (i > 0 || i <= 0)
func2(i);
}
Clang correctly diagnoses func2()
as being recursive along all paths, but it mysteriously does not diagnose func1()
. (https://godbolt.org/z/Ks3Wvdf8W)
Surprisingly, we don't seem to catch i || !i
as being a tautological comparison, so it's possible that's a related issue (https://godbolt.org/z/hs9Ehrbss).
@llvm/issue-subscribers-clang-frontend
I'll work on this.
We can also add i && !i
as a tautological comparison.
Proposed fix: https://reviews.llvm.org/D152093