diff options
author | Bill Wendling <5993918+bwendling@users.noreply.github.com> | 2023-11-20 09:49:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-20 09:49:20 -0800 |
commit | d8447c78ab16c16eb17abab76e0bc77f58d2d9be (patch) | |
tree | c926f3a22a51c336dd37e1b51fb237c5f8934063 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 4376f8c949a95914856199941ebed18c8c27b5cc (diff) | |
download | llvm-d8447c78ab16c16eb17abab76e0bc77f58d2d9be.zip llvm-d8447c78ab16c16eb17abab76e0bc77f58d2d9be.tar.gz llvm-d8447c78ab16c16eb17abab76e0bc77f58d2d9be.tar.bz2 |
[Clang] Correct handling of negative and out-of-bounds indices (#71877)
GCC returns 0 for a negative index on an array in a structure. It also
returns 0 for an array index that goes beyond the extent of the array.
In addition. a pointer to a struct field returns that field's size, not
the size of it plus the rest of the struct, unless it's the first field
in the struct.
struct s {
int count;
char dummy;
int array[] __attribute((counted_by(count)));
};
struct s *p = malloc(...);
p->count = 10;
A __bdos on the elements of p return:
__bdos(p, 0) == 30
__bdos(p->array, 0) == 10
__bdos(&p->array[0], 0) == 10
__bdos(&p->array[-1], 0) == 0
__bdos(&p->array[42], 0) == 0
Also perform some refactoring, putting the "counted_by" calculations in
their own function.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
0 files changed, 0 insertions, 0 deletions