Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8CB4C433E0 for ; Fri, 5 Jun 2020 13:44:29 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A763206E6 for ; Fri, 5 Jun 2020 13:44:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hM/8gCUL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A763206E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6B3B18714B; Fri, 5 Jun 2020 13:44:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SN_Hivc0M9dL; Fri, 5 Jun 2020 13:44:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 06CD286B4F; Fri, 5 Jun 2020 13:44:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EA530C0888; Fri, 5 Jun 2020 13:44:28 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6F2A6C016E for ; Fri, 5 Jun 2020 13:44:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 5F225884DC for ; Fri, 5 Jun 2020 13:44:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q5AGB+9+UC1Z for ; Fri, 5 Jun 2020 13:44:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by hemlock.osuosl.org (Postfix) with ESMTPS id E747988778 for ; Fri, 5 Jun 2020 13:44:27 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id h95so2751726pje.4 for ; Fri, 05 Jun 2020 06:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3CR1z9NG03ePu7G+tgZJY9zyBtNaGEunTpnX9HF6W0s=; b=hM/8gCULjRc+sV7QL80KfOKcw7rz7EgJZSm2W9pksCmGcaKh6uZTSS1BosotoK5waM gs4G1OMr8Uscj1tdALlND9FrR0wN12y5OiDs0nMGnbkobAfNPCbhvH2kjfteWcvd5Q0R ZA45CMsWszdwcT3meZnArs20YYo3qymavY2bOmZonTlYuuUYlH4Wx71T3yghRpQaupuF rKQ2mFgez5UaZNot8ENuKd5T5bH1XglPg2TBRttLwXlmQfhbJBSq7W9SFJ6hSe/W/m2U DxrqhGk8jVb7Y11MhUBWfb8cnwEPuIj1dX0oGkOBl4SVctHkzW41I45QaeM/xHm4MnIT WSUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3CR1z9NG03ePu7G+tgZJY9zyBtNaGEunTpnX9HF6W0s=; b=lI5UOsXE0OGAKL7W9aFucYyeNA8YBkCqTTZ8jj/xiH6Z5iCc8QcGwzsIEmFNTvIR0p EMZUQ/LiCFQHbKV8yfQYPfrAoesTUgUnXk5zeMjt5FDUVkIrgyaIYL6iPzxlvy3jOdar WLLcmEMaPs/aCO6v5nMnscyNbn5B+tZbAzDhzum72uL7KJ4g4YPgx59WiH+dVN+7ObjP VI04DvpsaWIXPaq0HAVtTuPEzB1uSdO2xMUm9ykMzvlx9H/cqqBVSWFZunPSbYd6NFGN qCZm9WCHhvGogALDtG3gBrk+PQaXK79kyvDLSB7cQofeNFJ1JRGCk0JD/w/L4QxYEs41 FkUw== X-Gm-Message-State: AOAM530Lbg14am4IS4J4YaCor5/2C+oiSkUJKie/1U4R98R6uvdrCLzd FPWH1SkfH7PKCUhoVdOzQeU= X-Google-Smtp-Source: ABdhPJzawQgtI/bL3wpRFIIiWFWNvd0iItEBFiMnVmNkF+J4mJL93eUnPCYffGwMliByLwGtEaAOCw== X-Received: by 2002:a17:90b:193:: with SMTP id t19mr3149586pjs.155.1591364667424; Fri, 05 Jun 2020 06:44:27 -0700 (PDT) Received: from localhost.localdomain ([1.38.221.125]) by smtp.gmail.com with ESMTPSA id w186sm7861353pff.83.2020.06.05.06.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2020 06:44:27 -0700 (PDT) From: Jaskaran Singh To: cocci@systeme.lip6.fr Date: Fri, 5 Jun 2020 19:13:15 +0530 Message-Id: <20200605134322.15307-8-jaskaransingh7654321@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200605134322.15307-1-jaskaransingh7654321@gmail.com> References: <20200605134322.15307-1-jaskaransingh7654321@gmail.com> MIME-Version: 1.0 Cc: julia.lawall@inria.fr, jaskaransingh7654321@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees] [PATCH v4 07/14] parsing_c: parser: Add attribute production in spec_qualif_list X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" As per GCC's C grammar, the specifier-qualifier-list has the following production: specifier-qualifier-list: gnu-attributes specifier-qualifier-list[opt] Add this production to the spec_qualif_list rule of Coccinelle's C parser. This parses attributes in struct fields and casts successfully. Some code examples from Linux v5.5-rc4: kernel/rcu/tree.h: struct rcu_node { ... raw_spinlock_t __private lock; ... }; kernel/sysctl.c: char __user **buffer = (char __user **)buf; Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index 443ac59f..d24ab7b8 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1500,10 +1500,12 @@ abstract_declaratorp: /*(* for struct and also typename *)*/ /*(* can't put decl_spec cos no storage is allowed for field struct *)*/ spec_qualif_list2: - | type_spec { addTypeD ($1, nullDecl) } - | type_qualif { {nullDecl with qualifD = (fst $1,[snd $1])}} - | type_spec spec_qualif_list { addTypeD ($1,$2) } - | type_qualif spec_qualif_list { addQualifD ($1,$2) } + | type_spec { ([], addTypeD ($1, nullDecl)) } + | type_qualif { ([], {nullDecl with qualifD = (fst $1,[snd $1])})} + | attribute { ([$1], nullDecl) } + | type_spec spec_qualif_list { (fst $2, addTypeD ($1,snd $2)) } + | type_qualif spec_qualif_list { (fst $2, addQualifD ($1,snd $2)) } + | attribute spec_qualif_list { ([$1]@(fst $2), snd $2) } spec_qualif_list: spec_qualif_list2 { dt "spec_qualif" (); $1 } @@ -1521,9 +1523,12 @@ type_qualif_list: type_name: | spec_qualif_list - { let (returnType, _) = fixDeclSpecForDecl $1 in returnType } + { let (attrs, ds) = $1 in + let (returnType, _) = fixDeclSpecForDecl ds in returnType } | spec_qualif_list abstract_declaratort - { let (returnType, _) = fixDeclSpecForDecl $1 in $2 returnType } + { let (attrs1, ds) = $1 in + let (returnType, _) = fixDeclSpecForDecl ds in + $2 returnType } @@ -1808,7 +1813,8 @@ struct_decl2: field_declaration: | spec_qualif_list struct_declarator_list TPtVirg { - let (returnType,storage) = fixDeclSpecForDecl $1 in + let (attrs, ds) = $1 in + let (returnType,storage) = fixDeclSpecForDecl ds in if fst (unwrap storage) <> NoSto then internal_error "parsing don't allow this"; @@ -1823,8 +1829,9 @@ field_declaration: | spec_qualif_list TPtVirg { + let (attrs, ds) = $1 in (* gccext: allow empty elements if it is a structdef or enumdef *) - let (returnType,storage) = fixDeclSpecForDecl $1 in + let (returnType,storage) = fixDeclSpecForDecl ds in if fst (unwrap storage) <> NoSto then internal_error "parsing don't allow this"; -- 2.21.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees