Bug 57141 - Cannot change attributes of USE-associated intrinsic
Summary: Cannot change attributes of USE-associated intrinsic
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-05-02 08:13 UTC by Roger Ferrer Ibanez
Modified: 2021-03-18 17:50 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.2, 4.3.4, 4.5.3, 4.6.3, 4.7.3, 4.8.0, 4.9.0
Last reconfirmed: 2013-05-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Ferrer Ibanez 2013-05-02 08:13:34 UTC
Hi,

gfortran-4.8 (and 4.7 as well and possibly earlier versions too) complain with this snippet.

The error message is not emitted if the declaration of R is uncommented.

! -- test.f90
MODULE M
    INTRINSIC :: NULL
    !! Uncommenting the following statement
    !! causes the error go away
    ! REAL, POINTER :: R(:) => NULL()
END MODULE M

MODULE M_INTERN
    USE M
    IMPLICIT NONE
    REAL, POINTER :: ARR(:) => NULL()
END MODULE M_INTERN
! -- end of test.f90

$ gfortran -c test.f90
test.f90:12.37:

    REAL, POINTER :: ARR(:) => NULL()
                                     1
Error: Cannot change attributes of USE-associated symbol null at (1)

Kind regards,
Comment 1 Dominique d'Humieres 2013-05-02 11:13:01 UTC
Confirmed from 4.3.1 to trunk.
Comment 2 Tobias Burnus 2013-05-03 08:59:48 UTC
decl.c's gfc_match_null has:

  gfc_intrinsic_symbol (sym);

  if (sym->attr.proc != PROC_INTRINSIC
      && (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL)
          || !gfc_add_function (&sym->attr, sym->name, NULL)))
    return MATCH_ERROR;

Failing is the call to gfc_add_procedure.

Here,
  attr.proc = PROC_UNKNOWN
  attr.intrinsic = 1
  attr.use_assoc = 1
  attr.if_source = IFSRC_DECL


Possible patch?

--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1705,2 +1705,3 @@ gfc_match_null (gfc_expr **result)
   if (sym->attr.proc != PROC_INTRINSIC
+      && !(sym->attr.use_assoc && sym->attr.intrinsic)
       && (!gfc_add_procedure(&sym->attr, PROC_INTRINSIC, sym->name, NULL)
Comment 3 Tobias Burnus 2013-05-05 14:04:42 UTC
Author: burnus
Date: Sun May  5 14:01:38 2013
New Revision: 198609

URL: http://gcc.gnu.org/viewcvs?rev=198609&root=gcc&view=rev
Log:
2013-05-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57141
        * decl.c (gfc_match_null): Permit use-associated
        NULL intrinsic.

2013-05-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57141
        * gfortran.dg/null_8.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/null_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Tobias Burnus 2013-05-05 14:05:04 UTC
FIXED on the trunk (GCC 4.9).

Thanks for the report!
Comment 5 Antonio 2021-03-16 10:29:29 UTC
I am experiencing this problem in gfortran from gcc version 10.2.0 and the same workaround also works. It seems to be a regression.
Comment 6 Tobias Burnus 2021-03-16 11:19:02 UTC
(In reply to Antonio from comment #5)
> I am experiencing this problem in gfortran from gcc version 10.2.0 and the
> same workaround also works. It seems to be a regression.

Hi Antonio.

Do you use exactly the program from the original comment 0 – or some other program? That program works here with mainline (GCC 11) and a GCC 10.2.0.

Additionally, exactly that program is part of the regression testsuite since 2013, hence, issues would show up, but don't.

Thus, I assume that you have a slightly different program. If so, can you please open a new PR (problem report) – and include/attach your failing variant?
Comment 7 Antonio 2021-03-18 17:50:56 UTC
Ok, I have created the following bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99651