public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>,
	Bernhard Reutner-Fischer <aldot@gcc.gnu.org>,
	gfortran ML <fortran@gcc.gnu.org>
Subject: [PATCH 1/2] Fortran: Cleanup struct ext_attr_t
Date: Thu, 10 Nov 2022 11:20:30 +0100	[thread overview]
Message-ID: <20221110102031.1366016-2-aldot@gcc.gnu.org> (raw)
In-Reply-To: <20221110102031.1366016-1-aldot@gcc.gnu.org>

Tiny cleanup opportunity since we now have ext_attr_args in
struct symbol_attribute.
Bootstrapped and regtested on x86_64-unknown-linux with no new
regressions.
Ok for trunk if the prerequisite was approved ([PATCH 2/2] Fortran: add
attribute target_clones) ?

gcc/fortran/ChangeLog:

	* gfortran.h (struct ext_attr_t): Remove middle_end_name.
	* trans-decl.cc (add_attributes_to_decl): Move building
	tree_list to ...
	* decl.cc (gfc_match_gcc_attributes): ... here. Add the attribute to
	the tree_list for the middle end.

Cc: gfortran ML <fortran@gcc.gnu.org>
---
 gcc/fortran/decl.cc       | 35 +++++++++++++++++++++++------------
 gcc/fortran/gfortran.h    |  1 -
 gcc/fortran/trans-decl.cc | 13 +------------
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 3a619dbdd34..d312d4812b6 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -11802,15 +11802,15 @@ gfc_match_gcc_attribute_args (bool require_string, bool allow_multiple)
 }
 
 const ext_attr_t ext_attr_list[] = {
-  { "dllimport",    EXT_ATTR_DLLIMPORT,    "dllimport" },
-  { "dllexport",    EXT_ATTR_DLLEXPORT,    "dllexport" },
-  { "cdecl",        EXT_ATTR_CDECL,        "cdecl"     },
-  { "stdcall",      EXT_ATTR_STDCALL,      "stdcall"   },
-  { "fastcall",     EXT_ATTR_FASTCALL,     "fastcall"  },
-  { "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL        },
-  { "deprecated",   EXT_ATTR_DEPRECATED,   NULL	       },
-  { "target_clones",EXT_ATTR_TARGET_CLONES,NULL	       },
-  { NULL,           EXT_ATTR_LAST,         NULL        }
+  { "dllimport",    EXT_ATTR_DLLIMPORT     },
+  { "dllexport",    EXT_ATTR_DLLEXPORT     },
+  { "cdecl",        EXT_ATTR_CDECL         },
+  { "stdcall",      EXT_ATTR_STDCALL       },
+  { "fastcall",     EXT_ATTR_FASTCALL,     },
+  { "no_arg_check", EXT_ATTR_NO_ARG_CHECK  },
+  { "deprecated",   EXT_ATTR_DEPRECATED    },
+  { "target_clones",EXT_ATTR_TARGET_CLONES },
+  { NULL,           EXT_ATTR_LAST          }
 };
 
 /* Match a !GCC$ ATTRIBUTES statement of the form:
@@ -11854,6 +11854,20 @@ gfc_match_gcc_attributes (void)
 	  gfc_error ("Unknown attribute in !GCC$ ATTRIBUTES statement at %C");
 	  return MATCH_ERROR;
 	}
+
+      /* Check for errors.
+	 If everything is fine, add attributes the middle-end has to know about.
+       */
+      if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus))
+	return MATCH_ERROR;
+      else if (id == EXT_ATTR_DLLIMPORT
+	       || id == EXT_ATTR_DLLEXPORT
+	       || id == EXT_ATTR_CDECL
+	       || id == EXT_ATTR_STDCALL
+	       || id == EXT_ATTR_FASTCALL)
+	attr.ext_attr_args
+	  = chainon (attr.ext_attr_args,
+		     build_tree_list (get_identifier (name), NULL_TREE));
       else if (id == EXT_ATTR_TARGET_CLONES)
 	{
 	  attr_args
@@ -11864,9 +11878,6 @@ gfc_match_gcc_attributes (void)
 			 build_tree_list (get_identifier (name), attr_args));
 	}
 
-      if (!gfc_add_ext_attribute (&attr, (ext_attr_id_t)id, &gfc_current_locus))
-	return MATCH_ERROR;
-
       gfc_gobble_whitespace ();
       ch = gfc_next_ascii_char ();
       if (ch == ':')
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index ce0cb61e647..c4deec0d5b8 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -847,7 +847,6 @@ typedef struct
 {
   const char *name;
   unsigned id;
-  const char *middle_end_name;
 }
 ext_attr_t;
 
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 24cbd4cda28..7d5d2bdbb37 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1436,18 +1436,7 @@ gfc_add_assign_aux_vars (gfc_symbol * sym)
 static tree
 add_attributes_to_decl (symbol_attribute sym_attr, tree list)
 {
-  unsigned id;
-  tree attr;
-
-  for (id = 0; id < EXT_ATTR_NUM; id++)
-    if (sym_attr.ext_attr & (1 << id) && ext_attr_list[id].middle_end_name)
-      {
-	attr = build_tree_list (
-		 get_identifier (ext_attr_list[id].middle_end_name),
-				 NULL_TREE);
-	list = chainon (list, attr);
-      }
-  /* Add attribute args.  */
+  /* Add attributes and their arguments.  */
   if (sym_attr.ext_attr_args != NULL_TREE)
     list = chainon (list, sym_attr.ext_attr_args);
 
-- 
2.38.1


  reply	other threads:[~2022-11-10 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 10:20 [PATCH 0/2] Fortran: Add attribute flatten Bernhard Reutner-Fischer
2022-11-10 10:20 ` Bernhard Reutner-Fischer [this message]
2022-11-21 11:08   ` [PATCH 1/2] Fortran: Cleanup struct ext_attr_t Mikael Morin
2022-11-21 20:34     ` Bernhard Reutner-Fischer
2022-11-22 11:52       ` Mikael Morin
2022-11-10 10:20 ` [PATCH 2/2] Fortran: Add attribute flatten Bernhard Reutner-Fischer
2022-11-21 11:24   ` Mikael Morin
2022-11-21 20:13     ` Bernhard Reutner-Fischer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110102031.1366016-2-aldot@gcc.gnu.org \
    --to=rep.dot.nop@gmail.com \
    --cc=aldot@gcc.gnu.org \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).