From patchwork Tue Oct 22 18:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 57567 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90F023858C32 for ; Tue, 22 Oct 2024 18:49:02 +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 [139.178.84.217]) by sourceware.org (Postfix) with ESMTPS id C820F3858D21 for ; Tue, 22 Oct 2024 18:48:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C820F3858D21 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 C820F3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=139.178.84.217 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729622896; cv=none; b=HRVweOhvojDifuEsK4qFC8SujEsQXjbVEujpGDsaafN4hK5C9/Rn7tn8jbK0RIcIVblmMZvjwN2ivOHOibXkilx5m3MBUrjrCMFqdy2fn6KLP0Q09yJK0YNzC+pY7xAcnqXqwfyn3Vb/Pwne/Gz0p+oHcPv5gVWxS+GhJ73dONQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729622896; c=relaxed/simple; bh=7poyGnsfp3z+olkYsej3incrREciA9dRGVqIkIkj3f4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=szd2CXMgl7x3ONDUN+Wz0VuD+FlfoazxMA8nA/SmuyIyDhXYtZDTOaJNIpBL2He529+sk9U3O1bIkrnyFY8bCqohubrFCkBtSEnXylTDelOqagN06KnGcHW+GC2xGlWdEhnmg+AtY1D5w4SeANnxA9yHNEznRwMLcAjhCNNtMBU= 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 363025C593F; Tue, 22 Oct 2024 18:48:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D78DFC4CEC3; Tue, 22 Oct 2024 18:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729622890; bh=7poyGnsfp3z+olkYsej3incrREciA9dRGVqIkIkj3f4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lIAAS8W5SBTp4q2HiwLNUJ/rtWTpWaf0j9yRFEPQ2rZsRxp3086uxltIjPh1HdZP5 xKNza4sg7X32XQHnNnZlYzQWlwsOvkXpp2jRk6YC8N901WkcL3BIehqDXgF7sQDPT+ G7HCGLaNTVRO+q02sBnEdYGa+ecjkiFA2NARqRb5qkv96OZinVVSIbZONmt/Yo4sIM Vk6VUmxwCsH6xAQOTO5tnK2mlfUKQS00BgkIE13fVJ3Oc+Anv478ZYBd1uvUa77mCi F6FpB0nQgARARK+etlA15uLo1xFyk9nZB1rWlYfJ8cAmeMrPP10VuMikrru7xq92U4 cLbtuMLeZqZdg== Date: Tue, 22 Oct 2024 20:48:07 +0200 From: Alejandro Colomar To: gcc-patches@gcc.gnu.org, josmyers@redhat.com Cc: Alejandro Colomar Subject: [PATCH v17 0/2] c: Add __countof__ operator Message-ID: X-Mailer: git-send-email 2.45.2 References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240728141547.302478-1-alx@kernel.org> X-Spam-Status: No, score=-4.2 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 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~patchwork=sourceware.org@gcc.gnu.org Hi Joseph, I found some tests that could be improved, so I've worked on that in the last few days. I'll post as a reply to this email the bootstrap and regression testing results. v17 changes: - Rebase (patches 2/4 and 3/4 from v16b have been merged already). - Improve and add tests. Below is the range diff against v16b. Have a lovely night! Alex Alejandro Colomar (2): contrib/: Add support for Cc: and Link: tags c: Add __countof__ operator contrib/gcc-changelog/git_commit.py | 5 +- 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 | 22 +++- gcc/c/c-parser.cc | 62 +++++++--- gcc/c/c-tree.h | 4 + gcc/c/c-typeck.cc | 118 ++++++++++++++++++- gcc/doc/extend.texi | 30 +++++ gcc/testsuite/gcc.dg/countof-compile.c | 127 +++++++++++++++++++++ gcc/testsuite/gcc.dg/countof-vla.c | 46 ++++++++ gcc/testsuite/gcc.dg/countof.c | 150 +++++++++++++++++++++++++ 12 files changed, 570 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/countof-compile.c create mode 100644 gcc/testsuite/gcc.dg/countof-vla.c create mode 100644 gcc/testsuite/gcc.dg/countof.c Range-diff against v16b: 1: eac2d18d8a0 = 1: d847dc4a795 contrib/: Add support for Cc: and Link: tags 2: 7418a11fcd6 < -: ----------- gcc/: Rename array_type_nelts => array_type_nelts_minus_one 3: 0cfae0598b3 < -: ----------- gcc/: Merge definitions of array_type_nelts_top 4: 12a30a2a6fd ! 2: 936f7945fae c: Add __countof__ operator @@ gcc/testsuite/gcc.dg/countof-compile.c (new) +static int y[__countof__(z)]; + +void -+automatic(void) ++completed (void) +{ -+ __countof__ (w); ++ int i = 42; ++ int a[] = {1, 2, i}; ++ ++ _Static_assert(__countof__ (w) == 3); ++ __countof__ (a); +} + +void @@ gcc/testsuite/gcc.dg/countof-compile.c (new) +{ + __countof__ (x); /* { dg-error "incomplete" } */ + -+ /* We want to support the following one in the future, -+ but for now it should fail. */ ++ /* We want to support array parameters in the future, ++ which should change this from "invalid" to "incomplete". */ + __countof__ (p); /* { dg-error "invalid" } */ +} + @@ gcc/testsuite/gcc.dg/countof-compile.c (new) + __countof__ (s.fam); /* { dg-error "incomplete" } */ +} + ++void ++param (int n, int p[n]) ++{ ++ /* We want to support array parameters in the future, ++ which would make this work. */ ++ __countof__ (p); /* { dg-error "invalid" } */ ++} ++ +void fix_fix (int i, char (*a)[3][5], int (*x)[__countof__ (*a)]); +void fix_var (int i, char (*a)[3][i], int (*x)[__countof__ (*a)]); +void fix_uns (int i, char (*a)[3][*], int (*x)[__countof__ (*a)]);