The extension that allows for pointer arithmetic on 'void' types treats
the 'void' as a 'char'. We should use the 'char' size instead of one in
this case to allow warning when pointer arithmetic would go out of
bounds.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/Sema/array-bounds-ptr-arith.c | ||
---|---|---|
14 | I'm fine with that change, but I don't understand how it relates to that commit ;-) |
clang/test/Sema/array-bounds-ptr-arith.c | ||
---|---|---|
14 | The original size 80 was large enough to emit a warning. However, 9 *didn't* emit a warning, but should. (Note that 8 won't emit a warning because of pointer arithmetic voodoo.) |
clang/test/Sema/array-bounds-ptr-arith.c | ||
---|---|---|
14 | It's slightly confusing, but the previous increment of 80 masked the issue with a smaller increment that was still out of bounds, IIUC. I think the previous code had a bytes vs bits bug? |
clang/test/Sema/array-bounds-ptr-arith.c | ||
---|---|---|
14 | Yes, that's pretty much what way happening. The comparison would be 80 (index) vs 64 (array length). But when the ptrarith_typesize is one, the comparison is 9 vs 64. |
LGTM; please consider appending to the commit message something along the lines of "operations on the result of getTypeSize() are in bits, not bytes. Using 1 as the value for void* is the correct number of bytes, but we're doing arithmetic in bits." or something to denote this is a unit-of-measure related bug.
I'm fine with that change, but I don't understand how it relates to that commit ;-)