Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1047437ybv; Thu, 13 Feb 2020 14:44:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxzm9EimiC6LQzv7OKQn6VmCqNgLknyXDAJDfsdS7dxYx1qzNZcA7xD8fsH3n0Ps5ginBds X-Received: by 2002:aca:4309:: with SMTP id q9mr4589556oia.158.1581633844606; Thu, 13 Feb 2020 14:44:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581633844; cv=none; d=google.com; s=arc-20160816; b=EnO3mivwnBCuc91/CyB1RpI2NeW+hXW0iEFadArdqpWiza0XOnIbQad0dvqoMuwLkm 3+sNtIdZRNelxVQxxgn6+43hAqaL8Yj3TImToOkFaDrLTsgdxG2XHxC+ilJpackVyi0G fBepFbjVyTPDdGZROuCkOPeAp9EGRBs8On/HcvxrzEEa94jiz4td/j9lO8fJrZTbQXZR KubrUqNPhCrLGv44giu6iupbbtRESsXfA09WLyhYtZpHsm2GM+VDJ1aJP89aZV4kO/lB zZEnU91uOfcuDAy4xLhZzak3woko0lAAaMdqlT5nua0WG/O3X8VhbpxV6IHNCrMaP7Vt hAGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1uz4onwD02FQH4e/dvdb1FjZu1rFnkl+4ltvHCVnzHQ=; b=VOG/x+M2x3F7GNCD/wyQ5HBVs4174rvFp7jzzX/1jdVwis0WpuEf2V25LC6r6FPWGz AxtILtQFpKFe7wX1tZbQsCwIDQSs1zjSzgO9EE6rkEnJRZRbRg9U3K4pjOhr0xPRAcfA Awi4didt24CUwYPLSy8ZB66kzeDPicQaup2g2oUzKxDv0RfolnQmrd8X8mNILNeZ/Qr5 /VG6WRmc2oUj3Pp8FWzentkvsY4nvyMbMM8+iTnj+/3+wxNZT0MBIDUOCeNo+jAK9L2O RR1OyMY2vrRSGHCTjEgwBB+i5c6YOBiImpB4PYdcMgQj2H7Fx7yQXLxQadNFa9ccyv0f 6hxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Mu7RaWQT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si1868156otf.36.2020.02.13.14.43.52; Thu, 13 Feb 2020 14:44:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Mu7RaWQT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbgBMWnd (ORCPT + 99 others); Thu, 13 Feb 2020 17:43:33 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46944 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbgBMWnd (ORCPT ); Thu, 13 Feb 2020 17:43:33 -0500 Received: by mail-pg1-f193.google.com with SMTP id b35so3743324pgm.13 for ; Thu, 13 Feb 2020 14:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1uz4onwD02FQH4e/dvdb1FjZu1rFnkl+4ltvHCVnzHQ=; b=Mu7RaWQT57rbjsEgWQeug20f4GIX77GFzc3qAC7n2UMwytWFBLui8a1qKbHPGKy1kO 9qHZUeD/Ig7Ke5Azt9yZuWIB3ilP30QdJLPVilNqofkViyiWVw9yHK13NFR7WQruhaev K9iZutEjIZ9rx6lvKFO6X2nTrfMLXqseES2VUtMF39yTdsb2GbDCvpgsBONkdsB8nnA5 MUo5zjOT/BmVDI9DZ/Hr6pq80Tpe5d2g9iwzD+aJyP/o8jZWLS7JhIi11/cydPIK6Nly ZZyDKTNDANgpYqFoT7sqnemXJg3T6yPh2tbZSI2Aim3r5vYBVqiLMFEqe5+3ngmFACR/ q5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1uz4onwD02FQH4e/dvdb1FjZu1rFnkl+4ltvHCVnzHQ=; b=nsupD/H3c8KDzFNUZpq+mhtA0v2qMnF0cVgeuonwQK/bcbZnxV+MmujUesBOLrPo2V NM1OmGV+FHvqy7z51+cLMfK9TPZ+HsiKl43kySUkTVfEyqpziAKvQlcoIrlbtEdGwOKj YvQX1fiiSdq4I4omELVxnv53GcQyIl0mozrSDGXDwywQRgMzWxO2EQvufEoIGVFYkIBm QaTzBI1YC0PVs1SgRlNUBV0dSh7GfaEMPmxu9mrQQkUinBOdJWulEx8h8uVUPqjlrwaI iZzFG1fyX2YvxivmItKOrQWac/WQmPjf8i4Aztj/xkVeZJGa04XnvaXG5LP9GQJWrqKE zHpA== X-Gm-Message-State: APjAAAX0xFvWqJbk317xG5UfiZOjVlIu2WS36S5mw4P2fYALpglkokzD Fsunwd1aexnVdBY10aNhAWJGFtpVOhxFqvvtBspJtg== X-Received: by 2002:a63:64c5:: with SMTP id y188mr195696pgb.10.1581633812546; Thu, 13 Feb 2020 14:43:32 -0800 (PST) MIME-Version: 1.0 References: <20200211050808.29463-1-natechancellor@gmail.com> <20200211061338.23666-1-natechancellor@gmail.com> <4c806435-f32d-1559-9563-ffe3fa69f0d1@daenzer.net> <20200211203935.GA16176@ubuntu-m2-xlarge-x86> <20200212170734.GA16396@ubuntu-m2-xlarge-x86> In-Reply-To: From: Nick Desaulniers Date: Thu, 13 Feb 2020 14:43:21 -0800 Message-ID: Subject: Re: [PATCH v2] drm/i915: Disable -Wtautological-constant-out-of-range-compare To: =?UTF-8?Q?Michel_D=C3=A4nzer?= Cc: Nathan Chancellor , intel-gfx@lists.freedesktop.org, LKML , clang-built-linux , dri-devel , Rodrigo Vivi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 12, 2020 at 9:17 AM Michel D=C3=A4nzer wro= te: > > On 2020-02-12 6:07 p.m., Nathan Chancellor wrote: > > On Wed, Feb 12, 2020 at 09:52:52AM +0100, Michel D=C3=A4nzer wrote: > >> On 2020-02-11 9:39 p.m., Nathan Chancellor wrote: > >>> On Tue, Feb 11, 2020 at 10:41:48AM +0100, Michel D=C3=A4nzer wrote: > >>>> On 2020-02-11 7:13 a.m., Nathan Chancellor wrote: > >>>>> A recent commit in clang added -Wtautological-compare to -Wall, whi= ch is > >>>>> enabled for i915 so we see the following warning: > >>>>> > >>>>> ../drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1485:22: warning: > >>>>> result of comparison of constant 576460752303423487 with expression= of > >>>>> type 'unsigned int' is always false > >>>>> [-Wtautological-constant-out-of-range-compare] > >>>>> if (unlikely(remain > N_RELOC(ULONG_MAX))) > >>>>> ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~ > >>>>> > >>>>> This warning only happens on x86_64 but that check is relevant for > >>>>> 32-bit x86 so we cannot remove it. > >>>> > >>>> That's suprising. AFAICT N_RELOC(ULONG_MAX) works out to the same va= lue > >>>> in both cases, and remain is a 32-bit value in both cases. How can i= t be > >>>> larger than N_RELOC(ULONG_MAX) on 32-bit (but not on 64-bit)? > >>>> > >>> > >>> Hi Michel, > >>> > >>> Can't this condition be true when UINT_MAX =3D=3D ULONG_MAX? > >> > >> Oh, right, I think I was wrongly thinking long had 64 bits even on 32-= bit. > >> > >> > >> Anyway, this suggests a possible better solution: > >> > >> #if UINT_MAX =3D=3D ULONG_MAX > >> if (unlikely(remain > N_RELOC(ULONG_MAX))) > >> return -EINVAL; > >> #endif > >> > >> > >> Or if that can't be used for some reason, something like > >> > >> if (unlikely((unsigned long)remain > N_RELOC(ULONG_MAX))) > >> return -EINVAL; > >> > >> should silence the warning. > > > > I do like this one better than the former. > > FWIW, one downside of this one compared to all alternatives (presumably) > is that it might end up generating actual code even on 64-bit, which > always ends up skipping the return. The warning is pointing out that the conditional is always false, which is correct on 64b. The check is only active for 32b. https://godbolt.org/z/oQrgT_ The cast silences the warning for 64b. (Note that GCC and Clang also generate precisely the same instruction sequences in my example, just GCC doesn't warn on such tautologies). --=20 Thanks, ~Nick Desaulniers