Hi, Joseph and Martin, When I implemented the patch to attach the counted_by information to an array reference (FAM reference) in C FE, The work was done inside the routine “build_component_ref” in gcc/c/c-typeck.cc <http://c-typeck.cc/>. and this is very reasonable and quite clean.
Now, If we try to replace a structure pointer reference with counted_by attached to the FAM field, where in the C FE I should look at? For the following small example, I am trying to replace the pointer reference at line 28, “obj”, and line 34, “q” to a call to .ACCESS_WITH_SIZE. However, “p” at line 21 and “q” at line 33 should not be replaced. Do you have any suggestions? Thanks a lot for your help here. Qing 1 #include <stdlib.h> 2 #include <stddef.h> 3 4 struct annotated { 5 size_t count; 6 char array[] __attribute__((counted_by (count))); 7 }; 8 9 /* compute the minimum # of bytes needed to hold a structure “annotated”, 10 whose # of elements of “array” is COUNT. */ 11 #define MAX(A, B) (A > B) ? (A) : (B) 12 #define ALLOC_SIZE_ANNOTATED(COUNT) \ 13 MAX(sizeof (struct annotated), \ 14 offsetof(struct annotated, array[0]) + (COUNT) * sizeof(char)) 15 16 /* allocate the memory for the structure with FAM, 17 update “count” with the # of elements “index”. */ 18 static struct annotated * __attribute__((__noinline__)) alloc_buf (int index) 19 { 20 struct annotated *p; 21 p = (struct annotated *) malloc (ALLOC_SIZE_ANNOTATED(index)); 22 p->count = index; 23 return p; 24 } 25 26 static size_t __attribute__((__noinline__)) size_of (struct annotated * obj) 27 { 28 return __builtin_dynamic_object_size (obj, 1); 29 } 30 31 int main() 32 { 33 struct annotated *q = alloc_buf (10); 34 __builtin_printf ("the bdos whole is %d\n", size_of (q)); 35 return 0; 36 }