llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

-Winfinite-recursion confused by some tautological expressions

Open AaronBallman opened this issue 2 years ago • 3 comments

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).

AaronBallman avatar Jun 14 '22 17:06 AaronBallman

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Jun 14 '22 17:06 llvmbot

I'll work on this. We can also add i && !i as a tautological comparison.

hazohelet avatar Mar 24 '23 06:03 hazohelet

Proposed fix: https://reviews.llvm.org/D152093

hazohelet avatar Jun 28 '23 13:06 hazohelet