Issue 120214
Summary -Wtautological-compare should flag tautological pointer bounds checks
Labels clang:diagnostics
Assignees
Reporter nikic
    `-Wtautological-compare` should report pointer "bounds checks" patterns that are always true/false because unsigned pointer arithmetic cannot overflow.

```
bool test1(const char *ptr, size_t index) {
  return ptr + index < ptr; // always false
}

bool test2(const char *ptr, size_t index) {
  return ptr + index >= ptr; // always true
}
```

These two are fine though:

```
bool test3(const char *ptr, ssize_t index) {
  return ptr + index < ptr; // unknown
}

bool test4(const char *ptr, ssize_t index) {
  return ptr + index >= ptr; // unknown
}
```

Idea from https://github.com/llvm/llvm-project/pull/118472#issuecomment-2548141458.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to