Issue 136379
Summary -Warray-bounds misses unsafe pointer arithmetic
Labels new issue
Assignees
Reporter shuffle2
    I would expect the following to issue a warning:
```c
void g(uint64_t a, uint64_t b) {
    printf("%lx %lx\n", a, b);
}

int main(int argc, char **argv) {
    uint8_t a;
    
    // one-past the end is valid (as long as not deref'd)
    g((uint64_t)&a, (uint64_t)(&a + 1));
    // >1 past end is invalid
    // XXX clang has -Warray-bounds, but it does not warn on the below.
    // clang's -Wunsafe-buffer-usage *does* warn on it, though.
    // -Wunsafe-buffer-usage doesn't seem usable in real world tho for C code. (lots of false positives).
    g((uint64_t)&a, (uint64_t)(&a + 2));
    
 return 0;
}
```

gcc detects this as I'd expect, clang does not: https://godbolt.org/z/WEYTzMGGb

It's unclear to me if -Wunsafe-buffer-usage is the expected solution here - this flag seems unhelpful for plain C code. https://clang.llvm.org/docs/SafeBuffers.html makes it sound like the flag is mainly for use in C++ code, to detect locations that should be converted to c++-specific code patterns.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to