From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from CHE01-GV0-obe.outbound.protection.outlook.com (mail-gv0che01on2071.outbound.protection.outlook.com [40.107.23.71]) by sourceware.org (Postfix) with ESMTPS id 9F4E53858D3C for ; Mon, 22 Aug 2022 19:27:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F4E53858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cern.ch Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cern.ch ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z2fH1i4hjrTpq9IyM6rvju6OUuvi64T/uEAKfw3LVBtycOVQVDiuQk+0ID2d+eBDdIPjxX8ET1nDe4/oFYJ7LX+zn65QaJfinTC3XsOHnbFFpyaBtTabaKPata+ChmwG0SvIUBSIJZVTxpxMJiSbd42aD4rmDvaHeEUXIIf78DKa8kp/Aatk6EemJBlJfCzqyjUOMvzU9LOdjj5Zju1PtLe91nHV4sCLq7qzhq1lz6oVUA0r5Nc5aW2wMfgchnwYXAoFpacR/0BAd3WNiZKGdlmPrCplw2cJ5ucQvk/LG8N88E1EFNF6AwGc4NQktgcA2dbkzJwuEo+rfVUALTrG3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O7Yd/XtghdMMFh8FlGgzz6gCxEE30ASNXkk4vjNJKKE=; b=LwiEgdBByzywphJy01CoYVuQPkED+3Ms+pulw5sZ0ZGZHGttotvQ63Z9wShj9Y5virQkDKK9w+cjimR+a8LHIL+MFEtQ0bUU9LEjSdd7ggviR0WZJNfKBUt1HJd+SwlR/IgBQ7ldFikMmOeLzrt2c3gMm6AlZsu1oZhBfl/0HDXUEVjio+WxTfqxGybQtKUzH/LIGg91Ea6vVtgNoyyRq0PVyioLcKaYwdCpBIzTjZJ0MwmOdC9gyn3/6EUWSm8mdDsDNBH8ZWsnKlqhorZw8bEp6fcXQdGrxPqM+VXP8XCOits+OGbwUUhLPcxq5RW64Ox5IRp2BilrntofjTkaPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 188.184.36.46) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=cern.ch; dmarc=bestguesspass action=none header.from=cern.ch; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cern.onmicrosoft.com; s=selector2-cern-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O7Yd/XtghdMMFh8FlGgzz6gCxEE30ASNXkk4vjNJKKE=; b=VxT0xwVzTUlKEJjQcMLzK3Qie4QbPmysXLt+Neb0hAWJeoPP4sGLBHlso+uTcWe9h1FIQR7Cs3HAHz9InfAIuq9RErlNUW7Qm7eNg3MM3lUxXpgWc1ASd8JxO7W6nqGIgPBOqiiqGJvYCImtXkv2IUqme4owiDbT8+9ykPez3xs= Received: from AS9PR04CA0068.eurprd04.prod.outlook.com (2603:10a6:20b:48b::10) by GVAP278MB0472.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:3f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 19:27:49 +0000 Received: from AM5EUR02FT028.eop-EUR02.prod.protection.outlook.com (2603:10a6:20b:48b:cafe::4c) by AS9PR04CA0068.outlook.office365.com (2603:10a6:20b:48b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.23 via Frontend Transport; Mon, 22 Aug 2022 19:27:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 188.184.36.46) smtp.mailfrom=cern.ch; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=cern.ch; Received-SPF: Pass (protection.outlook.com: domain of cern.ch designates 188.184.36.46 as permitted sender) receiver=protection.outlook.com; client-ip=188.184.36.46; helo=cernmxgwlb4.cern.ch; pr=C Received: from cernmxgwlb4.cern.ch (188.184.36.46) by AM5EUR02FT028.mail.protection.outlook.com (10.152.8.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5546.15 via Frontend Transport; Mon, 22 Aug 2022 19:27:49 +0000 Received: from cernfe06.cern.ch (188.184.36.49) by cernmxgwlb4.cern.ch (188.184.36.46) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 22 Aug 2022 21:27:47 +0200 Received: from mail-qt1-f173.google.com (209.85.160.173) by smtp.cern.ch (188.184.36.52) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 22 Aug 2022 21:27:46 +0200 Received: by mail-qt1-f173.google.com with SMTP id h21so8724551qta.3 for ; Mon, 22 Aug 2022 12:27:46 -0700 (PDT) X-Gm-Message-State: ACgBeo3tmgBYMHZH+KuRnZ8nbalvCDI6i15eY0jMnF7TYpD0xBt/rCN1 8+sgwtIzmWCEcOf+TWZRAbUcC0ZpoZBIvKH/bUo= X-Google-Smtp-Source: AA6agR7dVbCT+VcqMu4aCwShOogTv5xM5OthhMo7aDtP+x8QWF3Tz6zgiCCgGB7835FgAGsYOrZ6SV3X7IVzvYJYeA8= X-Received: by 2002:ac8:5c0d:0:b0:344:b49c:2109 with SMTP id i13-20020ac85c0d000000b00344b49c2109mr7301111qti.667.1661196464856; Mon, 22 Aug 2022 12:27:44 -0700 (PDT) MIME-Version: 1.0 References: <20220822173203.GP25951@gate.crashing.org> In-Reply-To: <20220822173203.GP25951@gate.crashing.org> From: Andrea Bocci Date: Mon, 22 Aug 2022 21:27:09 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Warn about conversion from floating point to integers To: Segher Boessenkool CC: X-Originating-IP: [209.85.160.173] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c1d73ea-0bfb-4e73-c00a-08da8474663a X-MS-TrafficTypeDiagnostic: GVAP278MB0472:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ie5qCiNRfqqONbxXor6q2mq5kFSXriO3eEagYGeddDfl8vVKD6AkQOPfaq1b2987q2AQpwroE00oSinCYDtEnwdOHCtqI7yVIvWgzazERPo6WihuDTAHytBqYT15L66JXN08MguvUBV9b7Vhj+qmtDYQIl6qZN1W1FZPdVErd9POucUXlAfUVgKThvDa9wk3yRBxDfQ0g5zmtgpHa0ZXENnZxg2/u6taimLLJDc4FseOZT8Iy3dWwJHbxQkhaneqjebR6Q8nuFKTIeiQTgtkWzvpEp2KgDgMhhII7frVDWdMpom+ZRVl21P8gEau4r03LmNaRo2KgtehOfekpbyEFptoJlEeo9MVKoTh8KxV9WGUrtTPDXK3al5m4HiO12AuMZarXcwbf7rQ4K1VSGh5/5shAZ8kndM425UfnM1ZYiQu8QEog8ZXP+x0yk3vHCvhGuXqjrxuhC4JyF4gAkZbu9RX4tjhaHDyYRlqdIbk5lw9r3d7SqL82Hai5ZCtwTwy+D6Q4HKv9nICYf/sROB35a+PIk9IBhs9mepv4sbw+ceoILQ6kKfJfWa8Jz40rcx8ascuPMpga6QLhtfq9qcCGpaFi2QesYBJAbPfojfm8aM/LOYldrXyssDCMF0X0e1EpHgFArxCtlcf4qx+lH/t+tSJawqiESy2WxdmPBVwTyfoWcgHESoWyMlV+JKOteaR0Yl49Q2FZLpYNmfTz9ne26Fj9sNEHt4KSxQaj2LmxUx6hY7FfolEremMbIEQwuo3Ibgi36W3mQZKTwwVnGC7cb85zuGFLPSCdHyvSWgM8Pvi6dmZfHWQzTdDw5JpovB5ggeE1ri5ZH5J6f6i/+LnuQ== X-Forefront-Antispam-Report: CIP:188.184.36.46; CTRY:CH; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:cernmxgwlb4.cern.ch; PTR:cernmx13.cern.ch; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(396003)(376002)(346002)(40470700004)(36840700001)(46966006)(40460700003)(33964004)(356005)(82740400003)(55236004)(82310400005)(478600001)(70206006)(9686003)(70586007)(26005)(8676002)(4326008)(55446002)(786003)(86362001)(316002)(41300700001)(42186006)(166002)(6666004)(40480700001)(7636003)(186003)(336012)(36860700001)(5660300002)(8936002)(83380400001)(47076005)(44832011)(21615005)(6862004)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: cern.ch X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 19:27:49.0201 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c1d73ea-0bfb-4e73-c00a-08da8474663a X-MS-Exchange-CrossTenant-Id: c80d3499-4a40-4a8c-986e-abce017d6b19 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c80d3499-4a40-4a8c-986e-abce017d6b19; Ip=[188.184.36.46]; Helo=[cernmxgwlb4.cern.ch] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR02FT028.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVAP278MB0472 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_KAM_HTML_FONT_INVALID, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2022 19:27:54 -0000 On Mon, 22 Aug 2022 at 19:33, Segher Boessenkool wrote: > Hi! > > On Sat, Aug 20, 2022 at 11:21:50AM +0200, Andrea Bocci wrote: > > is there a way to ask GCC to produce a warning when there is a conversion > > from a floating point type (float or double) to an integer type (char, > > short, int, long, etc.), but not when there is a conversion from double > to > > float ? > > > > The reason is that we often do computations in double precision and store > > the result in single precision, so I'd rather not warn about that. > > > > -Wconversion warns about both kinds and more. > > -Wfloat-conversion warns about both kinds. > > There is no separate option. But, you can just grep the error messages? > > fc.c: In function 'f': > fc.c:1:28: warning: conversion from 'double' to 'float' may change value > [-Wfloat-conversion] > 1 | float f(double x) { return x; } > | ^ > fc.c: In function 'g': > fc.c:2:26: warning: conversion from 'double' to 'int' may change value > [-Wfloat-conversion] > 2 | int g(double x) { return x; } > | ^ > > Not ideal of course, but this should be workable? (You may want to set > LANG=C to get parsable warning messages). > > If you want a separate -W option for this, please file a PR? > See . Thanks! > Hi Segher, thank you for your message ! >From a test build of our code base with -Wfloat-conversion we got over 700k warnings from 65k unique locations, the vast majority being about "warning: conversion from 'double' to 'float' may change value". So, while we can run an ad-hoc build with -Wfloat-conversion and post-process the compiler messages, it's not something we can really keep enabled all the time. Making a PR for this might be a tad complicated, but I agree it would be the best way forward... so thanks for the suggestion :-) Ciao, .Andrea -- Dr. Andrea Bocci Applied Physicist, CMS Experiment EP-CMD, CERN 168990 (+41 75 411 8990) CERN 40/1-B01 E27810 Esplanade des particules, 1, CH-1211 Geneve 23, Switzerland