diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2024-05-28 18:34:09 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2024-05-31 16:42:52 +0000 |
commit | bb49b6e4f55891d0d8b596845118f40df6ae72a5 (patch) | |
tree | e870389567207f05db4006bc0370fd8a26d64c68 /gcc/c/c-tree.h | |
parent | f824acd0e807546a733c122ab6340f18cef88766 (diff) | |
download | gcc-bb49b6e4f55891d0d8b596845118f40df6ae72a5.zip gcc-bb49b6e4f55891d0d8b596845118f40df6ae72a5.tar.gz gcc-bb49b6e4f55891d0d8b596845118f40df6ae72a5.tar.bz2 |
Convert references with "counted_by" attributes to/from .ACCESS_WITH_SIZE.
Including the following changes:
* The definition of the new internal function .ACCESS_WITH_SIZE
in internal-fn.def.
* C FE converts every reference to a FAM with a "counted_by" attribute
to a call to the internal function .ACCESS_WITH_SIZE.
(build_component_ref in c_typeck.cc)
This includes the case when the object is statically allocated and
initialized.
In order to make this working, the routine digest_init in c-typeck.cc
is updated to fold calls to .ACCESS_WITH_SIZE to its first argument
when require_constant is TRUE.
However, for the reference inside "offsetof", the "counted_by" attribute is
ignored since it's not useful at all.
(c_parser_postfix_expression in c/c-parser.cc)
In addtion to "offsetof", for the reference inside operator "typeof" and
"alignof", we ignore counted_by attribute too.
When building ADDR_EXPR for the .ACCESS_WITH_SIZE in C FE,
replace the call with its first argument.
* Convert every call to .ACCESS_WITH_SIZE to its first argument.
(expand_ACCESS_WITH_SIZE in internal-fn.cc)
* Provide the utility routines to check the call is .ACCESS_WITH_SIZE and
get the reference from the call to .ACCESS_WITH_SIZE.
(is_access_with_size_p and get_ref_from_access_with_size in tree.cc)
gcc/c/ChangeLog:
* c-parser.cc (c_parser_postfix_expression): Ignore the counted-by
attribute when build_component_ref inside offsetof operator.
* c-tree.h (build_component_ref): Add one more parameter.
* c-typeck.cc (build_counted_by_ref): New function.
(build_access_with_size_for_counted_by): New function.
(build_component_ref): Check the counted-by attribute and build
call to .ACCESS_WITH_SIZE.
(build_unary_op): When building ADDR_EXPR for
.ACCESS_WITH_SIZE, use its first argument.
(lvalue_p): Accept call to .ACCESS_WITH_SIZE.
(digest_init): Fold call to .ACCESS_WITH_SIZE to its first
argument when require_constant is TRUE.
gcc/ChangeLog:
* internal-fn.cc (expand_ACCESS_WITH_SIZE): New function.
* internal-fn.def (ACCESS_WITH_SIZE): New internal function.
* tree.cc (is_access_with_size_p): New function.
(get_ref_from_access_with_size): New function.
* tree.h (is_access_with_size_p): New prototype.
(get_ref_from_access_with_size): New prototype.
gcc/testsuite/ChangeLog:
* gcc.dg/flex-array-counted-by-2.c: New test.
Diffstat (limited to 'gcc/c/c-tree.h')
-rw-r--r-- | gcc/c/c-tree.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 531a7e8..56a33b8 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -779,7 +779,7 @@ extern void mark_exp_read (tree); extern tree composite_type (tree, tree); extern tree lookup_field (const_tree, tree); extern tree build_component_ref (location_t, tree, tree, location_t, - location_t); + location_t, bool = true); extern tree build_array_ref (location_t, tree, tree); extern tree build_omp_array_section (location_t, tree, tree, tree); extern tree build_external_ref (location_t, tree, bool, tree *); |