From patchwork Fri Oct 22 21:50:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 46556 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAEB33857823 for ; Fri, 22 Oct 2021 21:50:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 2ACF23858416; Fri, 22 Oct 2021 21:50:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2ACF23858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: /kOUYaBSp5RK+JCmpilSdhzlkji3zFsN7YkDzMwo1E1Zm5wHl6Ltv/gTw9pmbwJYKo1npqEz0v JajsFDptCVOQFmC6KVXCNShM3Vf2YDdzxhpL+V8cwYX6JXmXRosYme4oJxY0UCpuElYUkeilgb 2v3xnX06Q0ut6WUlRR5wtUtHj+PMTI/i7hdJJtdQYstVEI/GUZNd0TKq481+tRRiej9/fd3q4+ CgT+AeKPOrxwUb4wEiLuBLv3vC+yYydLm+miDB55tUzpkR7BCUjkG1SA8bSWjc6Fx7fs8AeYWP jwQQtipVpsl+XdhFX3oPKwfF X-IronPort-AV: E=Sophos;i="5.87,173,1631606400"; d="diff'?scan'208";a="67392539" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 22 Oct 2021 13:50:32 -0800 IronPort-SDR: qg/VcA/Q6TuuvgCcL63UbEXAR1x05NAyvx05GB+I6DcmPJqILPQHaDUKfZlBqSsSk0AqNGWEpO zw7Zdk8nEC8yxSRi5qVVdU1eFxb823yoCiYvdcM0qCeLiCpYcF7Q6LKbmh36A6CUZsDJA9u8ix 5DxfC6NeZzzFHUGw4H0VL6Y7GdxT2ZfhIoeiAADR0IvsOAga1vRyjVIEsQHe2SxehvBhcl1rES rcdDs3UTe/9S1yrdCOAQ25wgZjs+qe4xZDbbfRslfZPc9tZme9XHRTCjfg1ew3augXv1Is7DeX Zrs= Message-ID: <8a62c1ac-8170-b1f0-2b60-ecb81004a76f@codesourcery.com> Date: Fri, 22 Oct 2021 23:50:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Content-Language: en-US From: Tobias Burnus To: gcc-patches , fortran Subject: [committed] Fortran: Avoid running into assert with -fcheck= + UBSAN [PR92621] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The testcase of the PR or as attached gave an ICE, but only when compiled with -fcheck=all -fsanitize=undefined. Solution: Strip the nop to avoid the assert failure. Committed as r12-4632-g24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 Tobias * * * PS: Similar issues when using additional flags: ICE also with -fcheck=all -fsanitize=undefined: https://gcc.gnu.org/PR102901 ICE (segfault) when compiling pdt_13.f03 with -fcheck=all in gfc_check_pdt_dummy -> structure_alloc_comps https://gcc.gnu.org/PR102900 ICE via gfc_class_data_get with alloc_comp_class_4.f03 or proc_ptr_52.f90 using -fcheck=all + runtime same flags but running the code: https://gcc.gnu.org/PR102903 New: Invalid gfortran.dg testcases or wrong-code with -fcheck=all -fsanitize=undefined Here, false positives might/do surely exist as do testcase bugs. (And the list is incomplete.) + -flto fail (not really fitting into this series): https://gcc.gnu.org/PR102885 - [12 Regression] ICE when compiling gfortran.dg/bind_c_char_10.f90 with -flto since r12-4467-g64f9623765da3306 ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 commit 24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 Author: Tobias Burnus Date: Fri Oct 22 23:23:06 2021 +0200 Fortran: Avoid running into assert with -fcheck= + UBSAN PR fortran/92621 gcc/fortran/ * trans-expr.c (gfc_trans_assignment_1): Add STRIP_NOPS. gcc/testsuite/ * gfortran.dg/bind-c-intent-out-2.f90: New test. diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 29697e69e75..2d7f9e0fb91 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -11727,6 +11727,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, tmp = INDIRECT_REF_P (lse.expr) ? gfc_build_addr_expr (NULL_TREE, lse.expr) : lse.expr; + STRIP_NOPS (tmp); /* We should only get array references here. */ gcc_assert (TREE_CODE (tmp) == POINTER_PLUS_EXPR diff --git a/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 b/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 new file mode 100644 index 00000000000..fe8f6060f1f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 @@ -0,0 +1,39 @@ +! { dg-do run } +! { dg-additional-options "-fsanitize=undefined -fcheck=all" } + +! PR fortran/92621 + +subroutine hello(val) bind(c) + use, intrinsic :: iso_c_binding, only: c_int + + implicit none + + integer(kind=c_int), allocatable, intent(out) :: val(:) + + allocate(val(1)) + val = 2 + return +end subroutine hello + +program alloc_p + + use, intrinsic :: iso_c_binding, only: c_int + + implicit none + + interface + subroutine hello(val) bind(c) + import :: c_int + implicit none + integer(kind=c_int), allocatable, intent(out) :: val(:) + end subroutine hello + end interface + + integer(kind=c_int), allocatable :: a(:) + + allocate(a(1)) + a = 1 + call hello(a) + stop + +end program alloc_p