public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Rimvydas Jasinskas <rimvydasjas@gmail.com>
To: Harald Anlauf <anlauf@gmx.de>
Cc: Rimvydas Jasinskas via Fortran <fortran@gcc.gnu.org>
Subject: Re: Support for WEAK attribute, part 2
Date: Thu, 23 Feb 2023 15:55:45 +0200	[thread overview]
Message-ID: <CAFmAMQ0bzmO1bmCy_5men10qmmv2K9G6jRgSk6XnY+HW-VVtLA@mail.gmail.com> (raw)
In-Reply-To: <trinity-bb49b3d4-7455-4c7b-89d9-a9a857e68651-1676584221172@3c-app-gmx-bs44>

[-- Attachment #1: Type: text/plain, Size: 182 bytes --]

Thank you Harald, for the feedback!

Attached is part2 patch for weak variables support.  I'll post part3
patch for module-wide attribute support separately.

Best regards,
Rimvydas

[-- Attachment #2: 0001-Fortran-Add-support-for-WEAK-attribute-for-variables.patch --]
[-- Type: text/x-patch, Size: 6168 bytes --]

From fb1cf60d3fd7c6aa2d9787bb3af86f18e0178bf7 Mon Sep 17 00:00:00 2001
From: Rimvydas Jasinskas <rimvydas.jas@gmail.com>
Date: Thu, 23 Feb 2023 12:55:28 +0000
Subject: Fortran: Add support for WEAK attribute for variables

 Add the rest of the weak-*.f90 testcases.

gcc/fortran/ChangeLog:

	* trans-decl.cc (gfc_finish_var_decl): Apply attribute.
	(generate_local_decl): Add diagnostic for dummy or local variables.

gcc/testsuite/ChangeLog:

	* gfortran.dg/weak-2.f90: New test.
	* gfortran.dg/weak-3.f90: New test.
	* gfortran.dg/weak-4.f90: New test.
	* gfortran.dg/weak-5.f90: New test.
	* gfortran.dg/weak-6.f90: New test.
	* gfortran.dg/weak-7.f90: New test.
	* gfortran.dg/weak-8.f90: New test.

Signed-off-by: Rimvydas Jasinskas <rimvydas.jas@gmail.com>
---
 gcc/fortran/trans-decl.cc            |  9 +++++++++
 gcc/testsuite/gfortran.dg/weak-2.f90 |  9 +++++++++
 gcc/testsuite/gfortran.dg/weak-3.f90 |  9 +++++++++
 gcc/testsuite/gfortran.dg/weak-4.f90 | 10 ++++++++++
 gcc/testsuite/gfortran.dg/weak-5.f90 | 15 +++++++++++++++
 gcc/testsuite/gfortran.dg/weak-6.f90 |  6 ++++++
 gcc/testsuite/gfortran.dg/weak-7.f90 | 13 +++++++++++++
 gcc/testsuite/gfortran.dg/weak-8.f90 |  9 +++++++++
 8 files changed, 80 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/weak-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-6.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/weak-8.f90

diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index ff64588b9a8..24a85cf6043 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -814,6 +814,10 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
     set_decl_tls_model (decl, decl_default_tls_model (decl));
 
+  /* Mark weak variables.  */
+  if (sym->attr.ext_attr & (1 << EXT_ATTR_WEAK))
+    declare_weak (decl);
+
   gfc_finish_decl_attrs (decl, &sym->attr);
 }
 
@@ -5885,6 +5889,11 @@ generate_local_decl (gfc_symbol * sym)
       if (!sym->attr.dummy && !sym->ns->proc_name->attr.entry_master)
 	generate_dependency_declarations (sym);
 
+      if (sym->attr.ext_attr & (1 << EXT_ATTR_WEAK))
+	gfc_error ("Symbol %qs at %L has the WEAK attribute but is a %s",
+		   sym->name, &sym->declared_at, sym->attr.dummy
+		   ? "dummy argument" : "local variable");
+
       if (sym->attr.referenced)
 	gfc_get_symbol_decl (sym);
 
diff --git a/gcc/testsuite/gfortran.dg/weak-2.f90 b/gcc/testsuite/gfortran.dg/weak-2.f90
new file mode 100644
index 00000000000..0c948640c89
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-2.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+! { dg-skip-if "" { x86_64-*-mingw* } }
+! { dg-skip-if "" { nvptx-*-* } }
+! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?impl" } }
+integer function impl()
+implicit none
+!GCC$ ATTRIBUTES weak :: impl
+end function
diff --git a/gcc/testsuite/gfortran.dg/weak-3.f90 b/gcc/testsuite/gfortran.dg/weak-3.f90
new file mode 100644
index 00000000000..39ad299291b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-3.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+! { dg-skip-if "" { x86_64-*-mingw* } }
+! { dg-skip-if "" { nvptx-*-* } }
+! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?bar__" } }
+integer function impl() bind(c,name='bar__')
+implicit none
+!GCC$ ATTRIBUTES weak :: impl
+end function
diff --git a/gcc/testsuite/gfortran.dg/weak-4.f90 b/gcc/testsuite/gfortran.dg/weak-4.f90
new file mode 100644
index 00000000000..fef0233be8a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-4.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+! { dg-skip-if "" { x86_64-*-mingw* } }
+! { dg-skip-if "" { nvptx-*-* } }
+! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?__foo_MOD_abc" } }
+module foo
+implicit none
+!GCC$ ATTRIBUTES weak :: abc
+real :: abc(7)
+end module
diff --git a/gcc/testsuite/gfortran.dg/weak-5.f90 b/gcc/testsuite/gfortran.dg/weak-5.f90
new file mode 100644
index 00000000000..e48a8053570
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-5.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+! { dg-options "-Wall -Wextra" }
+module foo
+implicit none
+real :: a,b
+common /c/ a,b
+integer :: c
+! no error, common /c/ is not exported and variable 'c' has a mangled name
+!GCC$ ATTRIBUTES weak :: c
+contains
+ subroutine bar
+  c = 1
+ end subroutine
+end module
diff --git a/gcc/testsuite/gfortran.dg/weak-6.f90 b/gcc/testsuite/gfortran.dg/weak-6.f90
new file mode 100644
index 00000000000..bcdf4df78a6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-6.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+program foo  ! { dg-error "weak declaration of 'foo' must be public" "" }
+implicit none
+!GCC$ ATTRIBUTES weak :: foo
+end program
diff --git a/gcc/testsuite/gfortran.dg/weak-7.f90 b/gcc/testsuite/gfortran.dg/weak-7.f90
new file mode 100644
index 00000000000..9f8f71c2f36
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-7.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+subroutine foo
+implicit none
+contains
+ function dar() ! { dg-error "weak declaration of 'dar' must be public" "" }
+ integer :: dar
+!GCC$ ATTRIBUTES weak :: dar
+ end function
+ subroutine bar ! { dg-error "weak declaration of 'bar' must be public" "" }
+!GCC$ ATTRIBUTES weak :: bar
+ end subroutine
+end subroutine
diff --git a/gcc/testsuite/gfortran.dg/weak-8.f90 b/gcc/testsuite/gfortran.dg/weak-8.f90
new file mode 100644
index 00000000000..d4bfe221312
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/weak-8.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-require-weak "" }
+subroutine foo(n) ! { dg-error "has the WEAK attribute but is a dummy argument" "" }
+implicit none
+integer :: n
+!GCC$ ATTRIBUTES weak :: n
+real :: abc       ! { dg-error "has the WEAK attribute but is a local variable" "" }
+!GCC$ ATTRIBUTES weak :: abc
+end subroutine
-- 
2.39.2


  reply	other threads:[~2023-02-23 13:56 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-10  5:42 Support for NOINLINE attribute Rimvydas Jasinskas
2023-02-10  8:24 ` Steve Kargl
2023-02-10  8:38   ` Rimvydas Jasinskas
2023-02-10 18:53     ` Steve Kargl
2023-02-10 21:07 ` Harald Anlauf
2023-02-10 21:16   ` Steve Kargl
2023-02-10 22:16   ` Rimvydas Jasinskas
2023-02-11 21:26     ` Harald Anlauf
2023-02-12  6:59       ` Rimvydas Jasinskas
2023-02-12 21:28         ` Harald Anlauf
2023-02-13 17:50           ` Harald Anlauf
2023-02-14  9:35             ` nvptx: Adjust 'scan-assembler' in 'gfortran.dg/weak-1.f90' (was: Support for NOINLINE attribute) Thomas Schwinge
2023-02-14 19:55               ` Harald Anlauf
2023-02-15 20:58                 ` Support for WEAK attribute, part 2 Rimvydas Jasinskas
2023-02-16 21:50                   ` Harald Anlauf
2023-02-23 13:55                     ` Rimvydas Jasinskas [this message]
2023-02-23 20:53                       ` Harald Anlauf
2023-02-24  5:16                         ` Rimvydas Jasinskas
2023-02-24 22:03                           ` Harald Anlauf
2023-03-28 21:06                           ` Enable 'gfortran.dg/weak-2.f90' for nvptx target (was: Support for WEAK attribute, part 2) Thomas Schwinge
2023-02-18 20:35 ` Support for NOINLINE attribute Bernhard Reutner-Fischer
2023-02-24  7:19   ` Bernhard Reutner-Fischer
2023-02-24 12:02     ` Rimvydas Jasinskas

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=CAFmAMQ0bzmO1bmCy_5men10qmmv2K9G6jRgSk6XnY+HW-VVtLA@mail.gmail.com \
    --to=rimvydasjas@gmail.com \
    --cc=anlauf@gmx.de \
    --cc=fortran@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).