Received: by 10.192.165.156 with SMTP id m28csp1703019imm; Wed, 18 Apr 2018 14:23:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx48CEU5aSYQYRY3AniNSzBA2TOumxMHYhddCKEVa5FCNCvl+GA6iVvJTc7HLybk5tbfOEh6Q X-Received: by 10.101.74.138 with SMTP id b10mr2947752pgu.22.1524086604906; Wed, 18 Apr 2018 14:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524086604; cv=none; d=google.com; s=arc-20160816; b=R6qcyhz1easPQmzfbidHz2KsMZ9Ob0CcR2Y8awMGuCFy9WxlR7Atc0I5tjn84B/ocg k3VDRsmWCfPlEZsCWr042HGwwBUTcpxm1RpZRLnq2L+jhvra2e9zOTyKoCVsyVMzXoqP fkt0fMegNJXrovoWzbqrApyHctbX76CYXUdfP9vJl3kRxMI2UyoX+dYGVbP95I+fMIif uMZdPWGrnUIgATFDRGdRfqVR7S0dkPPRt3YJAkfYy4/54RVu0aEG9ZA2wRqlOYQy6BIP B9r0NEaADp1x6iQdU2KOjqu1X+EhZhXJ5yrwzaA95ZXwY1Cr3C2B4ncJv8HDG/3/0y9f ldkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=eQVkb9ZCrSRd/pPQpA+i3Y8dxR7mNEdZ9iRp4q/r61c=; b=a7Mz76OtkRQErj1WnBAzc6xMM+NwYS01IlUUDMhzvO4YPzDTxDiPINJ+cKVM3F0+OG ywRZXu6dzlkqBqJ7obBRNfNqqk7HksG9NAwECvqwt1Tioq0llkb8t97X2oE8iOYWPdsY xVQPTIYOn+ndDjAqr3/nvqIjlvLvLKYouHEZ69ZtV9rMEps5pJECQAbgK9zKc676JWr2 6xtz0xkVpUm+S5b1RK/NCvNvXxX7wU2cdv9w8wC1x1Zw9nq+IgGNE35+MRQx679YPn8c jICA4AqQu7etNPCAS7g8s52myhngnzQp8la0wMyBQlRgUks4S4Eg2yy0ojsOszMoLQoE 30cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=s4TthIdo; dkim=fail header.i=@linux-foundation.org header.s=google header.b=VZzPuh8e; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si1728954pgn.267.2018.04.18.14.23.04; Wed, 18 Apr 2018 14:23:24 -0700 (PDT) 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=fail header.i=@gmail.com header.s=20161025 header.b=s4TthIdo; dkim=fail header.i=@linux-foundation.org header.s=google header.b=VZzPuh8e; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752336AbeDRVVS (ORCPT + 99 others); Wed, 18 Apr 2018 17:21:18 -0400 Received: from mail-io0-f175.google.com ([209.85.223.175]:42534 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbeDRVVP (ORCPT ); Wed, 18 Apr 2018 17:21:15 -0400 Received: by mail-io0-f175.google.com with SMTP id l2-v6so2693386iog.9; Wed, 18 Apr 2018 14:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=eQVkb9ZCrSRd/pPQpA+i3Y8dxR7mNEdZ9iRp4q/r61c=; b=s4TthIdo46QTn528CY8KsYocdY/8j0GBIpkOHHdedVBb8UEQZxgVmuvycbAfC9RIMa WE/b0zhZBjW4FTy2fDRU0V/t4slDa5S1hpRRp83Nu0+P9Uh5K+5jI9uGOAizkMIWsNwC ym2sao92OfZdvTqh6EIjpWSgcTUWx4j+duRryYtPdBzF7nQOfr6bYeIpLKSAhB0/Kecs p7FGnAxxBm6uFTm2L/QMQDLz+UxTIt+tju+J9G1E+EDpDYY4Z7FxpaLGIb0oIM3i+94g VT00Jw584H4zxA9NtQfte4+sqwtv+ctWg1UtH23sfHCijAOIn/AeiT0iC8IHzVLl6ZJ9 nETQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=eQVkb9ZCrSRd/pPQpA+i3Y8dxR7mNEdZ9iRp4q/r61c=; b=VZzPuh8eSFjIczQLu6NB4T0jQVx8kVge4tLnucoODuC3kcjLkEi9BcWjDt1/p2WJqX kW5zo8oSpM2b0I7oY1w1/jUPN6ZZavJjCLm2lP1cdz4L07SGFAQNb3bd5TyI85BBTPYj qdqQRyNpa1BzwyYvp9HJpNOCVLaTsBG5S4oN0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=eQVkb9ZCrSRd/pPQpA+i3Y8dxR7mNEdZ9iRp4q/r61c=; b=AaWxA8WsS0f9nk2Gst5lwEIkM7QhBKJjLXu1Si69ysAb7yq3NSNBkLdzK0j/z0cNcP n4FcoX37ETdOSRB5ZZ7ELvUdy16K4VfC90xx9aBYwknJ03tW1S1bMHK+36dCuYZ6SYq/ KdWMVXD8nvONXAxHyQxUHWPyu7iXfvormha5PgxembYN5Nk5PP2PhHU32k6BcTh/DlET 0gM/A5//BiHON+ZzV2POAO+SlXe+PuRG20ZwyoQzjkfPky02WwQcjT0phoIZyXHKwtfJ dbI4laM3LhQA079cV74pBdMIY+g2rLe7v45PqCd0ozvURH3nciSaiN9dTFJqAa+dx7jS iS7A== X-Gm-Message-State: ALQs6tDipqICCXFbMb5nqiATdpieOctJorvyujoixj+D7H61aVEAZR2Q d4Y7zx+8sxOvV6AGvunEK9dWTaoLupv6KMTlcdQ= X-Received: by 2002:a6b:afdb:: with SMTP id p88-v6mr3619258ioo.257.1524086474781; Wed, 18 Apr 2018 14:21:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.95.15 with HTTP; Wed, 18 Apr 2018 14:21:14 -0700 (PDT) In-Reply-To: <1524039174.3028.24.camel@suse.com> References: <20180417233511.6573-1-mwilck@suse.com> <20180417233511.6573-2-mwilck@suse.com> <1524039174.3028.24.camel@suse.com> From: Linus Torvalds Date: Wed, 18 Apr 2018 14:21:14 -0700 X-Google-Sender-Auth: InOwUIqy1MO_kP9x5ejdSDSYVN0 Message-ID: Subject: Re: [PATCH v3 1/6] ilog2: create truly constant version for sparse To: Martin Wilck Cc: "Martin K. Petersen" , Linux SCSI List , Linux Kernel Mailing List , Hannes Reinecke , James Bottomley , Xose Vazquez Perez , Bart Van Assche , Ard Biesheuvel , Thomas Gleixner , Jonathan Corbet , Randy Dunlap Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 18, 2018 at 1:12 AM, Martin Wilck wrote: > > No, it doesn't (gcc 7.3.0). -> https://paste.opensuse.org/27471594 > It doesn't even warn on an expression like this: > > #define SIZE (1<<10) > static int foo[ilog2(SIZE)]; Ok, I think this is the "random gcc versions act differently" issue. Sometimes __builtin_constant_p() to a ternary operation acts as a constant expression, and sometimes it doesn't. Oh well. > sparse 0.5.2 doesn't warn about that either. Yeah, sparse doesn't get picky about "constant value" vs "constant expression" normally. But some things do use the strict form, and array index expressions is one of those cases. > So maybe I was wrong, and this is actually a false positive in sparse. No, it's correct, it's just that the semantics of exactly when something is considered constant are a bit fluid. > Do you want me to convert the patch to your approach anyway? I suspect using the __is_constexpr() trick would make it rather more technically correct, but would actually generate much worse code. Because it would make us do that dynamic "__ilog2_uXX()" function call even when you have a compile-time constant value, if it wasn't actually a constant expression (ie a constant argument passed to an inline function, for example). So I guess your patch is fine, but I also wonder if we should just default sparse to allow the good old non-strict "constant values are ok" for indexes. And turn on strict mode only with -pedantic or something. Linus