From: Guillermo E. Martinez via Libabigail Date: Thu, 17 Nov 2022 03:43:05 +0000 (-0600) Subject: ctf-reader: Fix array size representation X-Git-Tag: libabigail-2.2~5 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=77ae31417697dde8d3119e042dafd7dddb9538e1;p=libabigail.git ctf-reader: Fix array size representation A variable length array (VLA), or a flexible array member (with its size set to zero to recognize such cases) is represented in the libabigail IR as an array with "non-finite" length. This is a way to say that the length of the array is not statically known. The ABIXML array-type-def element looks like: The patch teaches the ctf-reader to correctly set the size of the array for VLAs. * src/abg-ctf-reader.cc (build_array_ctf_range): Use * tests/data/Makefile.am: Add new test. `upper_bound' and number of elements to indicate infinite array size. * tests/data/test-read-ctf/test-array-size.abi: New test. * tests/data/test-read-ctf/test-array-size.c: Likewise. * tests/data/test-read-ctf/test-array-size.o: Likewise. * tests/test-read-ctf.cc: Update testsuite. Signed-off-by: Guillermo E. Martinez Signed-off-by: Dodji Seketeli --- diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index b4b957d2..e0b8bfb1 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -1194,7 +1194,7 @@ build_array_ctf_range(reader *rdr, ctf_dict_t *dic, upper_bound.set_unsigned(nelems > 0 ? nelems - 1 : 0U); /* for VLAs number of array elements is 0 */ - if (upper_bound.get_unsigned_value() == 0) + if (upper_bound.get_unsigned_value() == 0 && nelems == 0) is_infinite = true; subrange.reset(new array_type_def::subrange_type(rdr->env(), diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index d04ecf3f..e994aff3 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -716,6 +716,9 @@ test-read-ctf/test-const-array.o \ test-read-ctf/test-array-mdimension.abi \ test-read-ctf/test-array-mdimension.c \ test-read-ctf/test-array-mdimension.o \ +test-read-ctf/test-array-size.abi \ +test-read-ctf/test-array-size.c \ +test-read-ctf/test-array-size.o \ \ test-annotate/test0.abi \ test-annotate/test1.abi \ diff --git a/tests/data/test-read-ctf/test-array-size.abi b/tests/data/test-read-ctf/test-array-size.abi new file mode 100644 index 00000000..3fbc65b6 --- /dev/null +++ b/tests/data/test-read-ctf/test-array-size.abi @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-array-size.c b/tests/data/test-read-ctf/test-array-size.c new file mode 100644 index 00000000..fe2f3fef --- /dev/null +++ b/tests/data/test-read-ctf/test-array-size.c @@ -0,0 +1,4 @@ +/* gcc -gctf -c test-array-size.c -o test-array-size.o */ +char foo[2]; +char bar[1]; +char baz[0]; diff --git a/tests/data/test-read-ctf/test-array-size.o b/tests/data/test-read-ctf/test-array-size.o new file mode 100644 index 00000000..8e4d8b14 Binary files /dev/null and b/tests/data/test-read-ctf/test-array-size.o differ diff --git a/tests/data/test-read-ctf/test9.o.abi b/tests/data/test-read-ctf/test9.o.abi index 9f5a7466..5c89f821 100644 --- a/tests/data/test-read-ctf/test9.o.abi +++ b/tests/data/test-read-ctf/test9.o.abi @@ -7,8 +7,8 @@ - - + + diff --git a/tests/test-read-ctf.cc b/tests/test-read-ctf.cc index f3d46118..236ccbf2 100644 --- a/tests/test-read-ctf.cc +++ b/tests/test-read-ctf.cc @@ -381,6 +381,15 @@ static InOutSpec in_out_specs[] = "output/test-read-ctf/test-array-mdimension.abi", "--ctf", }, + { + "data/test-read-ctf/test-array-size.o", + "", + "", + SEQUENCE_TYPE_ID_STYLE, + "data/test-read-ctf/test-array-size.abi", + "output/test-read-ctf/test-array-size.abi", + "--ctf", + }, // This should be the last entry. {NULL, NULL, NULL, SEQUENCE_TYPE_ID_STYLE, NULL, NULL, NULL} };