Received: by 10.213.65.68 with SMTP id h4csp2373598imn; Thu, 5 Apr 2018 13:53:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/UzSGKN/qi3ANFMDEMz4vL+Ea5BtSMaKHLvQjAaldDYECNGu0HY4iJmUJJ/MLbqlOmbZ9N X-Received: by 10.101.73.141 with SMTP id r13mr16094262pgs.426.1522961627274; Thu, 05 Apr 2018 13:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522961627; cv=none; d=google.com; s=arc-20160816; b=AERCwbtkd5XTpT8pUyWA2eXZzatuezYJifHtugL7MJYgZriE2dPhNKWFbkGBAM70PX Kcq/wvmvEQ3ZJXWKx1b0Dyj2BEMbxJa1UscUedssmklsOqqW1k8Jid79DFRs+sCXbxpN ndyRU84FzE5L7TEX1XboNrQyvgHzCBBD0GoNwM5q3i4ybZu52b9aPSVFytdq/no0JzTu ZzE4uDfOPG4/RM6yYbS7NeWacZezK9m0YEVdRmI8PId6Q9vm1u+WQz5HTnG/e+K+YRUk BMxYwbszbGfTaq4U+d5eBncBbrPhhF9ixc+quSUJM3w9Dlvc5xlD2pXjwrU2p4QZ5jJr qsAQ== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=LhjugTnBiCG4ICRGbdDBl1X0QrCsmhDlOmNjYdL6/ao=; b=Tom2K+LyfTO71UT/OPpedghABDJcogHa+ywwFxxUJrzbsqoyRqXOKXDzvUlom4jW5/ eYpKbbB/yTnIf0IPoGZvdYkzQ7d9fZJScinTYs+V8tERmLPrBC4GTfrSczv5GoXCdfKF IX/rNsxIUzRRlopTaBY6lxylZHJX4BnbSernuK9YTYBd6XIDxWAXTTFDBY1gn4YuCQgZ 9uDWZFpvxvS0sjR/T57KA/UEYsfOYodrFGIMryrImZc/PwJ1UvpRGjiH2++LELt/VjmJ ClM7ovlmWod3qcuu0wjjbA1Y9mnXFg1z0EyvONeqITTC0k3NxI2ZMYhJp//egYSsSIi7 rMrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QRwtJtP+; 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 a190si6061232pge.436.2018.04.05.13.53.32; Thu, 05 Apr 2018 13:53:47 -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=pass header.i=@google.com header.s=20161025 header.b=QRwtJtP+; 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 S1751516AbeDEUwA (ORCPT + 99 others); Thu, 5 Apr 2018 16:52:00 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:38568 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155AbeDEUv6 (ORCPT ); Thu, 5 Apr 2018 16:51:58 -0400 Received: by mail-vk0-f68.google.com with SMTP id b16so15329138vka.5 for ; Thu, 05 Apr 2018 13:51:58 -0700 (PDT) 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; bh=LhjugTnBiCG4ICRGbdDBl1X0QrCsmhDlOmNjYdL6/ao=; b=QRwtJtP+fUUWYyWbvdJynz7VGPsZgUNp67My+Qff8zSDO0OBcQEo2Yfn87Nzw7cms1 UVtKFJI3t6NpUqR/+mV3rDwJYz4VQkzfYPH7Uo8o26pxaddUMwZXiokU5NCHD4ghC7Zt VybfpZWBPWBxbuhzbauap6WYCUGR7eBP7jJUQ2J4ew6k1yTXlNs5iAC/Mdrt8EbdIxpc R2a3bZIZwMlDWi+aIbgWnBjdNm6RP0Ps5illzouDyZNIYhrR9UbmZM2tV+Osc2HbfAl/ xvgBNfmA2RkXH3qlpWhTWq19bH6RrLK4WovySd9QcvyaRk5ud/DshGzZLLRiYCBRL6nM 0E0w== 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; bh=LhjugTnBiCG4ICRGbdDBl1X0QrCsmhDlOmNjYdL6/ao=; b=QNwiWODBoDaAmODVKXj16Zr2oPHdwXzAyRo4yivRoHsulIoUOhpwLOZHkMO+XkEIfU 7ITOdL7QsTwSOD4DN9fUKbM0Ho/6sLx52mrBSlaw5iNf/gXDQSj75P9kfYMioO6VoeVg il4Nf5cXdf5PgQrMypfRa4X+en75EdSj/NqJjb9u58wSnfW069MkhqTe11Vz4OgIRPlp G37PFCSNT5gyCh+BD72lCnZjYXz5Tcg7Ug9RpjV97Jbs4lzlo6BjWZHWoRwVy3xm9GKW ParG/GF9y+WtG2Y3w53CwyJiOk7X0z1hDv0MfTBjTyWWPf4SCcgxWp3mtSUQM0HcrzlW Z/pg== X-Gm-Message-State: ALQs6tBdKxQBNjIsyTVC3LbVdlVr93v/apSJNnlpcO9TRUsuT6pq+0BE bkRtJyLi0P6umRRUYI02lXQt9B1JQTPXGPlhyQYOPw== X-Received: by 10.31.127.6 with SMTP id o6mr14988233vki.34.1522961517599; Thu, 05 Apr 2018 13:51:57 -0700 (PDT) MIME-Version: 1.0 References: <20180404093007.GI4082@hirez.programming.kicks-ass.net> <20180404191724.GF87376@google.com> <20180404205848.GG87376@google.com> <20180404214639.GH87376@google.com> <20180404221744.GI87376@google.com> <20180404233111.GJ87376@google.com> <20180405072017.GN4043@hirez.programming.kicks-ass.net> In-Reply-To: From: James Y Knight Date: Thu, 05 Apr 2018 20:51:31 +0000 Message-ID: Subject: Re: [GIT PULL] x86/build changes for v4.17 To: Linus Torvalds Cc: Peter Zijlstra , mka@chromium.org, arnd@arndb.de, Ingo Molnar , Linux Kernel Mailing List , tglx@linutronix.de, Andrew Morton , Chandler Carruth , Stephen Hines , Nick Desaulniers , Kees Cook , groeck@chromium.org, Greg Hackmann , gregkh@linuxfoundation.org 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 Thu, Apr 5, 2018 at 2:06 PM Linus Torvalds wrote: > On Thu, Apr 5, 2018 at 10:46 AM, James Y Knight wrote: > > > > GCC, however, mixes up the concept of a C "constant expression" with the > > results of running optimization passes such as inlining for its > > definition/implementation of __builtin_constant_p. Clang does not, and quite > > likely will not ever, do that. > Nothing has ever said that "__builtin_constant_p(x)" means "is x an > integer constant expression" I had actually meant that the __builtin_constant_p **itself** had to be a constant expression, not that its *argument* must be an I-C-E for __builtin_constant_p to return true. But after spending some time on further investigating in order to show an example of how this matters, I must take back my words. I was mistaken about GCC's semantics. Take this example: === int function(void); void useval(int*); int f() { int v = 1 + 2; int array[2][__builtin_constant_p(v) ? 1 : 100]; useval(array[0]); return sizeof(array[function()]) / sizeof(array[0]); } === Build with "gcc -O -std=c99": === f: subq $24, %rsp leaq 8(%rsp), %rdi call useval call function movl $4, %eax addq $24, %rsp ret === Note the fact that "function" is actually *called* indicates that 'array' is a VLA (...and that C99's sizeof(VLA) semantics are bonkers, but that's another story...). Which means that __builtin_constant_p(v) was _not_ evaluated as an integer constant expression by GCC. Instead, it was left as an expression. And, the stack frame being only 24 bytes indicates that the __bcp eventually evaluated to true. I actually think this actually _is_ something clang can implement. Thanks for making me try to prove myself. :)