aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-decl.cc
diff options
context:
space:
mode:
authorMartin Uecker <uecker@tugraz.at>2024-06-23 23:14:33 +0200
committerMartin Uecker <uecker@gcc.gnu.org>2024-08-02 10:56:12 +0200
commit4b9ba9cee9511930411b7b53e1333e1b6b93078d (patch)
tree4290507da09807432ad5bf34c177834c964e5f5c /gcc/c/c-decl.cc
parent1fbce3252bc00b1678cdf62b8798a94962e99f76 (diff)
downloadgcc-4b9ba9cee9511930411b7b53e1333e1b6b93078d.zip
gcc-4b9ba9cee9511930411b7b53e1333e1b6b93078d.tar.gz
gcc-4b9ba9cee9511930411b7b53e1333e1b6b93078d.tar.bz2
c: Add support for byte arrays in C2Y
To get correct aliasing behavior requires that structures and unions that contain a byte array, i.e. an array of non-atomic character type (N3254), are marked with TYPE_TYPELESS_STORAGE. This change affects also earlier language modes. gcc/c/ * c-decl.cc (grokdeclarator, finish_struct): Set and propagate TYPE_TYPELESS_STORAGE. gcc/testsuite/ * gcc.dg/c2y-byte-alias-1.c: New test. * gcc.dg/c2y-byte-alias-2.c: New test. * gcc.dg/c2y-byte-alias-3.c: New test.
Diffstat (limited to 'gcc/c/c-decl.cc')
-rw-r--r--gcc/c/c-decl.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 97f1d346..8cef8f2 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -7502,12 +7502,18 @@ grokdeclarator (const struct c_declarator *declarator,
modify the shared type, so we gcc_assert (itype)
below. */
{
+ /* Identify typeless storage as introduced in C2Y
+ and supported also in earlier language modes. */
+ bool typeless = (char_type_p (type)
+ && !(type_quals & TYPE_QUAL_ATOMIC))
+ || (AGGREGATE_TYPE_P (type)
+ && TYPE_TYPELESS_STORAGE (type));
+
addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
type = build_qualified_type (type,
ENCODE_QUAL_ADDR_SPACE (as));
-
- type = build_array_type (type, itype);
+ type = build_array_type (type, itype, typeless);
}
if (type != error_mark_node)
@@ -9659,6 +9665,10 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
if (DECL_NAME (x)
|| RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)))
saw_named_field = true;
+
+ if (AGGREGATE_TYPE_P (TREE_TYPE (x))
+ && TYPE_TYPELESS_STORAGE (TREE_TYPE (x)))
+ TYPE_TYPELESS_STORAGE (t) = true;
}
detect_field_duplicates (fieldlist);
@@ -9859,6 +9869,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
TYPE_FIELDS (x) = TYPE_FIELDS (t);
TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
TYPE_TRANSPARENT_AGGR (x) = TYPE_TRANSPARENT_AGGR (t);
+ TYPE_TYPELESS_STORAGE (x) = TYPE_TYPELESS_STORAGE (t);
C_TYPE_FIELDS_READONLY (x) = C_TYPE_FIELDS_READONLY (t);
C_TYPE_FIELDS_VOLATILE (x) = C_TYPE_FIELDS_VOLATILE (t);
C_TYPE_FIELDS_NON_CONSTEXPR (x) = C_TYPE_FIELDS_NON_CONSTEXPR (t);