diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-27 17:42:41 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-28 22:17:04 +0100 |
| commit | 813fb036ba9015c6744c85bf7c2e13ca1f4afff8 (patch) | |
| tree | 7d3b5519094c272ab9bec327707532e2b8b90a5d /validation | |
| parent | 69a789a78d4e64052628307f25310e195a50f5ee (diff) | |
| download | sparse-dev-813fb036ba9015c6744c85bf7c2e13ca1f4afff8.tar.gz | |
fix implicit size of unsized arrays
When an array is declared without an explicit size. In this case,
an implicit size is given by the number of elements in its initializer
if one is present.
Currently, in sparse, this implicit size is only associated with
the node corresponding to the initializer while the base type is
left unsized. This is a problem because the node is only used for
the modifiers & address-space and the bitsize of nodes are expected
to match the size of the basetype. So this implicit size can be used
for when directly using the bit_size of the node but the array is
still left, essentially unsized.
It's not enough to simply copy the bitsize of the node to the base
type because:
1) sym->array_size need to be set in the node & the base type.
2) the base type can be shared between several declarators.
It's thus needed to copy the the base type to unshare it before
setting the sym->array_size.
Reported-by: Dibyendu Majumdar <mobile@majumdar.org.uk>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/array-implicit-size.c | 26 | ||||
| -rw-r--r-- | validation/constexpr-preop.c | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/validation/array-implicit-size.c b/validation/array-implicit-size.c new file mode 100644 index 00000000..7011008b --- /dev/null +++ b/validation/array-implicit-size.c @@ -0,0 +1,26 @@ +static int array[] = { 0, 1, 2, 3, }; +_Static_assert(sizeof(array) == 4 * sizeof(int), "size of array"); + + +typedef int table_t[]; +static table_t tbl2 = { + 0, + 1, +}; +_Static_assert(sizeof(tbl2) == 2 * sizeof(int), "size of tbl2"); + +static table_t tbl1 = { + 0, +}; +_Static_assert(sizeof(tbl1) == 1 * sizeof(int), "size of tbl1"); + +static table_t tbl3 = { + 0, + 1, + 2, +}; +_Static_assert(sizeof(tbl3) == 3 * sizeof(int), "size of tbl3"); + +/* + * check-name: array-implicit-size + */ diff --git a/validation/constexpr-preop.c b/validation/constexpr-preop.c index 4b54defd..3fd57745 100644 --- a/validation/constexpr-preop.c +++ b/validation/constexpr-preop.c @@ -25,5 +25,7 @@ constexpr-preop.c:8:4: error: bad constant expression constexpr-preop.c:9:4: error: bad constant expression constexpr-preop.c:14:4: error: bad integer constant expression constexpr-preop.c:15:4: error: bad integer constant expression +constexpr-preop.c:10:4: error: index out of bounds in initializer +constexpr-preop.c:11:4: error: index out of bounds in initializer * check-error-end */ |
