[gcc r11-5267] Dump type attributes in dump_function_to_file.

Martin Sebor msebor@gcc.gnu.org
Tue Nov 24 00:19:38 GMT 2020


https://gcc.gnu.org/g:6692c400f207c68fb11b44182ae127856e8b9ad3

commit r11-5267-g6692c400f207c68fb11b44182ae127856e8b9ad3
Author: Martin Sebor <msebor@redhat.com>
Date:   Mon Nov 23 17:15:54 2020 -0700

    Dump type attributes in dump_function_to_file.
    
    gcc/ChangeLog:
    
            * tree-cfg.c (dump_function_to_file): Print type attributes
            and return type.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/attr-access-5.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/attr-access-5.c | 16 ++++++++++++++++
 gcc/tree-cfg.c                       | 17 +++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/attr-access-5.c b/gcc/testsuite/gcc.dg/attr-access-5.c
new file mode 100644
index 00000000000..e78b3602ade
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/attr-access-5.c
@@ -0,0 +1,16 @@
+/* { dg-do compile }
+   { dg-options "-fdump-tree-gimple" } */
+
+__attribute__ ((aligned (32)))
+__attribute__ ((access (write_only, 2, 1)))
+void f (int n, void *p)
+{
+  __builtin_memset (p, 0, n);
+}
+
+/* Verify the DECL_ATTRIBUTE "aligned" is mentioned:
+   { dg-final { scan-tree-dump "__attribute__\\(\\(aligned" "gimple" } }
+   and the TYPE_ATTRIBUTE "access" is also mentioned:
+   { dg-final { scan-tree-dump "__attribute__\\(\\(access" "gimple" } }
+   and the function signature including its return type is mentioned:
+   { dg-final { scan-tree-dump "void f *\\(int n, void *\\* *p\\)" "gimple" } } */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index aaf390bda42..f59a0c05200 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -7972,14 +7972,19 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 		  && decl_is_tm_clone (fndecl));
   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
 
-  if (DECL_ATTRIBUTES (fndecl) != NULL_TREE)
+  tree fntype = TREE_TYPE (fndecl);
+  tree attrs[] = { DECL_ATTRIBUTES (fndecl), TYPE_ATTRIBUTES (fntype) };
+
+  for (int i = 0; i != 2; ++i)
     {
+      if (!attrs[i])
+	continue;
+
       fprintf (file, "__attribute__((");
 
       bool first = true;
       tree chain;
-      for (chain = DECL_ATTRIBUTES (fndecl); chain;
-	   first = false, chain = TREE_CHAIN (chain))
+      for (chain = attrs[i]; chain; first = false, chain = TREE_CHAIN (chain))
 	{
 	  if (!first)
 	    fprintf (file, ", ");
@@ -8032,7 +8037,11 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 	}
     }
   else
-    fprintf (file, "%s %s(", function_name (fun), tmclone ? "[tm-clone] " : "");
+    {
+      print_generic_expr (file, TREE_TYPE (fntype), dump_flags);
+      fprintf (file, " %s %s(", function_name (fun),
+	       tmclone ? "[tm-clone] " : "");
+    }
 
   arg = DECL_ARGUMENTS (fndecl);
   while (arg)


More information about the Gcc-cvs mailing list