Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1017702ybv; Thu, 13 Feb 2020 14:06:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzjB4C7N6sUWiE5oUkPca1b47s6gadGMniCi+7tunACsQ+LLOYd448S0EpW6SVhhJ1O5NGq X-Received: by 2002:a9d:6d81:: with SMTP id x1mr15952037otp.9.1581631586398; Thu, 13 Feb 2020 14:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581631586; cv=none; d=google.com; s=arc-20160816; b=PdU3cauV7YliUUoyCyrrBIUZK7bAh1ge1Hlx+wxa93PkCTUkZb+c0RaNawKD0atIx6 KGouh95ysWBjzri7rYvl12WV4j+Qn0r8R334uiVhLge8UFQ4Bzb1080cdHWC8ZGRCnBK Umy7H9zsPBA6sssYrdH3uf4UDvvwIVJ5wVa31GjBtcqRNyC89SiwFFTbgpkXDmTo228Z JC1Jnaf4RE/yf+A3YmApM1Jnm2Tipt/SOPtzolRtVmo5fmYxcW/JuwggVU78n3raY/dB 53mqCQq1CE0TI9G0cTF3LjuORi0OezoyAC0+PYUPzBuXJ7A/WkyM56LUjVovRLrfXK3M yw1A== 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:mime-version :message-id:date:references:organization:in-reply-to:subject:cc:to :from; bh=Wq4xqkd/iwZ9n9Xa4rNp/uL8BfLX52jHuYBHhu9lZW0=; b=eGsQmIbzuBH9szTIYYiuOp9XK22M04tR7pBHfs1FvgZo5Fv0x7C9eCtQ0XPGaQiEj1 DIjfI/N5NyxtjIzc99PGjH0UXJd4jfS4nRex/uUUNQX898qJfz5yNlFbOmRfJXh0WRO0 ba+6rEfi8ocA9Ry/DC/VWpQSD2+DnSDAllT86GojuVGYlpAlEnatKeEm+mWQ8aYaYIaU 40lUF9WmHzcYCoS2w+aWLBx78nnN4lSyw1kl2+PvjdDeGfoy91wQL75xzy5aU3InYHTI YaiK7z6pRy8SA6TM8s+o/wuA/eQmYD9umKkD11YAeOhZ/s/253lM8NO3pdG3zGCo/CCm 4nnA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 10si1668908ois.76.2020.02.13.14.06.14; Thu, 13 Feb 2020 14:06:26 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbgBMWFC convert rfc822-to-8bit (ORCPT + 99 others); Thu, 13 Feb 2020 17:05:02 -0500 Received: from mga03.intel.com ([134.134.136.65]:59918 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727519AbgBMWFC (ORCPT ); Thu, 13 Feb 2020 17:05:02 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 14:05:01 -0800 X-IronPort-AV: E=Sophos;i="5.70,438,1574150400"; d="scan'208";a="227391043" Received: from unknown (HELO localhost) ([10.252.53.8]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2020 14:04:58 -0800 From: Jani Nikula To: Nathan Chancellor Cc: Michel =?utf-8?Q?D=C3=A4nzer?= , clang-built-linux@googlegroups.com, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [Intel-gfx] [PATCH v2] drm/i915: Disable -Wtautological-constant-out-of-range-compare In-Reply-To: <20200213214812.GA7980@ubuntu-m2-xlarge-x86> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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> <877e0qy2n8.fsf@intel.com> <20200213214812.GA7980@ubuntu-m2-xlarge-x86> Date: Fri, 14 Feb 2020 00:05:24 +0200 Message-ID: <87mu9mw3bv.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Feb 2020, Nathan Chancellor wrote: > On Thu, Feb 13, 2020 at 04:37:15PM +0200, Jani Nikula wrote: >> On Wed, 12 Feb 2020, Michel Dänzer wrote: >> > On 2020-02-12 6:07 p.m., Nathan Chancellor wrote: >> >> On Wed, Feb 12, 2020 at 09:52:52AM +0100, Michel Dänzer wrote: >> >>> On 2020-02-11 9:39 p.m., Nathan Chancellor wrote: >> >>>> On Tue, Feb 11, 2020 at 10:41:48AM +0100, Michel Dänzer wrote: >> >>>>> On 2020-02-11 7:13 a.m., Nathan Chancellor wrote: >> >>>>>> A recent commit in clang added -Wtautological-compare to -Wall, which 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 value >> >>>>> in both cases, and remain is a 32-bit value in both cases. How can it 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 == 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 == 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. >> >> I like this better than the UINT_MAX == ULONG_MAX comparison because >> that creates a dependency on the type of remain. >> >> Then again, a sufficiently clever compiler could see through the cast, >> and flag the warning anyway... > > Would you prefer a patch that adds that cast rather than silencing the > warning outright? It does appear to work for clang. I'd take the cast. If that fails for whatever reason, per-file CFLAGS_gem/i915_gem_execbuffer.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare) over subdir-ccflags-y would be preferrable I think. BR, Jani. > > Cheers, > Nathan -- Jani Nikula, Intel Open Source Graphics Center