diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2021-07-01 18:06:46 +0200 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2021-07-01 18:13:12 +0200 |
commit | a3d8860d6386cd12942bc0b1995765ea516297bd (patch) | |
tree | 94904be460b914f7de438e1c9884453e47f6ab5e /gcc | |
parent | 506c68e25fb6aea135468972dbc9d8abf816a443 (diff) | |
download | gcc-a3d8860d6386cd12942bc0b1995765ea516297bd.zip gcc-a3d8860d6386cd12942bc0b1995765ea516297bd.tar.gz gcc-a3d8860d6386cd12942bc0b1995765ea516297bd.tar.bz2 |
Improve packed record layout support with -fdump-ada-spec
We cannot fully support packed record layout in -fdump-ada-spec, as packing
in C and Ada does not behave the same, so we issue a warning. But simple
cases are OK and can actually be handled without much work.
gcc/c-family/
* c-ada-spec.c (packed_layout): New global variable.
(dump_ada_declaration): Set it upon seeing a packed record type.
Do not put the "aliased" keyword if it is set.
(dump_ada_structure): Add Pack aspect if it is set and clear it.
gcc/testsuite/
* c-c++-common/dump-ada-spec-14.c: Adjust dg-warning directive.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-ada-spec.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/dump-ada-spec-14.c | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index ea52be6..827bcc7 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -2038,6 +2038,7 @@ is_float128 (tree node) } static bool bitfield_used = false; +static bool packed_layout = false; /* Recursively dump in BUFFER Ada declarations corresponding to NODE of type TYPE. SPC is the indentation level. LIMITED_ACCESS indicates whether NODE @@ -2851,14 +2852,14 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) return 1; } - /* ??? Packed record layout is not supported. */ + /* Packed record layout is not fully supported. */ if (TYPE_PACKED (TREE_TYPE (t))) { - warning_at (DECL_SOURCE_LOCATION (t), 0, - "unsupported record layout"); + warning_at (DECL_SOURCE_LOCATION (t), 0, "packed layout"); pp_string (buffer, "pragma Compile_Time_Warning (True, "); - pp_string (buffer, "\"probably incorrect record layout\");"); + pp_string (buffer, "\"packed layout may be incorrect\");"); newline_and_indent (buffer, spc); + packed_layout = true; } if (orig && TYPE_NAME (orig)) @@ -2951,7 +2952,8 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) pp_string (buffer, " : "); - if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) != POINTER_TYPE) + if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) != POINTER_TYPE + && !packed_layout) pp_string (buffer, "aliased "); if (TYPE_NAME (TREE_TYPE (t))) @@ -3185,7 +3187,8 @@ dump_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE && (TYPE_NAME (TREE_TYPE (t)) || (TREE_CODE (TREE_TYPE (t)) != INTEGER_TYPE - && TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE))) + && TREE_CODE (TREE_TYPE (t)) != ENUMERAL_TYPE)) + && !packed_layout) pp_string (buffer, "aliased "); if (TREE_READONLY (t) && TREE_CODE (t) != FIELD_DECL) @@ -3352,7 +3355,7 @@ dump_ada_structure (pretty_printer *buffer, tree node, tree type, bool nested, pp_string (buffer, "Unchecked_Union => True"); } - if (bitfield_used) + if (bitfield_used || packed_layout) { char buf[32]; pp_comma (buffer); @@ -3363,6 +3366,7 @@ dump_ada_structure (pretty_printer *buffer, tree node, tree type, bool nested, sprintf (buf, "Alignment => %d", TYPE_ALIGN (node) / BITS_PER_UNIT); pp_string (buffer, buf); bitfield_used = false; + packed_layout = false; } if (nested) diff --git a/gcc/testsuite/c-c++-common/dump-ada-spec-14.c b/gcc/testsuite/c-c++-common/dump-ada-spec-14.c index bfdec61..291eea8 100644 --- a/gcc/testsuite/c-c++-common/dump-ada-spec-14.c +++ b/gcc/testsuite/c-c++-common/dump-ada-spec-14.c @@ -1,7 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-fdump-ada-spec" } */ -struct __attribute__((packed)) S /* { dg-warning "unsupported record layout" } */ +struct __attribute__((packed)) S /* { dg-warning "packed layout" } */ { char c; int t; |