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 512A43857B8B for ; Fri, 16 Feb 2024 19:47:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 512A43857B8B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 512A43857B8B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708112858; cv=pass; b=YUoIJOXtQeaJMzXp8HODoFL8/c+NAo5VvjrPJdSXo9oPovqd2ntAfZcGVeZQF2qmtcAlRUvlLa1eguqJ19YFeprGl+QzC/LrxWrv6NTSIt0UMDatqxvcksO3HbHPPTBtprQc7NXrRQN5+mKTwonNmtWTTBI63c/1pUZin34sr8U= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708112858; c=relaxed/simple; bh=MwnQg36R22/s9Zm/DUh1CritOlF8Z+AbIuhg7Y3nhbM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=pSjSIgCDhwXD0JhaHCdUTNZjfdI50Sc+eZcMlNWfyf8ewybyiaR2TVeTbqqqNx+HYora4dMhkfFAqqy0anxIQPfqsL7BJPuheT86tADVouM8H9wALpbLw30WX0wgxM5IjhsLaLis5+agA5VptjHAdN+PhH6UXnvKA78q0iafHog= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41GCtpP4016660; Fri, 16 Feb 2024 19:47:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2023-11-20; bh=E85QTunRzqGMer3O1W2K2XbtxM6BZiINhdN+hh5NgVU=; b=PxlbeKpgDGIV0d/nwsLId9Y8tceN0gAdK731Auf1xLPa4ugQPBh7dps1SHXN/G0R1uqR duZdTGYvlUkR8M9lniNtTyHF5CyrnqrzDtwSuZcRM7L6HlNFQe/RSum+FhAVx0LQhBjR miW339E27BxIk3J83ytSepbWhiZBPCwproBfsWixfhiqgvSImsJebW3FfEWJbup+wxlU Tg/alcaWbS2dbNJp2Lcc8a8XMc3MtbKb0JmkpxN1saKXvgzFB+3Huz6nme+fhqAVrk1v DPoDWNMMfnsKfyfRNvDeZQ63N9ENECNiePccxx+SwDrMXWJvLMm8E1lakkpFYOVr+AEa vQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3w92ppnyg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 19:47:34 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41GIbtqu024614; Fri, 16 Feb 2024 19:47:32 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3w5ykjwqcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 19:47:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fS7vgyt9M8m15BaWaPSIIFkqwciH0T36+6WjSs0YZJajPtIJY1H+nf41oi03FkznDItsMpxgFSc2loXKI7EdGuhAUUIoTYIn6TisD8pUAf6x++OZgZqaqbztP/a2y0SG+0vxbmbF/RCH73gY/qG5dzAWJHHtMQxCx6Bnm4B2mYasZZ1wppA81hv/Hg37GYYWlQ1RnPnTXUIFz6QKFDC/0Dh7t+05oPLmIkz+SX2lX7U07IZ5HvRkHvPyEpzRHI5PsHsVVT/1jDxWuexBV+D72dy/Leg7Kne02S2G1KnApfzC8OsouOffdQvYoo0YNNWlmh4k8fRlzKnr7VC56YXE3w== 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=E85QTunRzqGMer3O1W2K2XbtxM6BZiINhdN+hh5NgVU=; b=FxuEh2VcvnSAah6tsIfB+Rz+7htnjsgjR6BmJMrj5Z8NPBm0/bS7QaaYeebW+5/rncPWGabNnOEYL20MelAy4JUI/RnikggUkHDBJ47V1cOi5ly8TxG3URebC8+Vz4tR9M7Zkb4og5W+EIhm1yk1QoqEunEod59nRDeeJVRg7sHMMSnUc/Wnhfd+5OpttcRmC3Q7azx+6hcc5GE+Wpj0SMtDkFccPwdH886LfQNos1cpmcpjqE2rKoXnnpn0qUBzOcaig4aHDCnkKeUAlq/NsbXeSaeTIvjLvNwWdC+GjU6SBEhPcVd/8UwjPRYqDx60VtH/dOQQ9OO868S91Q/4sA== 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=E85QTunRzqGMer3O1W2K2XbtxM6BZiINhdN+hh5NgVU=; b=EK/42GeWyM1uEVdcwjqboEQ9bXRIsmkCAGrkOG0GlTn6BrIq5Gl5CwhzGEnLxYCntPb4W3xy0BlsfU+/WBt5kN73WtfcUnKybDRobwXC471eU4Yhs5eW0hzFJMbnVYg6DHfzpDs2hKIeGVn6Pk7K4yrRYL7/CwiIhEhJhnqMoXk= Received: from CH3PR10MB7957.namprd10.prod.outlook.com (2603:10b6:610:1bf::19) by IA1PR10MB7238.namprd10.prod.outlook.com (2603:10b6:208:3f6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.28; Fri, 16 Feb 2024 19:47:29 +0000 Received: from CH3PR10MB7957.namprd10.prod.outlook.com ([fe80::1e58:cfe8:d9f5:6363]) by CH3PR10MB7957.namprd10.prod.outlook.com ([fe80::1e58:cfe8:d9f5:6363%6]) with mapi id 15.20.7292.029; Fri, 16 Feb 2024 19:47:29 +0000 From: Qing Zhao To: josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org, uecker@tugraz.at Cc: keescook@chromium.org, isanbard@gmail.com, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v6 0/5]New attribute "counted_by" to annotate bounds for C99 FAM(PR108896) Date: Fri, 16 Feb 2024 19:47:18 +0000 Message-Id: <20240216194723.391359-1-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 Content-Type: text/plain; charset=y Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR03CA0097.namprd03.prod.outlook.com (2603:10b6:a03:333::12) To CH3PR10MB7957.namprd10.prod.outlook.com (2603:10b6:610:1bf::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7957:EE_|IA1PR10MB7238:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f4370e6-1ed2-4666-8515-08dc2f281bf0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QoHUQ65NAXb/E+c3Vw3wNM3gmASQADEB3DFHDZaReFG3CX7rqwT84JpC7DKU1YyCh+6rfnGaw0NcPkOKQnGkMJPnmUtyFrmIHoUo01QzxgNeby+y50xD6szCrs8WRUpML1BzZbDVML9pb3nBTD80KRXzBX+bMjfKxbq+nDnH719gyqYrsXShFxbcIRLwqa0AY7cvp6Co6L3WbgTzrRSX1URTu+n//HtEVB1TZrBjPGZTdOlu8fvj/ce0UBqjVDeBGuv4+THwoLimqwuPqJWlO/IYg275Yrw9PBCjnmV7FOCBJwwsiO3PJTbNypB+gufx2CHGD/pNTWzmM3FrLSkw5TTiUzA+UQqFxs9CEyMpv9S2GLCJ7BgH4gseKdxEw0MSK2yriAocIFaUHPIEdgVs4ktfjg6j3r1UcWVRBgCDA59VEnteJxrqdSFVGxjoKvQVlYp+NQU2TcqBpQShtf32VS1KSfLiUqMwqz/AT1SNBBgPv7rYwk+gHss59VjkVlq7c+Cpm8es5dH/NF8UzeYcDWdWBiV/gxAJkLTF/A6T+vKC1sL5/K/61b2oTKMlLEU0 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB7957.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(376002)(39860400002)(346002)(396003)(366004)(230273577357003)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(4326008)(8936002)(8676002)(5660300002)(6666004)(2906002)(83380400001)(4743002)(86362001)(107886003)(1076003)(36756003)(38100700002)(26005)(66556008)(2616005)(66946007)(316002)(66476007)(6506007)(44832011)(478600001)(966005)(6512007)(6486002)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CWVd+HIby0gDh/bgdU7iCQxRI0S2yInD0x9aqIl2TQf8YQn4PgL5WOEp3Rsu?= =?us-ascii?Q?f0Rqq7rGQvL2ULnXXzYMNAwMO6I0kjTVLIhdsCc0ejX5VSH/RJ9275K+DlUb?= =?us-ascii?Q?PNB4Yl0frn+SlWwVP/ZEvdaMLx59xX9N4tRwLSXbH8ZjAe8AmIU3i1T6B+r7?= =?us-ascii?Q?LDOunWL0jU+WnSwbnpdKrMmWuDTpw/tg7m0yt8aLOcBFgGjbjVJvuTeFMW7u?= =?us-ascii?Q?pnWJWTDLqymqwgtdmufekFsBSqtS5G3DBfzgu/W56Zu5Dn/ciGEPI5xImSZz?= =?us-ascii?Q?uxeYmQmQsQuiqFlxnVDrdUsoebQcEIRz05nQickJAUF7tOmtGnIGsd7TnMA2?= =?us-ascii?Q?inC8wrKDb10jXULc9dAcCEJIGtIOrCS92Xgh6R2BNK1VknpNKE4Ofv5tuSBQ?= =?us-ascii?Q?qTA4GzJxswlQwxoMQ2EyA8ZWVdvg5DbnvPW9Bc0N4YHU3azpTxEAOOGZfg24?= =?us-ascii?Q?hhQCMTboylRA+SeVHpQOzhoUBPcylhXfxlpjraOPk3UgJ+TS128y5qqs3YQ9?= =?us-ascii?Q?7BSzqIaVSp9kAxXJN0/I2f57ltrGFbLRC5IfiimntpxDCkM77csfolWzOQnC?= =?us-ascii?Q?xxK7g7Rcxd0ZAQ3ml/6SIp+0EeEZtKvEAi/WFu8TQbzBHP16ch3RKg5afL7F?= =?us-ascii?Q?tUdDW+Ob0ZUZkMD+qPK0XXJrrYf0MeJW5TOE5L43r85XpnxaO3pBlsN0rPLP?= =?us-ascii?Q?xO0NdqlpXKtNRm0RvmK/EGLlQvwBu1f/yCe2njGsR/c6iXDN/6y65g41OLKW?= =?us-ascii?Q?D8mFpDNdz3NU7QAuHoJZNC/HizP6czAx68uaRyb33Nk/KR0l5BjxrHjOxvCl?= =?us-ascii?Q?k9NVlY/K3RhOUus/6rKbYGMMSr1icUERERB2Kymo+F+2LynJLRqnlPv+Qnib?= =?us-ascii?Q?ic+2eBnRKnm/p740rWnPAVTB9/KgFUwV86CEtwackU2HRd+TAWPx+ZQBq7We?= =?us-ascii?Q?T+jyN7yPNU3TuqR+nn6dGhCEtAP+oSpeVe5gk8UylH9UVVPFtBG4FjmNxDiJ?= =?us-ascii?Q?fZnTS81ZnIbVw6B97mjYjBksXmC0jUFi3Cq9y4xsISvRBZRwEVHmi/Iuhgp/?= =?us-ascii?Q?nEGAsisSN4mmIFuYY8ry882f8ZuiRmxtIC4lM4ap3FQ61iXpAHzUjU/plP6z?= =?us-ascii?Q?hXtiLNiuNCQ0xjmGb0NpfvW6nSsHf9pXUuMv8Tx5Wolk7wMMkhfvLOAUmTwU?= =?us-ascii?Q?qJNMnRrdvnRl/8yEnCy3mIQsuu/6yOvHxNP7CWt3ICFL5Bd6ATMvEbH2G6mH?= =?us-ascii?Q?AUgajvnnMIDROdlCS7+DxmpIV0LQkgSXOt07E5zjBkm1TvvM6UEDvky2mAJs?= =?us-ascii?Q?va8O4r0/bVBV87tJtDDmKkcM7+KX72Z1cIs4B9q4lBMw/C18pXTl176tAgnQ?= =?us-ascii?Q?yNfjyKwxcOTwkGPQ592mMHwEYND0e5l7/7CqP45YvUjVbKYVGfbYmNgR4f0Y?= =?us-ascii?Q?++4zP4oy4V1w0xbPO2bHITT0yKMsLtCG8ma5ileINRwF4Yg/Hu2UA7IEr3om?= =?us-ascii?Q?y8PLMB7P9vzwofDoSVgRX+cqzk5x7elWSggB45xrKmMkPmLsR8wr0BDODFIy?= =?us-ascii?Q?U+P9FgN3H0VVe6ED56tQffHisX5eE5YDLB0NrkZD?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: TKqbzBj6uqsYg8y2+Yjn1MbeXcIoLsGQqAsf+TI5TGWmTn1XXn0spUA9w6+tlLcjGQ28U4Pu52GQfFuAiZgki24WBLoc53bc93nay1d0AzC/g5N9XdsQxjrGC0NAJUsMsPamFtcRU4HVLf8bnLB52CLnVFafp0GmIA6nPhuj9bY6P5utbUv6VtHJjo2LEgelbAaSSw0P+6tNO33/ecNHK1ngOhjMJ5lGR/vH7QkyJsz2IWM3PBLa+rDrGdvH+U+R3/K5iofLV5SGWwbwBnfuVyf37D93zVRY5a2RDFPUXE9WlTP+q0UaGfGi2OyQ4RhYUyF9SLMCzLd/KMz9Xgt6d8Oqu//njdUBZWHF2eYOsB6O6y0Mm+SIZlXQ7gPXSCzqGXTBtTnWOAaWxMsdasT4DZ4pA9+uyvd83f68akzMbWMi6mu+ujo31Z51+xNvt/JtlaMh5e/NrhCaQYwdb9LuX6B0QiFGmVq4GF4XkWmHPqHQcjYgOt2NNUDFQs616XqVInboeo64w3Vj8rA0R+Pf6OFRS1gsKWqpsN3YClKI4giDfx+hgBTgycwYYeFw/XwD6Y40B/fbO7nbynn6uNdDp5uZ+imi0laOoktO/cCwZ3Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f4370e6-1ed2-4666-8515-08dc2f281bf0 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7957.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2024 19:47:29.5378 (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: nU0x/701RBlN7gzcCQPwxHj8A2hgOV6/uMpcllXIQwnFeZo9Z5gIJVV/rqY8TsbRDNRyO0k5UZmqs50MJMLFXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB7238 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-16_19,2024-02-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160154 X-Proofpoint-ORIG-GUID: ziHe8J87_olqBGEQxlYkVAAJlvJRgULm X-Proofpoint-GUID: ziHe8J87_olqBGEQxlYkVAAJlvJRgULm X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,MIME_CHARSET_FARAWAY,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: Hi, This is the 6th version of the patch. compare with the 5th version, the only difference is: 1. Add the 6th argument to .ACCESS_WITH_SIZE to carry the TYPE of the flexible array. Such information is needed during tree-object-size.cc. previously, we use the result type of the routine .ACCESS_WITH_SIZE to decide the element type of the original array, however, the result type of the routine might be changed during tree optimizations due to possible type casting in the source code. compare with the 4th version, the major difference are: 1. Change the return type of the routine .ACCESS_WITH_SIZE FROM: Pointer to the type of the element of the flexible array; TO: Pointer to the type of the flexible array; And then wrap the call with an indirection reference. 2. Adjust all other parts with this change, (this will simplify the bound sanitizer instrument); 3. Add the fixes to the kernel building failures, which include: A. The operator “typeof” cannot return correct type for a->array; B. The operator “&” cannot return correct address for a->array; 4. Correctly handle the case when the value of “counted-by” is zero or negative as following 4.1. Update the counted-by doc with the following: When the counted-by field is assigned a negative integer value, the compiler will treat the value as zero. 4.2. Adjust __bdos and array bound sanitizer to handle correctly when “counted-by” is zero. It based on the following proposal: https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635884.html Represent the missing dependence for the "counted_by" attribute and its consumers ******The summary of the proposal is: * Add a new internal function ".ACCESS_WITH_SIZE" to carry the size information for every reference to a FAM field; * In C FE, Replace every reference to a FAM field whose TYPE has the "counted_by" attribute with the new internal function ".ACCESS_WITH_SIZE"; * In every consumer of the size information, for example, BDOS or array bound sanitizer, query the size information or ACCESS_MODE information from the new internal function; * When expansing to RTL, replace the internal function with the actual reference to the FAM field; * Some adjustment to ipa alias analysis, and other SSA passes to mitigate the impact to the optimizer and code generation. ******The new internal function .ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, CLASS_OF_SIZE, TYPE_OF_SIZE, ACCESS_MODE, TYPE_OF_REF) INTERNAL_FN (ACCESS_WITH_SIZE, ECF_LEAF | ECF_NOTHROW, NULL) which returns the "REF_TO_OBJ" same as the 1st argument; Both the return type and the type of the first argument of this function have been converted from the incomplete array type to the corresponding pointer type. The call to .ACCESS_WITH_SIZE is wrapped with an INDIRECT_REF, whose type is the original imcomplete array type. Please see the following link for why: https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638793.html https://gcc.gnu.org/pipermail/gcc-patches/2023-December/639605.html 1st argument "REF_TO_OBJ": The reference to the object; 2nd argument "REF_TO_SIZE": The reference to the size of the object, 3rd argument "CLASS_OF_SIZE": The size referenced by the REF_TO_SIZE represents 0: unknown; 1: the number of the elements of the object type; 2: the number of bytes; 4th argument "TYPE_OF_SIZE": A constant 0 with the TYPE of the object refed by REF_TO_SIZE 5th argument "ACCESS_MODE": -1: Unknown access semantics 0: none 1: read_only 2: write_only 3: read_write 6th argument "TYPE_OF_REF": A constant 0 with the pointer TYPE to the original flexible array type. ****** The Patch sets included: 1. Provide counted_by attribute to flexible array member field; which includes: * "counted_by" attribute documentation; * C FE handling of the new attribute; syntax checking, error reporting; * testing cases; 2. Convert "counted_by" attribute to/from .ACCESS_WITH_SIZE. which includes: * The definition of the new internal function .ACCESS_WITH_SIZE in internal-fn.def. * C FE converts every reference to a FAM with "counted_by" attribute to a call to the internal function .ACCESS_WITH_SIZE. (build_component_ref in c_typeck.cc) This includes the case when the object is statically allocated and initialized. In order to make this working, we should update initializer_constant_valid_p_1 and output_constant in varasm.cc to include calls to .ACCESS_WITH_SIZE. However, for the reference inside "offsetof", ignore the "counted_by" attribute since it's not useful at all. (c_parser_postfix_expression in c/c-parser.cc) In addtion to "offsetof", for the reference inside operator "typeof" and "alignof", we ignore counted_by attribute too. When building ADDR_EXPR for the .ACCESS_WITH_SIZE in C FE, replace the call with its first argument. * Convert every call to .ACCESS_WITH_SIZE to its first argument. (expand_ACCESS_WITH_SIZE in internal-fn.cc) * adjust alias analysis to exclude the new internal from clobbering anything. (ref_maybe_used_by_call_p_1 and call_may_clobber_ref_p_1 in tree-ssa-alias.cc) * adjust dead code elimination to eliminate the call to .ACCESS_WITH_SIZE when it's LHS is eliminated as dead code. (eliminate_unnecessary_stmts in tree-ssa-dce.cc) * Provide the utility routines to check the call is .ACCESS_WITH_SIZE and get the reference from the call to .ACCESS_WITH_SIZE. (is_access_with_size_p and get_ref_from_access_with_size in tree.cc) * testing cases. (for offsetof, static initialization, generation of calls to .ACCESS_WITH_SIZE, code runs correctly after calls to .ACCESS_WITH_SIZE are converted back) 3. Use the .ACCESS_WITH_SIZE in builtin object size (sub-object only) which includes: * use the size info of the .ACCESS_WITH_SIZE for sub-object. * when the size is a negative integer, treat it as zero. * testing cases. 4 Use the .ACCESS_WITH_SIZE in bound sanitizer which includes: * Instrument array_ref with a call to .ACCESS_WITH_SIZE for bound sanitizer. * when the size is a negative integer, treat it as zero. * testing cases. 5. Add the 6th argument to .ACCESS_WITH_SIZE to carry the TYPE of the flexible array. which includes: * Add the 6th argument to .ACCESS_WITH_SIZE. * use the type of the 6th argument of the routine in tree-object-size.cc * testing case. ******Remaining works: 6 Improve __bdos to use the counted_by info in whole-object size for the structure with FAM. 7 Emit warnings when the user breaks the requirments for the new counted_by attribute compilation time: -Wcounted-by run time: -fsanitizer=counted-by * The initialization to the size field should be done before the first reference to the FAM field. * the array has at least # of elements specified by the size field all the time during the program. I have bootstrapped and regression tested on both x86 and aarch64, no issue. Linux kernel linux-6.8-rc4 has been built and exposed one bug with the new counted-by, fixed. Let me know your comments. thanks. Qing Qing Zhao (5): Provide counted_by attribute to flexible array member field (PR108896) Convert references with "counted_by" attributes to/from .ACCESS_WITH_SIZE. Use the .ACCESS_WITH_SIZE in builtin object size. Use the .ACCESS_WITH_SIZE in bound sanitizer. Add the 6th argument to .ACCESS_WITH_SIZE