lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 2 Feb 2022 22:20:25 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Miguel Ojeda' <miguel.ojeda.sandonis@...il.com>
CC:     Kees Cook <keescook@...omium.org>,
        Jonathan Corbet <corbet@....net>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Martin Uecker <Martin.Uecker@....uni-goettingen.de>,
        Ingo Molnar <mingo@...nel.org>,
        Rikard Falkeborn <rikard.falkeborn@...il.com>,
        Arnd Bergmann <arnd@...db.de>,
        "linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
        Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: RE: [PATCH] linux/const.h: Explain how __is_constexpr() works

From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
> Sent: 02 February 2022 20:14
> To: David Laight
> 
> On Wed, Feb 2, 2022 at 5:19 PM David Laight <David.Laight@...lab.com> wrote:
> >
> > - The conditional operator (?:) requires that both expressions have the
> >   the same type (after numeric promotions).
> 
> I think you are referring to the arithmetic types case, but that one
> does not apply here.

The type of the result depends on the type of the 2nd and 3rd arguments.
Not on the value of the first one.

> > - If the expressions have distinct non-NULL pointer types then they are both
> >   cast to (void *) and the result has type 'void *'.
> 
> GCC and Clang give `void *` for this, but something like `float *` and
> `int *` do not fit the constrains of the operator.

Compiling:

#define k(x) (sizeof(*(1 ? (float *)8 : (int *)8)))

int f1(void){ return k(6); }

gives:

f1:
        movl    $1, %eax
        ret

(see https://godbolt.org/z/e1MvYYxGz)

Change to #define k(x) (sizeof(*(1 ? (void *)(x) : (int *)0)))
and you only get 4 when x is a compile-time constant 0.

It has nothing to with the condition, the compiler is trying to 'sort out'
a suitable return type.

I suspect the mismatched pointer types might even be a gcc extension.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists