From patchwork Sun Aug 11 23:46:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 1971396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=HRrpuwqD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WhvSM3FF7z1ydh for ; Mon, 12 Aug 2024 09:46:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 658853858C52 for ; Sun, 11 Aug 2024 23:46:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by sourceware.org (Postfix) with ESMTPS id 710C83858D34 for ; Sun, 11 Aug 2024 23:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 710C83858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 710C83858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2604:1380:4641:c500::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723419979; cv=none; b=JnLNIAzopo7TQKksyx+0lv0HKjohyyQfz5D1T4mtUNO1rs84vb91l1cSunRip8oqpFDxAobeMdhmCVOi+jMWGxn75/UPAjvez1rbOVGOnRfnjLotFH5wnIlsL1bXiv7SHydxt56Ykdc77yKRag9ED+SosP1fvlZBMFA53WelrkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723419979; c=relaxed/simple; bh=ccN1evg2kC4MjSHtIqa5mPxH/1k9GTs4xH8BYdM+1U8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=fFsWGaKTd2F2VBgcIrp7URHQi5h39KSUgUnXu/Knu5xV50UZRwDZEd+VN2jBOuHNpzOemxs0qQXLS2WNnkZzvE9uXdBiL53Z8sDQANCLAc93l86Udf7BwLSOnd0AJ8+gt48L9G8ei8WI1wWyL9rqykUPPCByWrwRJ3uyN2tiVg8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A100B60FCB; Sun, 11 Aug 2024 23:46:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85DACC32786; Sun, 11 Aug 2024 23:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723419976; bh=ccN1evg2kC4MjSHtIqa5mPxH/1k9GTs4xH8BYdM+1U8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HRrpuwqD82E4R3u4zYH9Zfqi5RcFkL7hwHDZoPEHhE8tdGwf4M44aeo7NT90VOeWZ ZnTI1ebJn/YCaWfspMWLRerSEJ81ond7HQM6t4wZU5oLkEncUGS5ePds1bvxAUVHS/ I8CkBoR8qHh6pKpT8ieO75C1uQ3x/ikGte5aY8EyyHXXIUyKKEei9SNyF26yGj8FQp BgkBFcTMhvYF5hL3sEJ93W2OO6oJspb7ClXHfTkU3pOmZLNPAP75S5HL/UTPAeHCaj u5YhNQ5zxd61MzZoeiTowWU7nvi7T6R5XlGvbW66qEtKSknUCVDQUFPDKGMNhyToss YhPBJVHscq6Aw== Date: Mon, 12 Aug 2024 01:46:11 +0200 From: Alejandro Colomar To: gcc-patches@gcc.gnu.org Cc: Alejandro Colomar , Martin Uecker , Xavier Del Campo Romero , Joseph Myers , Gabriel Ravier , Jakub Jelinek , Kees Cook , Qing Zhao , Jens Gustedt , David Brown , Florian Weimer , Andreas Schwab , Timm Baeder Subject: [PATCH v8 0/3] c: Add __lengthof__ operator Message-ID: X-Mailer: git-send-email 2.45.2 References: <20240728141547.302478-1-alx@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240728141547.302478-1-alx@kernel.org> X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! v8: - Reformat (simplify) change-log entries. - Improve wording of documentation. - Add link to LLVM issue in commit message. I've added a GitHub issue in the LLVM project reporting about the existence of this patch set: Have a lovely night! Alex Alejandro Colomar (3): gcc/: Rename array_type_nelts() => array_type_nelts_minus_one() Merge definitions of array_type_nelts_top() c: Add __lengthof__ operator gcc/c-family/c-common.cc | 26 ++++ gcc/c-family/c-common.def | 3 + gcc/c-family/c-common.h | 2 + gcc/c/c-decl.cc | 30 +++-- gcc/c/c-fold.cc | 7 +- gcc/c/c-parser.cc | 61 +++++++--- gcc/c/c-tree.h | 4 + gcc/c/c-typeck.cc | 118 ++++++++++++++++++- gcc/config/aarch64/aarch64.cc | 2 +- gcc/config/i386/i386.cc | 2 +- gcc/cp/cp-tree.h | 1 - gcc/cp/decl.cc | 2 +- gcc/cp/init.cc | 8 +- gcc/cp/lambda.cc | 3 +- gcc/cp/operators.def | 1 + gcc/cp/tree.cc | 13 -- gcc/doc/extend.texi | 31 +++++ gcc/expr.cc | 8 +- gcc/fortran/trans-array.cc | 2 +- gcc/fortran/trans-openmp.cc | 4 +- gcc/rust/backend/rust-tree.cc | 13 -- gcc/rust/backend/rust-tree.h | 2 - gcc/target.h | 3 + gcc/testsuite/gcc.dg/lengthof-compile.c | 115 ++++++++++++++++++ gcc/testsuite/gcc.dg/lengthof-vla.c | 46 ++++++++ gcc/testsuite/gcc.dg/lengthof.c | 150 ++++++++++++++++++++++++ gcc/tree.cc | 17 ++- gcc/tree.h | 3 +- 28 files changed, 598 insertions(+), 79 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/lengthof-compile.c create mode 100644 gcc/testsuite/gcc.dg/lengthof-vla.c create mode 100644 gcc/testsuite/gcc.dg/lengthof.c Range-diff against v7: 1: 8b68e250503 ! 1: a6aa38c9013 gcc/: Rename array_type_nelts() => array_type_nelts_minus_one() @@ Commit message gcc/ChangeLog: - * tree.cc (array_type_nelts): Rename function ... - (array_type_nelts_minus_one): ... to this name. The old name - was misleading. - * tree.h (array_type_nelts): Rename function ... - (array_type_nelts_minus_one): ... to this name. The old name - was misleading. + * tree.cc (array_type_nelts, array_type_nelts_minus_one): + * tree.h (array_type_nelts, array_type_nelts_minus_one): * expr.cc (count_type_elements): - Rename array_type_nelts() => array_type_nelts_minus_one() * config/aarch64/aarch64.cc - (pure_scalable_type_info::analyze_array): Likewise. - * config/i386/i386.cc (ix86_canonical_va_list_type): Likewise. + (pure_scalable_type_info::analyze_array): + * config/i386/i386.cc (ix86_canonical_va_list_type): + Rename array_type_nelts() => array_type_nelts_minus_one() + The old name was misleading. gcc/c/ChangeLog: * c-decl.cc (one_element_array_type_p, get_parm_array_spec): + * c-fold.cc (c_fold_array_ref): Rename array_type_nelts() => array_type_nelts_minus_one() - * c-fold.cc (c_fold_array_ref): Likewise. gcc/cp/ChangeLog: * decl.cc (reshape_init_array): + * init.cc + (build_zero_init_1): + (build_value_init_noctor): + (build_vec_init): + (build_delete): + * lambda.cc (add_capture): + * tree.cc (array_type_nelts_top): Rename array_type_nelts() => array_type_nelts_minus_one() - * init.cc (build_zero_init_1): Likewise. - (build_value_init_noctor): Likewise. - (build_vec_init): Likewise. - (build_delete): Likewise. - * lambda.cc (add_capture): Likewise. - * tree.cc (array_type_nelts_top): Likewise. gcc/fortran/ChangeLog: * trans-array.cc (structure_alloc_comps): + * trans-openmp.cc + (gfc_walk_alloc_comps): + (gfc_omp_clause_linear_ctor): Rename array_type_nelts() => array_type_nelts_minus_one() - * trans-openmp.cc (gfc_walk_alloc_comps): Likewise. - (gfc_omp_clause_linear_ctor): Likewise. gcc/rust/ChangeLog: 2: 21433097103 ! 2: 43300a17e4a Merge definitions of array_type_nelts_top() @@ Commit message gcc/ChangeLog: * tree.h (array_type_nelts_top): - * tree.cc (array_type_nelts_top): Define function (moved from - gcc/cp/). + * tree.cc (array_type_nelts_top): + Define function (moved from gcc/cp/). gcc/cp/ChangeLog: * cp-tree.h (array_type_nelts_top): - * tree.cc (array_type_nelts_top): Remove function (move - to gcc/). + * tree.cc (array_type_nelts_top): + Remove function (move to gcc/). gcc/rust/ChangeLog: * backend/rust-tree.h (array_type_nelts_top): - * backend/rust-tree.cc (array_type_nelts_top): Remove function. + * backend/rust-tree.cc (array_type_nelts_top): + Remove function. Signed-off-by: Alejandro Colomar 3: 4bd3837d09c ! 3: e6af87d54af c: Add __lengthof__ operator @@ Commit message Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2529.pdf Link: https://inbox.sourceware.org/gcc/M8S4oQy--3-2@tutanota.com/T/ + Link: https://github.com/llvm/llvm-project/issues/102836 Suggested-by: Xavier Del Campo Romero Co-developed-by: Martin Uecker Signed-off-by: Alejandro Colomar @@ gcc/doc/extend.texi: If the operand of the @code{__alignof__} expression is a fu +The keyword @code{__lengthof__} determines the length of an array operand, +that is, the number of elements in the array. +Its syntax is similar to @code{sizeof}. -+The operand must be a complete array type or an expression of that type. ++The operand must be ++a parenthesized complete array type name ++or an expression of such a type. +For example: + +@smallexample @@ gcc/doc/extend.texi: If the operand of the @code{__alignof__} expression is a fu +__lengthof__ (int [7][3]); // returns 7 +@end smallexample + -+The operand is not evaluated -+if the top-level length designator is an integer constant expression -+(in this case, the operator results in an integer constant expression); -+and it is evaluated -+if the top-level length designator is not an integer constant expression -+(in this case, the operator results in a run-time value). ++The result of this operator is an integer constant expression, ++unless the top-level array is a variable-length array. ++The operand is only evaluated ++if the top-level array is a variable-length array. +For example: + +@smallexample