Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3493429pxb; Fri, 4 Feb 2022 09:38:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJymVsZKPLYDBTY/bzGdOzrHAb6VsyY93JVLtM6TFhukLZ2bUcBiIuPZS9mic2wNrjR2WBGp X-Received: by 2002:a63:904c:: with SMTP id a73mr48703pge.449.1643996280063; Fri, 04 Feb 2022 09:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643996280; cv=none; d=google.com; s=arc-20160816; b=MnTOHs8hf4RxiNG5juAQ6DG0vFIFp2X1kwp/HYVZpgVo0CVAKMrVDq6lY4LMbsVXHf 9PdRJVkIFNXVqILofZyLtRS8GdPo0NQUhuiTBi3z8+V3PvoBhnq6JJPZS+6nUDv33Vir d3MFOOezMAxZImQuBA/I9a/bHr8ztq51CAARYnj/507pzq0oXUSQBrUQYnNn22lkyN1W Edd5lvuHo0mv3sT4JM2GOq7n2kWy6O4S0jIhxtfzTbUfgXlplslrFlMsZv7tizgtn8LZ AB45oeah8pltP/xKAOjqVLLy8Evj1jciZZvN4c5wri0g7wEt/JijghhAGCgrKy3bWP5N u+aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qyB3mZFViRKtoK+ZaB1dzKFHtCmielRBwsqk/DQ2WJQ=; b=V2D1aB1pnC1RYUsB9237Eknoz6UQncqcfr09dCjeIDxBtxcryFZwjSl4hDNMYbTkD4 Z+6mdA6jud2j5jctHfB3q4A9e5a8NZxeEXUKGIz/N3oWVYC/OUpI51viVD7CqJIZVG6u kv499zHfLDIuQzt6ZBJiLpICVAOUNJE9cs8fXRXXXTqtHfkq0wdr0eS+wpnAE3ylV9+o zhacxXYS7l5eaawgqFzgJDGSvonyAgTui8qMVaV0l5OaHtNQksnxGL+i2viFeIxqycWy 45p3TA4By5x4fg8GWYmZSxGBGXimp0DdtZHfzb009OWfDCz7ZqAHoUYSSYzJaHE6wiUg DH0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mUVp+yHn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p6si2848724pgs.476.2022.02.04.09.37.47; Fri, 04 Feb 2022 09:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mUVp+yHn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232693AbiBBUnV (ORCPT + 99 others); Wed, 2 Feb 2022 15:43:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347202AbiBBUnT (ORCPT ); Wed, 2 Feb 2022 15:43:19 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D932BC061714; Wed, 2 Feb 2022 12:43:19 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id s18so566954ioa.12; Wed, 02 Feb 2022 12:43:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qyB3mZFViRKtoK+ZaB1dzKFHtCmielRBwsqk/DQ2WJQ=; b=mUVp+yHnfU+Ky+xnhzeuAas2HJgzIGVaqSkvPow3NXucLX1B/su2vti0ba/qw8x581 2/jI+nwO+Oe2ECIk6ak3NofPP0IzJVvCUwEwqZSitjN+154j8mH2c+XKO/xTXM0T/SuJ li6I5HcI/xFwePbFHt8CDVUQOQ5UPkyp1pMrC7Q7sldI3q/WxSxPBg176xjV1IlNmFuG Fg5CNrKqWDIFfoVeV9sQTq76VKtLRaRzXQwjy7U+o1jfKpx5qjp2iT9dLSL9FOXdgRtR nYVYCqRapRJjZBDC5/6VCuymW1Z93T0uiWSgCnvFLeDHwJtYIvqdORtLt/9WnE7tEv55 D3eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qyB3mZFViRKtoK+ZaB1dzKFHtCmielRBwsqk/DQ2WJQ=; b=BwqH1klse1OxjqgS7wO1MElFwa57K76DnSdBG47W8BqlfCZ6EFYWvFCSrd/fYwM04j qnH2YMNNIO2kJ1kB1Ex4EcwvmcZCu8V8L6F0EVPMfvP/2rwAnI9tDTOGg1TRbZzqWIx2 Arzw5FDJKOm3Hw9RoyMVcYbYmd/R0Z08g+f4xrlzDd3CBi2RqODjMBCdry5AIBoq/4as RsN2pxzs/x8jf+Qak7PcKnIfMudcJ5U45wn0xLpjqDmz8Wwdh3KemKyOE7cOvZJLNiF2 OnY8HAaAS4RlwIuCucyneVh9pFkNt5BIMnj+k+8I9vLLFkBU5xhYgMaU0qs37HQytjLI 2Leg== X-Gm-Message-State: AOAM531B4WBdcWJiHB82G8pyUrfxzmUUvXRs6jdB6ryZcTI2sokEABQo U5OVPZX3xgkCQsRGuurJxg0NLs222P61C/YInGo= X-Received: by 2002:a05:6638:382a:: with SMTP id i42mr15171407jav.256.1643834599082; Wed, 02 Feb 2022 12:43:19 -0800 (PST) MIME-Version: 1.0 References: <20220131204357.1133674-1-keescook@chromium.org> In-Reply-To: <20220131204357.1133674-1-keescook@chromium.org> From: Miguel Ojeda Date: Wed, 2 Feb 2022 21:43:08 +0100 Message-ID: Subject: Re: [PATCH] linux/const.h: Explain how __is_constexpr() works To: Kees Cook Cc: Jonathan Corbet , Linus Torvalds , Martin Uecker , Ingo Molnar , Rikard Falkeborn , Arnd Bergmann , Linux Doc Mailing List , Tetsuo Handa , Andrew Morton , Andy Shevchenko , Nick Desaulniers , "Gustavo A. R. Silva" , linux-kernel , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 9:43 PM Kees Cook wrote: > > + * - The conditional operator ("... ? ... : ...") returns the type of the > + * operand that isn't a null pointer constant. This behavior is the Perhaps clarify that this happens only if it fits that case? ... > + * - If (x) is an integer constant expression, then the "* 0l" resolves it > + * into a null pointer constant, which forces the conditional operator > + * to return the type of the last operand: "(int *)". > + * - If (x) is not an integer constant expression, then the type of the > + * conditional operator is from the first operand: "(void *)". ... i.e. this one happens because it is specified as returning a pointer to void (one could read it as returning the type of the first operand). What about something like: - The behavior (including its return type) of the conditional operator ("... ? ... : ...") depends on the kind of expressions given for the second and third operands. This is the central mechanism of the macro. - If (x) is an integer constant expression, then the "* 0l" resolves it into a null pointer constant. When one operand is a null pointer constant and the other is a pointer, the conditional operator returns the type of the pointer operand; that is, "int *". - If (x) is not an integer constant expression, then that operand is a pointer to void (but not a null pointer constant). When one operand is a pointer to void and the other a pointer to an object type, the conditional operator returns a "void *" type. Cheers, Miguel