From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by sourceware.org (Postfix) with ESMTPS id BA431385783A for ; Fri, 4 Sep 2020 20:18:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA431385783A Received: by mail-wr1-x444.google.com with SMTP id w5so8345605wrp.8 for ; Fri, 04 Sep 2020 13:18:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=thsY5FbIYI0i/PkxLep6YwYz/AaUWY1h4/rLOxzmwhM=; b=ZXF4qv1AstsP/QPnurx6r3VLdRR1mtsOnJMayNRV5WgqkAtJppyYObAWGECDSzO1oz xIry4kHj1npkuRl8jm1Oa6adUcAoSE/OeHakEg0KUXVuS7tWik43y6ghG87EsW1NhXXj PMxOphTQvWvI5GWtLioXNNQxp8Kem0+y12E9V8utvjFrJ5va9lbsC4EBYudqJfw6xsfh GPTAUcVuu4bg1KK2HDFmpfP39e8X16d6MlwnRywJWoOk+qWbA5IZ9+tc4gJ+184r6TXQ ukDCXnz+Nz9ONosr84oMPvHIugEHJ/pmWB1tSM700wmBcb9Y1pCEQHpAkEp2LDqvtMzG 1aoA== X-Gm-Message-State: AOAM533+TXW3vUj4WSWUyKz+2gsy0R8rR+Z96ZN97MNFVTFUY4aSNhzp J5hdsH8WmOsF8vHG6Xz9ww6XYqrn6Y0Q5Q== X-Google-Smtp-Source: ABdhPJx+X8QcgXegR3lP1KG4ODArIEW9peKHp3P4h42alzQPbgo7goI7qkC9PTsDvHnkoOTi6Ydjow== X-Received: by 2002:adf:aad1:: with SMTP id i17mr9803672wrc.360.1599250724353; Fri, 04 Sep 2020 13:18:44 -0700 (PDT) Received: from ?IPv6:2a01:e34:ec28:8cb0:8d7a:83af:9605:a78b? ([2a01:e34:ec28:8cb0:8d7a:83af:9605:a78b]) by smtp.gmail.com with ESMTPSA id 92sm14603112wra.19.2020.09.04.13.18.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Sep 2020 13:18:43 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: Need help with vptr copy function calls From: FX In-Reply-To: <445460C6-726C-4AC1-B22F-C2D852A797A5@gmail.com> Date: Fri, 4 Sep 2020 22:18:43 +0200 Cc: Tobias Burnus Content-Transfer-Encoding: quoted-printable Message-Id: <692E87DD-BC29-406D-AE7F-C30D59343E80@gmail.com> References: <9B582636-C449-4240-A663-B7551AF6F805@gmail.com> <19fcd7e7-351c-b551-5bd9-7dca484b72d1@codesourcery.com> <445460C6-726C-4AC1-B22F-C2D852A797A5@gmail.com> To: fortran X-Mailer: Apple Mail (2.3608.120.23.2.1) X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2020 20:18:47 -0000 Hi again, There are apparently other functions with the same problem=E2=80=A6 so I = am wondering if this is possibly a wider issue. Take this code: ------------ module m implicit none type, abstract :: t1 logical :: l end type t1 type, extends(t1), abstract :: t2 integer :: i end type t2 type, extends(t2) :: t3 real :: x end type t3 contains subroutine s(u) class(t1), intent(in) :: u select type(u); class is(t2) select type(u); class is(t3) end select end select end subroutine s end module m program p use m implicit none type(t3) :: var =3D t3( l=3D.true. , i=3D2 , x=3D3.5 ) call s(var) end program p ------------ The select type construct is translated into series of =E2=80=9Cif = _gfortran_is_extension_of()=E2=80=9D. But the function call has the = wrong type (well, no type) for arguments. If you look into = gfc_conv_procedure_call(), after the function type is determined: fntype =3D TREE_TYPE (TREE_TYPE (se->expr)) then the fntype for _gfortran_is_extension_of is: unit-size align:32 warn_if_not_align:0 symtab:0 alias-set -1 = canonical-type 0x14309b918 precision:1 min = max > SI size unit-size align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type = 0x14322d998 attributes value >> arg-types >> pointer_to_this > Note the arg-types is an empty list. We=E2=80=99re declaring it as if = the function had no arguments, although it has two. Not all code paths in the compiler lead to this. If you compile code = that explicitly calls EXTENDS_TYPE_OF, like this one: ---------- module m implicit none type, abstract :: t1 logical :: l end type t1 type, extends(t1), abstract :: t2 integer :: i end type t2 contains subroutine s(u, v) class(t1), intent(in) :: u, v print *, extends_type_of(u, v) end subroutine s end module m ----------- then you can see the arg-types are good: unit-size align:32 warn_if_not_align:0 symtab:0 alias-set -1 = canonical-type 0x143c47918 precision:1 min = max > SI size unit-size align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type = 0x143dd95a8 attributes value >> arg-types unsigned restrict DI size unit-size align:64 warn_if_not_align:0 symtab:0 alias-set -1 = canonical-type 0x143dd9500> chain chain >>> pointer_to_this > It=E2=80=99s a different bug, and yet, it feels similar. Both lead to = wrong code generation on aarch64-apple-darwin, whose ABI has more = differences than most between named and variadic function args. I tried to set up the formal arg list to fix this in resolve.c=E2=80=99s = resolve_select_type(), like this: --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -9635,6 +9635,9 @@ resolve_select_type (gfc_code *code, gfc_namespace = *old_ns) new_st->expr1->value.function.actual->next =3D = gfc_get_actual_arglist (); new_st->expr1->value.function.actual->next->expr =3D = gfc_get_variable_expr (st); new_st->expr1->value.function.actual->next->expr->where =3D = code->loc; + /* Formal arguments. */ + new_st->expr1->value.function.isym->formal->ts =3D = selector_expr->symtree->n.sym->ts; + new_st->expr1->value.function.isym->formal->next->ts =3D = st->n.sym->ts; new_st->next =3D body->next; } if (default_case->next) but this does not work because = new_st->expr1->value.function.isym->formal is NULL. Sad. FX