[all-commits] [llvm/llvm-project] d8447c: [Clang] Correct handling of negative and out-of-bo...
Bill Wendling via All-commits
all-commits at lists.llvm.org
Mon Nov 20 09:49:33 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: d8447c78ab16c16eb17abab76e0bc77f58d2d9be
https://github.com/llvm/llvm-project/commit/d8447c78ab16c16eb17abab76e0bc77f58d2d9be
Author: Bill Wendling <5993918+bwendling at users.noreply.github.com>
Date: 2023-11-20 (Mon, 20 Nov 2023)
Changed paths:
M clang/lib/CodeGen/CGBuiltin.cpp
M clang/test/CodeGen/attr-counted-by.c
Log Message:
-----------
[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.
More information about the All-commits
mailing list