From patchwork Wed Oct 5 23:49:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramsay Jones X-Patchwork-Id: 9363567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F0BF3607D6 for ; Wed, 5 Oct 2016 23:49:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA45228D1F for ; Wed, 5 Oct 2016 23:49:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCD1C28D33; Wed, 5 Oct 2016 23:49:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3451228D1F for ; Wed, 5 Oct 2016 23:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932309AbcJEXtY (ORCPT ); Wed, 5 Oct 2016 19:49:24 -0400 Received: from avasout02.plus.net ([212.159.14.17]:46179 "EHLO avasout02.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932190AbcJEXtY (ORCPT ); Wed, 5 Oct 2016 19:49:24 -0400 Received: from [10.0.2.15] ([194.75.29.46]) by avasout02 with smtp id rzpJ1t0050zhorE01zpKEN; Thu, 06 Oct 2016 00:49:21 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.2 cv=G/5eKJs5 c=1 sm=1 tr=0 a=g54qAj+LxVGqXy9pVcJ+0w==:117 a=g54qAj+LxVGqXy9pVcJ+0w==:17 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=wDjg58x2tn9MiKexBWQA:9 a=QEXdDO2ut3YA:10 a=yJM6EZoI5SlJf8ks9Ge_:22 X-AUTH: ramsayjones@:2500 To: Christopher Li Cc: Sparse Mailing-list From: Ramsay Jones Subject: [PATCH v2] sparse: add 'alloc_align' to the ignored attributes Message-ID: <9a2e66f5-fdd3-1785-218b-4d5071d301c3@ramsayjones.plus.com> Date: Thu, 6 Oct 2016 00:49:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ramsay Jones --- Hi Christopher, As you requested, I have added a test for v2 of the patch. [BTW gcc (version 5.4.0) issues numerous 'enumeration value not handled in switch' warnings while compiling parse.c.] ATB, Ramsay Jones parse.c | 2 ++ validation/alloc-align.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 validation/alloc-align.c diff --git a/parse.c b/parse.c index b43d683..4b03192 100644 --- a/parse.c +++ b/parse.c @@ -504,6 +504,8 @@ static struct init_keyword { const char *ignored_attributes[] = { "alias", "__alias__", + "alloc_align", + "__alloc_align__", "alloc_size", "__alloc_size__", "always_inline", diff --git a/validation/alloc-align.c b/validation/alloc-align.c new file mode 100644 index 0000000..e414257 --- /dev/null +++ b/validation/alloc-align.c @@ -0,0 +1,38 @@ +typedef unsigned long int size_t; + +/* + * The alloc_align attribute is used to tell the compiler that the return + * value points to memory, where the returned pointer minimum alignment is given + * by one of the functions parameters. GCC uses this information to improve + * pointer alignment analysis. + * + * The function parameter denoting the allocated alignment is specified by one + * integer argument, whose number is the argument of the attribute. Argument + * numbering starts at one. + * + * For instance, + * + * void* my_memalign(size_t, size_t) __attribute__((alloc_align(1))) + * + * declares that my_memalign returns memory with minimum alignment given by + * parameter 1. + */ + +#define __alloc_align(x) __attribute__((__alloc_align__(x))) + +/* + * The aligned_alloc function allocates space for an object whose alignment is + * specified by alignment, whose size is specified by size, and whose value is + * indeterminate. The value of alignment shall be a valid alignment supported + * by the implementation and the value of size shall be an integral multiple + * of alignment. + * + * The aligned_alloc function returns either a null pointer or a pointer to the + * allocated space. + */ +void *aligned_alloc(size_t alignment, size_t size) __alloc_align(1); + + +/* + * check-name: attribute __alloc_align__ + */