From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 92FD03858418 for ; Mon, 7 Nov 2022 22:49:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92FD03858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2A7MLJH7005179 for ; Mon, 7 Nov 2022 22:49:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=2epleKc6uUNxAOtyxaoJ+luKF3QW5W+6HNdbc3+IuTI=; b=BmvOaMgPtrqBFssRnJNw99cNt1pR+WeuXS75DA4RCjxAAzqRhkFY0NASNQm0hdzw+5B+ wCYrNo1ZdJ5qQQSE4Eb2HVPS7c+64GgfB3dXhQQMlwcjzORLZ+LPHGxCmx61a/BTihjp /YE5vwF2Cv4cz/PRGEi6dAqJEEB/ztl56WOJovaXCZ7wgeOARBYwEKoMzDU0YfOklrxS eg1W1j7/9cWL57W8as9qVYM5jp5doc+QmprClg7d2kGASbI/zRO615P7aMYq3DYIjI9K DQliXKnP65JZsLaI9CvoG1kPQFt/sk+/jE8kcDIDqJl4Mhy+7L60tptobtYwfGVb6g5w Iw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kngrenf14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Nov 2022 22:49:53 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2A7Kuw4r003328 for ; Mon, 7 Nov 2022 22:49:52 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kpctbhbx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 07 Nov 2022 22:49:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BFJ6L8x5O/zuYAQR7FzbGL7PVFFXssoEoMDqDp1G8nhCXRGHE8OEVTGxdIUZmMUHRMwFsEjRPQbw5WTHQKksNX61BBjSkoFAaXW6bQvPeO2MNhqYCwY5CIav+9Creyq2XVq/J8In23bk/IYAVp4hnLEQD3PMSAjCpTo+9MzSb/pr32fjqw7HmEXQBTaLoKD82Cz/xg62ILj5iDmtOOlD37r/c2ljgPS2qrjizhHkbdLxOw4PQ9QFuVbbAtQZ8bE8bK2BVQkVg1eS50wEvkE8W5Y9LgwnOQuxa2Hpp3BBHyI2G243NLSSQ3mmpMry9CS40EBw0vAx/samIpUq5oIbNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2epleKc6uUNxAOtyxaoJ+luKF3QW5W+6HNdbc3+IuTI=; b=SOYp1PoaYAEX27uGjMbgNSAJb7iNjf0Kfr8RNmuqAaNcGYq1seKzKYhMOfdY30ji2VJfKmsBnp8dbvPMGHeQtzZnKCUglPfKdjqrKv/efbXmd0F1g7N1QO3Lle4+d/FFpQFCqNoDW6jdHWAR+3wEyPTKpyp5X4Ybe0TZFhnlaMHarTlu81OLcYiiYTPZr4T3FMbVcbqeTrngi4gI6vXm1wW9T0qaqa4q1wsj21XAd7QwzvgmF4d68tp8ycQQrUp/3iXH4OXvzboaDHRyHwZxLI78lWs7FvIzVRutIm70ra3qMqOK8bXES+wZhy5b1use/lklTIBcngaaGlhULx4iMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2epleKc6uUNxAOtyxaoJ+luKF3QW5W+6HNdbc3+IuTI=; b=gI6QrNQmvEVVQMBgoQZMzsirdquK+D9kLQB8V9DbeLTRKKBFjTtgtZFC9ckKRnL3ci90eXwivkzOV3+WfMFKbeN43b83QXnnFgdECgvfxG4d7vIFISR8ju3ek6GN+iT4Dv7UIYecWZsErm4MoLvDWGPIkYcGiBn9Dt9oVQih1Kk= Received: from MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by DM4PR10MB5992.namprd10.prod.outlook.com (2603:10b6:8:af::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25; Mon, 7 Nov 2022 22:49:50 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::dd41:a422:5763:8848]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::dd41:a422:5763:8848%7]) with mapi id 15.20.5791.026; Mon, 7 Nov 2022 22:49:50 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com Subject: [PATCH] bpf: Use enum for resolved overloaded builtins Date: Mon, 7 Nov 2022 14:48:29 -0800 Message-Id: <20221107224829.12440-1-david.faust@oracle.com> X-Mailer: git-send-email 2.38.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: DM6PR03CA0024.namprd03.prod.outlook.com (2603:10b6:5:40::37) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|DM4PR10MB5992:EE_ X-MS-Office365-Filtering-Correlation-Id: 237bbe85-0326-4d71-a27d-08dac11260f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yT4vNUc1mF6S0l/gPx4bptE/r5xbQkzA8kkAO4AaUCvZdzMNZXf4S9B6IETUYyvlyiZPmUfGWYPg++R/aWuX/y0X4m/qe+LHPditHV9qJTmFheLacE416mt9N1wta5NP2LEUTJe9DeaAfOEfK8/xJt/L/yoTBaTSeae1oWwTYaYpjNYnHCttmbGAtG3pdn9bdDdhTOXzxVmtFTIIlm+Ntey4jbfiArig6E9mMy3ZlAFZuM9w6IRBl4V8sjCESmibZHufI65TCYqntg/7Lx5RYaSUHspoRI8tBnJdStdgdZxeKdKRxnhBZiAiriV38ZnL8mEcKHFcmZ3qVglGNWd8eLqeLP9LV/OjHjUIoDlOdllIwF4FkLWkzkhFnffjZSAbb9KFGWl2kBfdPaXtEvye7NAe+AFRf6Uj39ZwzET0rTPOXUHNM3Dhp3bsQw9kyalGcpYRqPHKM1ZIVwzFiamO1V1L6jSh3QaEFEdOuV1kYO6CWUdKK7LWinKl9l7rJBCKQZqtyfOgdSsKKWZkXvNvqISQCiX2R+lCPns2MPuTazd/FaUP5wbeS34/K7xvRxA/qPb+CtUm7QLf/XDJPCjzQIp81MbA1//SsT3yGZr8Rq88SmdQCwpiLEWVdjJIPAUi+RiMHfhV0tySjtWmMFjqADHHbeYm0V8RuppHoUnSJw19ZH38mMKVTdiNzY5icks8+TicWeJfzuqg1+gQBLhaXA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3213.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(39860400002)(346002)(376002)(136003)(366004)(451199015)(6486002)(8676002)(66476007)(6916009)(66946007)(4326008)(316002)(66556008)(44832011)(2906002)(5660300002)(38100700002)(8936002)(6506007)(6666004)(107886003)(41300700001)(1076003)(186003)(83380400001)(2616005)(26005)(6512007)(478600001)(86362001)(66899015)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?w9lADXkVSuMf289+v2z1/umGnCgjWthbuSVnFUdBAZQXUUeDe+bPR/z1B3uP?= =?us-ascii?Q?1gvuMTOk26xaMEVUV9WnY8LwIiicnOm+0mO13E/6RQv5I5ih2AbouQkoBoju?= =?us-ascii?Q?rUcS3g/cNsuyPI8i89liiuu3zhAvqE71VIafz9o3azV82SDRHeu+wwzwhBEx?= =?us-ascii?Q?r6YeW3VgjeO+5Pmv9CGT5/v3yKpxcbgw5TR/NjxB/+DhowiftqVSqu/wX7IX?= =?us-ascii?Q?AUynA7oOvJeEwkq4pDPqyoasheb3NaSFfuUY3bbwOwob2fxH8daNm0FonVVW?= =?us-ascii?Q?IrleVfKj+cL5LdzffKFS4jzrBLjnS+J//IyYBE/2c2MiYRqa2yGR2yv8Erez?= =?us-ascii?Q?HjmjgC3LTrtEFKl5nbc03GMkslNvUgsuYgZ8rwSaO0n4bZIheb9VRasd6xby?= =?us-ascii?Q?1pbB0SsMetfxV21YBO4K7qCiSAhfeRVTND8Rr8J7P7CAyqm4iu2dI0EKuXaQ?= =?us-ascii?Q?f9mXb5UD/zUSwGPpmDLxfwDYflO2zTKcZDydVjsynIiFBhzMglvJW70kciRU?= =?us-ascii?Q?MNhesIzkq+y3iRBkyjavRqwMzj/GY1pN0G0+DPvnh5/3dCH9o8K+BlV/PgrO?= =?us-ascii?Q?0G01ZbOIffoYIEiLwA6TkSrassOMn4nwdH2EthfbCRZxYT1mJcv0lWPYJ7mG?= =?us-ascii?Q?Cw4mkiY6fRGild3hGmB81J6B597O6h3CA7ww2QZ6me7V9wlmYCXMkdz8s8K8?= =?us-ascii?Q?LZMKHNQ+CLJbSxaCxEP7VXeo9jLf92UrYixG5PJNInEtgud/qQuty1Y5VXcp?= =?us-ascii?Q?k/5p6w1+ZbbVb/SD1AkSxfMx6h07aNN7q1I9hHdnpNOR5F/5jtZLR/oQkVdJ?= =?us-ascii?Q?GrWDrEe8zgI9C5/jOOjS5CKW6mFbNvlSuA2rXuK1dfuhueXeKze/+iIYDrz3?= =?us-ascii?Q?TcD/rAHSyCyE4M/1e5I71MDwrdshUU8vaozj7prbeA0Wg+9LzMGFuEDVK+un?= =?us-ascii?Q?SX3tFMEe7AD9Qa4TZpWr7Cytr13/Wa3bI+5lx1KoERa1rUQsqU+cTy3N2ooD?= =?us-ascii?Q?BuM93UTselrVrysZf6AqeD9dHLUBOOIpIpMP1I3kmymj+G3HE8GjrAqGGb01?= =?us-ascii?Q?w6MqeDcqXyUgbz2Q9kyXmrFlwA//iiANa/nLu9w7/+iqzenpyWXEcLEoNRIY?= =?us-ascii?Q?qMAWyyYbQbZSD2ZUqSCTvGwuCiRfX19F1XJUW3w1E0pY/z0OUAYU76BsPMq+?= =?us-ascii?Q?vqzs1yWzvbigTfdIZ3IFbM6lffPt18/JTprdvzPYO3d6rA7KT4ksOlN/kREH?= =?us-ascii?Q?HQlb4/I5B+nZBOfdc3DNEU47tbdg4PUzLolrCXgOmyKJ2IxZFOplFzpa5+iT?= =?us-ascii?Q?4PaR2jmpk/cLNde8Xd7G+zlmDe1CMgQssE9HoDD3CI2OKsPk7uV5EGhc0uIv?= =?us-ascii?Q?/wHJerIfIuVrMyxbKCSifnKLaqHose7fqk5mS0ox/dn+ngeoOpsLHervz6Ok?= =?us-ascii?Q?2hhgfUhSJ2UTLRKwHbG0cuJGIrwaC96GsI5NOCyUig93jb3tgCu8n4uTukWr?= =?us-ascii?Q?1WbNVf1rgJfc7dfsbJTmhnoYcqV0xRzq7LIJsxWd5G+IipvxJ+snrQOMjClG?= =?us-ascii?Q?lZXnm/KfRpBtG0hBfS/Uw4p+F5cYsdEHHRjBeNto?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 237bbe85-0326-4d71-a27d-08dac11260f3 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2022 22:49:50.7435 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IO4uVtbYNQWpapS4uRcWwt/libnD6dcRKuqmkTc1Ci3pediekyVw3dVkP5xyftkPTaPme+zPXTT8//BIroWsWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB5992 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_11,2022-11-07_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211070172 X-Proofpoint-ORIG-GUID: T5hVDonz-Ae4v3SuzaOGDxs6u8kJhZQ5 X-Proofpoint-GUID: T5hVDonz-Ae4v3SuzaOGDxs6u8kJhZQ5 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: Change several places in the eBPF backend dealing with overloaded built-in functions to consistently use the enum bpf_builtins type, rather than variously using integer constants or booleans. The result is eaiser to read and extend. Tested on bpf-unknown-none, no known regressions. OK to push? Thanks. gcc/ * config/bpf/bpf.cc (struct core_walk_data): Add field `which'... (bpf_resolve_overloaded_builtin): ... set it here. Use values of enum bpf_builtins for error checks. (bpf_core_walk): Use values of enum bpf_builtins. (bpf_core_newdecl): Likewise. (bpf_expand_builtin): Likewise. --- gcc/config/bpf/bpf.cc | 106 +++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index fd4003c2bfc..16af2412bf6 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -1222,7 +1222,7 @@ bpf_expand_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, return gen_rtx_REG (ops[0].mode, BPF_R0); } - else if (code == -1) + else if (code == -BPF_BUILTIN_PRESERVE_ACCESS_INDEX) { /* A resolved overloaded __builtin_preserve_access_index. */ tree arg = CALL_EXPR_ARG (exp, 0); @@ -1249,7 +1249,7 @@ bpf_expand_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, return expand_normal (arg); } - else if (code == -2) + else if (code == -BPF_BUILTIN_PRESERVE_FIELD_INFO) { /* A resolved overloaded __builtin_preserve_field_info. */ tree src = CALL_EXPR_ARG (exp, 0); @@ -1444,28 +1444,37 @@ bpf_core_get_index (const tree node) __builtin_preserve_access_index. */ static tree -bpf_core_newdecl (tree type, bool is_pai) +bpf_core_newdecl (tree type, enum bpf_builtins which) { tree rettype; char name[80]; static unsigned long pai_count = 0; static unsigned long pfi_count = 0; - if (is_pai) + switch (which) { - rettype = build_function_type_list (type, type, NULL); - int len = snprintf (name, sizeof (name), "%s", "__builtin_pai_"); - len = snprintf (name + len, sizeof (name) - len, "%lu", pai_count++); - } - else - { - rettype = build_function_type_list (unsigned_type_node, type, - unsigned_type_node, NULL); - int len = snprintf (name, sizeof (name), "%s", "__builtin_pfi_"); - len = snprintf (name + len, sizeof (name) - len, "%lu", pfi_count++); + case BPF_BUILTIN_PRESERVE_ACCESS_INDEX: + { + rettype = build_function_type_list (type, type, NULL); + int len = snprintf (name, sizeof (name), "%s", "__builtin_pai_"); + len = snprintf (name + len, sizeof (name) - len, "%lu", pai_count++); + } + break; + + case BPF_BUILTIN_PRESERVE_FIELD_INFO: + { + rettype = build_function_type_list (unsigned_type_node, type, + unsigned_type_node, NULL); + int len = snprintf (name, sizeof (name), "%s", "__builtin_pfi_"); + len = snprintf (name + len, sizeof (name) - len, "%lu", pfi_count++); + } + break; + + default: + gcc_unreachable (); } - return add_builtin_function_ext_scope (name, rettype, is_pai ? -1 : -2, + return add_builtin_function_ext_scope (name, rettype, -which, BUILT_IN_MD, NULL, NULL_TREE); } @@ -1492,6 +1501,7 @@ bpf_core_is_maybe_aggregate_access (tree expr) struct core_walk_data { location_t loc; + enum bpf_builtins which; tree arg; }; @@ -1501,7 +1511,6 @@ static tree bpf_core_walk (tree *tp, int *walk_subtrees, void *data) { struct core_walk_data *dat = (struct core_walk_data *) data; - bool is_pai = dat->arg == NULL_TREE; /* If this is a type, don't do anything. */ if (TYPE_P (*tp)) @@ -1510,19 +1519,21 @@ bpf_core_walk (tree *tp, int *walk_subtrees, void *data) return NULL_TREE; } - /* Build a new function call to a resolved builtin for the desired operation. - If this is a preserve_field_info call, pass along the argument to the - resolved builtin call. */ - if (bpf_core_is_maybe_aggregate_access (*tp)) - { - tree newdecl = bpf_core_newdecl (TREE_TYPE (*tp), is_pai); - tree newcall; - if (is_pai) - newcall = build_call_expr_loc (dat->loc, newdecl, 1, *tp); - else - newcall = build_call_expr_loc (dat->loc, newdecl, 2, *tp, dat->arg); + /* Build a new function call to a type-resolved temporary builtin for the + desired operation, and pass along args as necessary. */ + tree newdecl = bpf_core_newdecl (TREE_TYPE (*tp), dat->which); - *tp = newcall; + if (dat->which == BPF_BUILTIN_PRESERVE_ACCESS_INDEX) + { + if (bpf_core_is_maybe_aggregate_access (*tp)) + { + *tp = build_call_expr_loc (dat->loc, newdecl, 1, *tp); + *walk_subtrees = 0; + } + } + else + { + *tp = build_call_expr_loc (dat->loc, newdecl, 2, *tp, dat->arg); *walk_subtrees = 0; } @@ -1572,32 +1583,26 @@ bpf_is_valid_preserve_field_info_arg (tree expr) /* Implement TARGET_RESOLVE_OVERLOADED_BUILTIN (see gccint manual section Target Macros::Misc.). - We use this for the __builtin_preserve_access_index builtin for CO-RE - support. + Used for CO-RE support builtins such as __builtin_preserve_access_index + and __builtin_preserve_field_info. FNDECL is the declaration of the builtin, and ARGLIST is the list of - arguments passed to it, and is really a vec *. - - In this case, the 'operation' implemented by the builtin is a no-op; - the builtin is just a marker. So, the result is simply the argument. */ + arguments passed to it, and is really a vec *. */ static tree bpf_resolve_overloaded_builtin (location_t loc, tree fndecl, void *arglist) { - bool is_pai = DECL_MD_FUNCTION_CODE (fndecl) - == BPF_BUILTIN_PRESERVE_ACCESS_INDEX; - bool is_pfi = DECL_MD_FUNCTION_CODE (fndecl) - == BPF_BUILTIN_PRESERVE_FIELD_INFO; + enum bpf_builtins which = (enum bpf_builtins) DECL_MD_FUNCTION_CODE (fndecl); - if (!is_pai && !is_pfi) + if (which < BPF_BUILTIN_PRESERVE_ACCESS_INDEX + || which >= BPF_BUILTIN_MAX) return NULL_TREE; - /* We only expect one argument, but it may be an arbitrarily-complicated - statement-expression. */ vec *params = static_cast *> (arglist); unsigned n_params = params ? params->length() : 0; - if ((is_pai && n_params != 1) || (is_pfi && n_params != 2)) + if (!(which == BPF_BUILTIN_PRESERVE_ACCESS_INDEX && n_params == 1) + && n_params != 2) { error_at (loc, "wrong number of arguments"); return error_mark_node; @@ -1605,12 +1610,15 @@ bpf_resolve_overloaded_builtin (location_t loc, tree fndecl, void *arglist) tree param = (*params)[0]; - /* If not generating BPF_CORE information, preserve_access_index does nothing, - and simply "resolves to" the argument. */ - if (!TARGET_BPF_CORE && is_pai) + /* If not generating BPF_CORE information, preserve_access_index does + nothing, and simply "resolves to" the argument. */ + if (which == BPF_BUILTIN_PRESERVE_ACCESS_INDEX && !TARGET_BPF_CORE) return param; - if (is_pfi && !bpf_is_valid_preserve_field_info_arg (param)) + /* For __builtin_preserve_field_info, enforce that the parameter is exactly a + field access and not a more complex expression. */ + else if (which == BPF_BUILTIN_PRESERVE_FIELD_INFO + && !bpf_is_valid_preserve_field_info_arg (param)) { error_at (EXPR_LOC_OR_LOC (param, loc), "argument is not a field access"); @@ -1642,7 +1650,11 @@ bpf_resolve_overloaded_builtin (location_t loc, tree fndecl, void *arglist) struct core_walk_data data; data.loc = loc; - data.arg = is_pai ? NULL_TREE : (*params)[1]; + data.which = which; + if (which == BPF_BUILTIN_PRESERVE_ACCESS_INDEX) + data.arg = NULL_TREE; + else + data.arg = (*params)[1]; walk_tree (¶m, bpf_core_walk, (void *) &data, NULL); -- 2.37.2