From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 5DD023857C45; Fri, 24 Feb 2023 21:54:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DD023857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677275694; bh=RYVuP06RW7k6VlD+/joW0SmrjSB5bCW3kCyshmKCxoQ=; h=From:To:Subject:Date:From; b=ge1nTxi7/xNtmZUjk4IQnClat/NcImLP07wMmyPIg+OaAYv8QByea4PPFBp0ctLSF HvCFJnIvEkncNQ/VvXKb+eFFnh5Ka1YB/kHyeDBBrnnyjHj67W1T48IaOuJpY/ZZPI 5paUm7ZIvbceiS4buOi8QcdIVpjqnHAAvR3cTkSo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6338] Fortran: Add support for WEAK attribute for variables X-Act-Checkin: gcc X-Git-Author: Rimvydas Jasinskas X-Git-Refname: refs/heads/master X-Git-Oldrev: 24c9edfa73632276d7698c103f35833f29804d98 X-Git-Newrev: bcbeebc498126c50d73809ec8a4bd0bff27ee97b Message-Id: <20230224215454.5DD023857C45@sourceware.org> Date: Fri, 24 Feb 2023 21:54:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bcbeebc498126c50d73809ec8a4bd0bff27ee97b commit r13-6338-gbcbeebc498126c50d73809ec8a4bd0bff27ee97b Author: Rimvydas Jasinskas Date: Fri Feb 24 04:41:00 2023 +0000 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 and local variables. gcc/testsuite/ChangeLog: * gfortran.dg/weak-2.f90: New test. * gfortran.dg/weak-3.f90: New test. Signed-off-by: Rimvydas Jasinskas Diff: --- gcc/fortran/trans-decl.cc | 14 ++++++++++++++ gcc/testsuite/gfortran.dg/weak-2.f90 | 26 ++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/weak-3.f90 | 30 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index ff64588b9a8..474920966ec 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,16 @@ 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)) + { + if (sym->attr.dummy) + gfc_error ("Symbol %qs at %L has the WEAK attribute but is a " + "dummy argument", sym->name, &sym->declared_at); + else + gfc_error ("Symbol %qs at %L has the WEAK attribute but is a " + "local variable", sym->name, &sym->declared_at); + } + 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..3e0e877e903 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/weak-2.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! { dg-require-weak "" } +! { dg-skip-if "" { x86_64-*-mingw* } } +! { dg-skip-if "" { nvptx-*-* } } + +! 1. +! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?__foo_MOD_abc" } } +module foo +implicit none +!GCC$ ATTRIBUTES weak :: abc +real :: abc(7) +end module + +! 2. +! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?impl1" } } +integer function impl1() +implicit none +!GCC$ ATTRIBUTES weak :: impl1 +end function + +! 3. +! { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?bar__" } } +integer function impl2() bind(c,name='bar__') +implicit none +!GCC$ ATTRIBUTES weak :: impl2 +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..cfa845921ff --- /dev/null +++ b/gcc/testsuite/gfortran.dg/weak-3.f90 @@ -0,0 +1,30 @@ +! { dg-do compile } +! { dg-require-weak "" } + +! 1. +program foo1 ! { dg-error "weak declaration of 'foo1' must be public" "" } +implicit none +!GCC$ ATTRIBUTES weak :: foo1 +end program + +! 2. +subroutine foo2 +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 + +! 3. +subroutine foo3(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