From 23f2660fb17e1160870fd00fe9aa73c8554c74b5 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 17 Apr 2016 17:38:28 +0000 Subject: c-ada-spec.c (get_underlying_decl): Return the typedef, if any. * c-ada-spec.c (get_underlying_decl): Return the typedef, if any. (dump_generic_ada_node) : Clean up handling of access to incomplete types. (dump_nested_type): Remove redundant tests and tidy up. (print_ada_declaration): Also set TREE_VISITED on the declaration of a type which is the typedef of an original type. From-SVN: r235084 --- gcc/c-family/ChangeLog | 9 +++ gcc/c-family/c-ada-spec.c | 88 ++++++++++++---------------- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/c-c++-common/dump-ada-spec-3.c | 12 ++++ gcc/testsuite/c-c++-common/dump-ada-spec-4.c | 12 ++++ 5 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/dump-ada-spec-3.c create mode 100644 gcc/testsuite/c-c++-common/dump-ada-spec-4.c (limited to 'gcc') diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ec79edb..5cf0e84 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2016-04-17 Eric Botcazou + + * c-ada-spec.c (get_underlying_decl): Return the typedef, if any. + (dump_generic_ada_node) : Clean up handling of access + to incomplete types. + (dump_nested_type): Remove redundant tests and tidy up. + (print_ada_declaration): Also set TREE_VISITED on the declaration of + a type which is the typedef of an original type. + 2016-04-15 Marek Polacek PR c/70651 diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c index 75a25cc..e33fdff 100644 --- a/gcc/c-family/c-ada-spec.c +++ b/gcc/c-family/c-ada-spec.c @@ -892,25 +892,22 @@ static const char *c_duplicates[] = { static tree get_underlying_decl (tree type) { - tree decl = NULL_TREE; - - if (type == NULL_TREE) + if (!type) return NULL_TREE; /* type is a declaration. */ if (DECL_P (type)) - decl = type; + return type; /* type is a typedef. */ if (TYPE_P (type) && TYPE_NAME (type) && DECL_P (TYPE_NAME (type))) - decl = TYPE_NAME (type); + return TYPE_NAME (type); /* TYPE_STUB_DECL has been set for type. */ - if (TYPE_P (type) && TYPE_STUB_DECL (type) && - DECL_P (TYPE_STUB_DECL (type))) - decl = TYPE_STUB_DECL (type); + if (TYPE_P (type) && TYPE_STUB_DECL (type)) + return TYPE_STUB_DECL (type); - return decl; + return NULL_TREE; } /* Return whether TYPE has static fields. */ @@ -2083,37 +2080,25 @@ dump_generic_ada_node (pretty_printer *buffer, tree node, tree type, int spc, } else { - /* For now, handle all access-to-access or - access-to-unknown-structs as opaque system.address. */ - tree type_name = TYPE_NAME (TREE_TYPE (node)); - const_tree typ2 = !type || - DECL_P (type) ? type : TYPE_NAME (type); - const_tree underlying_type = - get_underlying_decl (TREE_TYPE (node)); + tree decl = get_underlying_decl (TREE_TYPE (node)); + tree enclosing_decl = get_underlying_decl (type); + /* For now, handle access-to-access, access-to-empty-struct + or access-to-incomplete as opaque system.address. */ if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE - /* Pointer to pointer. */ - || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (node)) - && (!underlying_type - || !TYPE_FIELDS (TREE_TYPE (underlying_type)))) - /* Pointer to opaque structure. */ - - || underlying_type == NULL_TREE - || (!typ2 - && !TREE_VISITED (underlying_type) - && !TREE_VISITED (type_name) - && !is_tagged_type (TREE_TYPE (node)) - && DECL_SOURCE_FILE (underlying_type) - == source_file_base) - || (type_name && typ2 - && DECL_P (underlying_type) - && DECL_P (typ2) - && decl_sloc (underlying_type, true) - > decl_sloc (typ2, true) - && DECL_SOURCE_FILE (underlying_type) - == DECL_SOURCE_FILE (typ2))) + && !TYPE_FIELDS (TREE_TYPE (node))) + || !decl + || (!enclosing_decl + && !TREE_VISITED (decl) + && DECL_SOURCE_FILE (decl) == source_file_base) + || (enclosing_decl + && !TREE_VISITED (decl) + && DECL_SOURCE_FILE (decl) + == DECL_SOURCE_FILE (enclosing_decl) + && decl_sloc (decl, true) + > decl_sloc (enclosing_decl, true))) { if (package_prefix) { @@ -2160,13 +2145,11 @@ dump_generic_ada_node (pretty_printer *buffer, tree node, tree type, int spc, } if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (node)) && type_name) - dump_generic_ada_node - (buffer, type_name, - TREE_TYPE (node), spc, is_access, true); + dump_generic_ada_node (buffer, type_name, TREE_TYPE (node), + spc, is_access, true); else - dump_generic_ada_node - (buffer, TREE_TYPE (node), TREE_TYPE (node), - spc, 0, true); + dump_generic_ada_node (buffer, TREE_TYPE (node), + TREE_TYPE (node), spc, 0, true); } } } @@ -2507,13 +2490,12 @@ dump_nested_type (pretty_printer *buffer, tree field, tree t, tree parent, decl = get_underlying_decl (tmp); if (decl - && DECL_P (decl) - && decl_sloc (decl, true) > decl_sloc (t, true) - && DECL_SOURCE_FILE (decl) == DECL_SOURCE_FILE (t) - && !TREE_VISITED (decl) && !DECL_IS_BUILTIN (decl) && (!RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)) - || TYPE_FIELDS (TREE_TYPE (decl)))) + || TYPE_FIELDS (TREE_TYPE (decl))) + && !TREE_VISITED (decl) + && DECL_SOURCE_FILE (decl) == DECL_SOURCE_FILE (t) + && decl_sloc (decl, true) > decl_sloc (t, true)) { /* Generate forward declaration. */ pp_string (buffer, "type "); @@ -2529,10 +2511,7 @@ dump_nested_type (pretty_printer *buffer, tree field, tree t, tree parent, while (TREE_CODE (tmp) == ARRAY_TYPE) tmp = TREE_TYPE (tmp); decl = get_underlying_decl (tmp); - if (decl - && DECL_P (decl) - && !DECL_NAME (decl) - && !TREE_VISITED (decl)) + if (decl && !DECL_NAME (decl) && !TREE_VISITED (decl)) { /* Generate full declaration. */ dump_nested_type (buffer, decl, t, parent, spc); @@ -2682,7 +2661,10 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) casing), then ignore the second type. */ if (type_name (typ) == type_name (TREE_TYPE (t)) || !strcasecmp (type_name (typ), type_name (TREE_TYPE (t)))) - return 0; + { + TREE_VISITED (t) = 1; + return 0; + } INDENT (spc); @@ -2703,6 +2685,8 @@ print_ada_declaration (pretty_printer *buffer, tree t, tree type, int spc) dump_generic_ada_node (buffer, typ, type, spc, false, true); pp_semicolon (buffer); } + + TREE_VISITED (t) = 1; return 1; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 79b6afa..8f16407 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-04-17 Eric Botcazou + + * c-c++-common/dump-ada-spec-3.c: New test. + * c-c++-common/dump-ada-spec-4.c: Likewise. + 2016-04-17 Tom de Vries PR other/70183 diff --git a/gcc/testsuite/c-c++-common/dump-ada-spec-3.c b/gcc/testsuite/c-c++-common/dump-ada-spec-3.c new file mode 100644 index 0000000..19cfd00 --- /dev/null +++ b/gcc/testsuite/c-c++-common/dump-ada-spec-3.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-ada-spec" } */ + +typedef struct +{ + int a; +} Message_Type; + +extern int Func(const Message_Type *in, Message_Type *out); + +/* { dg-final { scan-ada-spec-not "System.Address" } } */ +/* { dg-final { cleanup-ada-spec } } */ diff --git a/gcc/testsuite/c-c++-common/dump-ada-spec-4.c b/gcc/testsuite/c-c++-common/dump-ada-spec-4.c new file mode 100644 index 0000000..d2a45a6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/dump-ada-spec-4.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-ada-spec" } */ + +typedef struct Message_Type +{ + int a; +} Message_Type; + +extern int Func(const Message_Type *in, Message_Type *out); + +/* { dg-final { scan-ada-spec-not "System.Address" } } */ +/* { dg-final { cleanup-ada-spec } } */ -- cgit v1.1