From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id D76393858D35 for ; Tue, 30 Jun 2020 17:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D76393858D35 Received: by mail-qk1-x741.google.com with SMTP id c139so19433611qkg.12 for ; Tue, 30 Jun 2020 10:52:12 -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:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nezAzzsXYqPhgHHMoIf9cBXxDdDBWOyXLcyiIhlwlNk=; b=cHKx9Txn+Pjfb7rGnWwvO5zTIY2UuLAsNh18lSv4Hr5mwfQpbmEwmV6Spi1bzuJXuz SK8aeIFkiifr4/nCIAbEp54EtAoZABs8D/4C8RDpzOv1SHzEWoUz2BNhD8mwIfTP924X E4yfW5skG+imtcA29CZ+Hbz4N4n+e7v1jn9kIbZ1TrG47swVnw3KrOIKLfZqEqOMyX91 YA3w16lxb3TUYPnimJAKZaaILCABiJWvIbldne/swY96nZA9Yiuf0TDjXRUwSqbdowUh pmc/LcB/FbaWRvCLk1oHb0rjQirYtwXb8y7X13NAMmbDuDGP/m9XM5owcWi5gEdKI0JF dxSw== X-Gm-Message-State: AOAM5306KrRa+zq++/zyViB+oUD7AM/PEnKiRzrR43pG188U38jxRsJ/ IkPYQWP9fukWVWJYzvEFg9b47iBXCj8= X-Google-Smtp-Source: ABdhPJy8o+ZTvPdM+saBnoHeGtV0DCEzwPCTKzvMWLxB3ih0G3KBCh5/VipwmyrqYFWfEKeQuXmUfg== X-Received: by 2002:a37:a4c3:: with SMTP id n186mr21077920qke.280.1593539532022; Tue, 30 Jun 2020 10:52:12 -0700 (PDT) Received: from ?IPv6:2804:7f0:8283:20c3:e01d:4330:d5b2:db25? ([2804:7f0:8283:20c3:e01d:4330:d5b2:db25]) by smtp.gmail.com with ESMTPSA id w11sm3792921qtk.35.2020.06.30.10.52.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jun 2020 10:52:11 -0700 (PDT) Subject: Re: [PATCH] Make out of range type conversions explicit To: Gary Benson , gdb-patches@sourceware.org References: <1593525480-5685-1-git-send-email-gbenson@redhat.com> From: Luis Machado Message-ID: <40e636d7-e938-1351-eb5e-9f92540d9c1a@linaro.org> Date: Tue, 30 Jun 2020 14:52:08 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <1593525480-5685-1-git-send-email-gbenson@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2020 17:52:14 -0000 If the approach is acceptable, we should at least make it clear, through comments, that this is being done for clang. Having these casts in the code, without an explanation, is a bit cryptic. On 6/30/20 10:58 AM, Gary Benson via Gdb-patches wrote: > HI all, > > Clang fails to compile two testcases with the following warning: > implicit conversion from 'X' to 'Y' changes value from x to y > [-Wconstant-conversion]. This patch adds casts that make the > value-changing conversions explicit. > > Checked on Fedora 31 x86_64, GCC and clang. Ok to commit? > > Cheers, > Gary > > -- > gdb/testsuite/ChangeLog: > > * gdb.base/charset.c (main): Explicitly cast values which are > out of range of their destination types. > * gdb.base/structs2.c (main): Likewise. > --- > gdb/testsuite/ChangeLog | 6 ++++++ > gdb/testsuite/gdb.base/charset.c | 6 +++--- > gdb/testsuite/gdb.base/structs2.c | 2 +- > 3 files changed, 10 insertions(+), 4 deletions(-) > > diff --git a/gdb/testsuite/gdb.base/charset.c b/gdb/testsuite/gdb.base/charset.c > index ec4927d..54bd2dd 100644 > --- a/gdb/testsuite/gdb.base/charset.c > +++ b/gdb/testsuite/gdb.base/charset.c > @@ -141,14 +141,14 @@ int main () > 120, > 7, 8, 12, > 10, 13, 9, > - 11, 162, 17); > + 11, (char) 162, 17); > fill_run (iso_8859_1_string, 7, 26, 65); > fill_run (iso_8859_1_string, 33, 26, 97); > fill_run (iso_8859_1_string, 59, 10, 48); > > /* Initialize ebcdic_us_string. */ > init_string (ebcdic_us_string, > - 167, > + (char) 167, > 47, 22, 12, > 37, 13, 5, > 11, 74, 17); > @@ -165,7 +165,7 @@ int main () > > /* Initialize ibm1047_string. */ > init_string (ibm1047_string, > - 167, > + (char) 167, > 47, 22, 12, > 37, 13, 5, > 11, 74, 17); > diff --git a/gdb/testsuite/gdb.base/structs2.c b/gdb/testsuite/gdb.base/structs2.c > index 7c8be03..2847cd6 100644 > --- a/gdb/testsuite/gdb.base/structs2.c > +++ b/gdb/testsuite/gdb.base/structs2.c > @@ -13,7 +13,7 @@ static void param_reg (register signed char pr_char, > > bkpt = 0; > param_reg (120, 130, 32000, 33000); > - param_reg (130, 120, 33000, 32000); > + param_reg ((signed char) 130, 120, (short) 33000, 32000); > > return 0; > } >