[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAA2zVHrF+teb3SwigH_sDqkWfKDg4itq4TkefYXUXw2RF9+4qw@mail.gmail.com>
Date: Thu, 05 Apr 2018 20:51:31 +0000
From: James Y Knight <jyknight@...gle.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>, mka@...omium.org,
arnd@...db.de, Ingo Molnar <mingo@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
tglx@...utronix.de, Andrew Morton <akpm@...ux-foundation.org>,
Chandler Carruth <chandlerc@...gle.com>,
Stephen Hines <srhines@...gle.com>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Kees Cook <keescook@...gle.com>, groeck@...omium.org,
Greg Hackmann <ghackmann@...gle.com>,
gregkh@...uxfoundation.org
Subject: Re: [GIT PULL] x86/build changes for v4.17
On Thu, Apr 5, 2018 at 2:06 PM Linus Torvalds
<torvalds@...ux-foundation.org>
wrote:
> On Thu, Apr 5, 2018 at 10:46 AM, James Y Knight <jyknight@...gle.com>
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. :)
Powered by blists - more mailing lists