From patchwork Thu Nov 14 15:52:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 1194944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513427-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LmEvRrhX"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="i3LOQ7Fq"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47DQx26RT9z9sNT for ; Fri, 15 Nov 2019 02:52:53 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=w8zY54xeAZfMWNsr353sj5XEtT3yIK4mbyyY85PecIo Z9seZllKnsUZ1pYnlUQSZYCNl6EJDUj7nzyJeL5qXixy56uEY47SRMNurvg7yg3Z vS5sozpY/cfV0i6jRGnQEGVpqnDoW7Y/1JwvxwXQELVDFTOPOqx0JCRJMi8qMzBE = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:cc:content-type; s=default; bh=5WrYSt05OlcQaw1kKUeY6W2XCHw=; b=LmEvRrhXklIuq08qe XisEWeGjhz+t+LvjgWG6uDsupvPg1CSUa/KSQNgyKjbn33Fs21ZpxZczjeSHXbzj LVOPPJo3/jh+5ZX74upLWSGb2l+QiuPSNEMFj5PeNCx3nyB/12SuOw9vsJOno4y/ b7kZWxvCPaaJcaIFPXz62e2BdI= Received: (qmail 14559 invoked by alias); 14 Nov 2019 15:52:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 14525 invoked by uid 89); 14 Nov 2019 15:52:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:sk:CAGkQGi, HX-Received:651c X-HELO: mail-lj1-f179.google.com Received: from mail-lj1-f179.google.com (HELO mail-lj1-f179.google.com) (209.85.208.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Nov 2019 15:52:40 +0000 Received: by mail-lj1-f179.google.com with SMTP id d5so7219676ljl.4; Thu, 14 Nov 2019 07:52:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=8h0x02bVn3d2zhnEIz5xcEBwS3onaavJLf5esbAn+8M=; b=i3LOQ7Fqk40Jy9B+XYYfsH1DAhFoF3xvGe2sGmlj9gQ9s5iKF3CV4jRdYY7v7Pd1he U5kpW+NQ9H/VRSrH4Dx3UUdZkBFTa/QLGuslMrMBYIVZ5aYEyLSdKg/98N33RP0E/V2h WwT3aGyVcXHvCTMWGk1Cfi7Tc/t+HkZ5qY/m74jheTaKzqq+kMXZYCvmm83A6eZ05eLz MQTA7Kgjb40fmb67hRuk/lLy+YSx7qvs/hPV1kpgfCk8YltQoSXG78bjNEOJPIyyjQtX iWSxrgU0FOHjEUjGFfb9/6KJw5vc+5paBPS0cKKYiJ4M3kFGVhxUvhMcSGoRtWGDC1H0 feeQ== MIME-Version: 1.0 From: Paul Richard Thomas Date: Thu, 14 Nov 2019 15:52:26 +0000 Message-ID: Subject: [Patch, fortran] PR69654 - ICE in gfc_trans_structure_assign To: "fortran@gcc.gnu.org" , gcc-patches Cc: talebi.hossein@gmail.com As I remarked in PR, this fix probably comes 1,379 days too late. I am not at all sure that I understand why I couldn't see the problem because it is rather trivial. I am open to not adding the second gcc_assert - it does seem like overkill. Regtested on FC30/x86_64 - OK for trunk and ....? Paul 2019-11-14 Paul Thomas PR fortran/69654 * trans-expr.c (gfc_trans_structure_assign): Move assignment to 'cm' after treatment of C pointer types and test that the type has been completely built before it. Add an assert that the backend_decl for each component exists. 2019-11-14 Paul Thomas PR fortran/69654 * gfortran.dg/derived_init_6.f90: New test. Index: gcc/fortran/trans-expr.c =================================================================== *** gcc/fortran/trans-expr.c (revision 278024) --- gcc/fortran/trans-expr.c (working copy) *************** gfc_trans_structure_assign (tree dest, g *** 8327,8333 **** gfc_se se; gfc_start_block (&block); - cm = expr->ts.u.derived->components; if (expr->ts.u.derived->from_intmod == INTMOD_ISO_C_BINDING && (expr->ts.u.derived->intmod_sym_id == ISOCBINDING_PTR --- 8327,8332 ---- *************** gfc_trans_structure_assign (tree dest, g *** 8345,8350 **** --- 8344,8360 ---- return gfc_finish_block (&block); } + /* Make sure that the derived type has been completely built. */ + if (!expr->ts.u.derived->backend_decl + || !TYPE_FIELDS (expr->ts.u.derived->backend_decl)) + { + tmp = gfc_typenode_for_spec (&expr->ts); + gcc_assert (tmp); + } + + cm = expr->ts.u.derived->components; + + if (coarray) gfc_init_se (&se, NULL); *************** gfc_trans_structure_assign (tree dest, g *** 8415,8420 **** --- 8425,8431 ---- gfc_add_expr_to_block (&block, tmp); } field = cm->backend_decl; + gcc_assert(field); tmp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field), dest, field, NULL_TREE); if (!c->expr) Index: gcc/testsuite/gfortran.dg/derived_init_6.f90 =================================================================== *** gcc/testsuite/gfortran.dg/derived_init_6.f90 (nonexistent) --- gcc/testsuite/gfortran.dg/derived_init_6.f90 (working copy) *************** *** 0 **** --- 1,60 ---- + ! { dg-do compile } + ! + ! Test the fix for PR69654 in which the derived type 'ty_foo2' was + ! not completely built in time for initialization thereby causing an ICE. + ! + ! Contributed by Hossein Talebi + ! + Module foo_pointers_class + implicit none + type :: ty_foo_pointers + integer :: scale=0 + integer,pointer :: universe_ulogfile => NULL() + class(*),pointer :: foo => NULL() + end type ty_foo_pointers + + type :: ty_part_ptrs + character(len=80),pointer :: part_name => NULL() + class(*),pointer :: part_fem => NULL() + end type + + type :: ty_class_basis + integer :: id=0 + end type ty_class_basis + + type :: ty_store_sclass + class(ty_class_basis),allocatable :: OBJ + end type ty_store_sclass + End Module foo_pointers_class + + Module foo_class + use foo_pointers_class + implicit none + type,extends(ty_class_basis) :: ty_foo2 + character(200) :: title + logical :: isInit=.false. + type(ty_foo_pointers) :: foo + end type ty_foo2 + ENd Module foo_class + + + Module foo_scripts_mod + implicit none + contains + + subroutine foo_script1 + use foo_class, only: ty_foo2 + implicit none + type(ty_foo2) :: foo2 + integer i + + Call foo_init2(foo2) + end subroutine foo_script1 + + subroutine foo_init2(self) + use foo_class, only: ty_foo2 + type(ty_foo2),target :: self + self%isInit=.true. + end subroutine foo_init2 + + End Module foo_scripts_mod