From patchwork Wed Jun 16 15:13:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= X-Patchwork-Id: 1492959 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kPFCMmHs; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G4pcG2vMQz9sX2 for ; Thu, 17 Jun 2021 01:13:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20C9C393AC3F for ; Wed, 16 Jun 2021 15:13:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20C9C393AC3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623856427; bh=AaCgiGQH8h3zX4n1EsK0vO+PJki+nKyMR10YdOa5We0=; h=Subject:References:To:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kPFCMmHsM2NHlEKTYngHjSavbesdrSwijZwq+1QheFN3+uRYLjLBf04+tbWdBpaNO y5W7nOBh9HsgsMhdsajKm2X+X3t2OyA9IpU9bhyzYQfhXqoXzHhMXOR7se+FISP4nS KMY1DW4/PAvj5+qMps/aTNOb5kNwQXQmQ3Wct4Yc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id D2D333890420; Wed, 16 Jun 2021 15:13:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D2D333890420 Received: by mail-wm1-x32b.google.com with SMTP id l9so1494351wms.1; Wed, 16 Jun 2021 08:13:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:to:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=AaCgiGQH8h3zX4n1EsK0vO+PJki+nKyMR10YdOa5We0=; b=Flse7GW27EkWRZBSOCQoWFuboQ6rV4GG2gmGFfC1wE2AikA1vmyHtPFpET4OJ3mdXA P6i+4QbWA79+v8yc25HXl1O6NHbP7xwD+jDASbceGHgm0goCj9OoPSbyCYNFcnbVQDmI imd1mPDWazwFQhqo+CrHx/O88YJ+n1kHHIKtqlMOzSwVbMwWjhzlc9UElbau9fNCSUVV bczcOPXxwVQrtt1Vse1ZUEguImm2tP5kjICLpL2JitALiQnhLUtySn5k2zpwbtCMWVwJ xdcL6sG/e5km/MHQ4OsPu+lxkyLlQZQptGlZ10r96DG1cPwcoqbIRoHD31VyQQ3zoe06 q8RA== X-Gm-Message-State: AOAM530nbbr2W2WOiOPWWu8ANehXF2BGCFRxIErp8kQi04k7BQO+OgOf s9CELbN5NA4j5k6IRhxUTeTFWfS0pzI= X-Google-Smtp-Source: ABdhPJyvUd6BFvmQK9+p/AeYK/90j6EJb2ZEhSeDjl1ufI5T9uMfGShO+owDKqrFxXCRBYQeN6saeA== X-Received: by 2002:a05:600c:154:: with SMTP id w20mr407309wmm.185.1623856382652; Wed, 16 Jun 2021 08:13:02 -0700 (PDT) Received: from ?IPv6:2001:8a0:7d79:6000:733c:e830:9b46:fc86? ([2001:8a0:7d79:6000:733c:e830:9b46:fc86]) by smtp.googlemail.com with ESMTPSA id 3sm4825165wmv.6.2021.06.16.08.13.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 08:13:01 -0700 (PDT) Subject: PING: [Patch, fortran] PR fortran/96724 - Bogus warnings with the repeat intrinsic and the flag -Wconversion-extra References: To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Forwarded-Message-Id: Message-ID: Date: Wed, 16 Jun 2021 15:13:00 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: 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: , X-Patchwork-Original-From: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa_via_Gcc-patches?= From: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= Reply-To: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" *PING* -------- Forwarded Message -------- Subject: [Patch, fortran] PR fortran/96724 - Bogus warnings with the repeat intrinsic and the flag -Wconversion-extra Date: Thu, 20 Aug 2020 16:52:10 +0000 From: José Rui Faustino de Sousa To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Hi all! Proposed patch to PR96724 - Bogus warnings with the repeat intrinsic and the flag -Wconversion-extra. Patch tested only on x86_64-pc-linux-gnu. Add code to force conversion to the default wider integer type before multiplication. Thank you very much. Best regards, José Rui 2020-8-20 José Rui Faustino de Sousa PR fortran/96724 * iresolve.c (gfc_resolve_repeat): Force conversion to gfc_index_integer_kind before the call to gfc_multiply. 2020-8-20 José Rui Faustino de Sousa PR fortran/96724 * repeat_8.f90.f90: New test. diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index 7376961..74075a7 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -2332,7 +2332,22 @@ gfc_resolve_repeat (gfc_expr *f, gfc_expr *string, } if (tmp) - f->ts.u.cl->length = gfc_multiply (tmp, gfc_copy_expr (ncopies)); + { + gfc_expr *e = gfc_copy_expr (ncopies); + + /* Force-convert to index_kind so that we don't need + so many runtime variations. */ + if (e->ts.kind != gfc_index_integer_kind) + { + gfc_typespec ts = e->ts; + + ts.kind = gfc_index_integer_kind; + gfc_convert_type_warn (e, &ts, 2, 0); + } + if (tmp->ts.kind != gfc_index_integer_kind) + gfc_convert_type_warn (tmp, &e->ts, 2, 0); + f->ts.u.cl->length = gfc_multiply (tmp, e); + } } diff --git a/gcc/testsuite/gfortran.dg/repeat_8.f90 b/gcc/testsuite/gfortran.dg/repeat_8.f90 new file mode 100644 index 0000000..6876af9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/repeat_8.f90 @@ -0,0 +1,88 @@ +! { dg-do compile } +! { dg-additional-options "-Wconversion-extra" } +! +! Test fix for PR96724 +! + +program repeat_p + + use, intrinsic :: iso_fortran_env, only: & + int8, int16, int32, int64 + + implicit none + + integer, parameter :: n = 20 + + integer(kind=int8), parameter :: p08 = int(n, kind=int8) + integer(kind=int16), parameter :: p16 = int(n, kind=int16) + integer(kind=int16), parameter :: p32 = int(n, kind=int32) + integer(kind=int16), parameter :: p64 = int(n, kind=int64) + + integer(kind=int8) :: i08 + integer(kind=int16) :: i16 + integer(kind=int32) :: i32 + integer(kind=int64) :: i64 + + character(len=n) :: c + + i08 = p08 + c = repeat('X', 20_int8) + c = repeat('X', i08) + c = repeat('X', p08) + c = repeat('X', len08(c)) + i16 = p16 + c = repeat('X', 20_int16) + c = repeat('X', i16) + c = repeat('X', p16) + c = repeat('X', len16(c)) + i32 = p32 + c = repeat('X', 20_int32) + c = repeat('X', i32) + c = repeat('X', p32) + c = repeat('X', len32(c)) + i64 = p64 + c = repeat('X', 20_int64) + c = repeat('X', i64) + c = repeat('X', p64) + c = repeat('X', len64(c)) + stop + +contains + + function len08(x) result(l) + character(len=*), intent(in) :: x + + integer(kind=int8) :: l + + l = int(len(x), kind=int8) + return + end function len08 + + function len16(x) result(l) + character(len=*), intent(in) :: x + + integer(kind=int16) :: l + + l = int(len(x), kind=int16) + return + end function len16 + + function len32(x) result(l) + character(len=*), intent(in) :: x + + integer(kind=int32) :: l + + l = int(len(x), kind=int32) + return + end function len32 + + function len64(x) result(l) + character(len=*), intent(in) :: x + + integer(kind=int64) :: l + + l = int(len(x), kind=int64) + return + end function len64 + +end program repeat_p