From patchwork Fri Feb 16 19:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 85906 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 84BF23857722 for ; Fri, 16 Feb 2024 19:48:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 6C6B63857705 for ; Fri, 16 Feb 2024 19:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C6B63857705 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 6C6B63857705 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708112874; cv=pass; b=TYP4s5HrbfdjQXYXXEEX85oe6ENUjL4E3rqT2thGUCVrlVT3A4/38t57NWczIith4dDC3D1LR/AEFwMUOKmqLkT9my1gZgzKAqc6oAz2sKpKL3s1DMYwkq2yLDPA0VPUvzqiXtR2rfXG1FeJDOe036+J5i4R0BjU851+/GWRpvY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1708112874; c=relaxed/simple; bh=VSBb2xJ72uoKEOycV54e3OQhCgpje6Cin0GiRWPuOsM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=uUByYnW2BqHZY4+T+vTeibQ5ecpyvlB6tL1bQN6tnTppSyFAOsjLKi0ksYu4eyZGS7JgBb3Kn5g5EtfrqoEbuj0uYc9FRnxi3XyAo/kWBfFZs9EHr358lCGaUclht503bTO/klN5VQ1VMkhu7vONwSHNvsZHP9D43Bc9YgKHgZw= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41GJVgG1015639; Fri, 16 Feb 2024 19:47:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=bdUoxJy8S/jcGDM7ZZCyg7gimp/kv+oR3hrfmBNmtik=; b=eiVCCCGIAH7Ux4R/7Vib2LKuQzJtf/4c9QW8DtoHnNve3d+KgHRVP+3ZoMAj+SEEjwF2 2QCZIZ6+bi5iW9WGv59V4Bt13rSZCVYBjVkFKZNYVNCpfgSSW0Y0wTRbLw77vHmvj6+K AnY6sDGMizKAIhAzhdPytxS7Iqf0BKvY3lNtU2xi6P8SPrezANZ9locP8a7c3g3KEY+s aqwWCUwRE/pQ5XRMTqDIU+2M6bhWhysEFxFQk/Kz/51MleiF2XbOCtsy23YVizyhLxD7 I0KL7wyVgXQ0pzCdlnBfGraVzf3/d4XEe7sm3MxiZbXQvFJgnMZ6ObDn9lJVYTYv1ihg 1w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3w92db5y4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 19:47:51 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41GIw7nh031672; Fri, 16 Feb 2024 19:47:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3w5ykcky68-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2024 19:47:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4LOHgbFoOQ2NUcjMGXIguGm1x+5qNM8bEo0eZt3jVaYpc0BFmNNct5aHV55JTN9h4FDh6gtVdzSo/rXuiW6MYJ4GK3wMccgI/8Fp6zPoFspeKF+u2FuYZk3dqsUqPbPPf2/Q9+KOVWyvoBJXXr/dmcJw3DkEnerejGJS97cAUJPAn+LgLaT7uEIuMMbmQKJWlEsk1p22r7/mBUefz+7mFcaJm/9qPe9JZOgbWxnI6w1rYKDPHahDDx2U4598UO5lcU75YALXNAXLfYFTyi5qWUxfQDCRX4SS/cCn9CF7czVzGFhYBOanhg9uLkk9SVETDHfVBG7uKKBbaSVaaaD5w== 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=bdUoxJy8S/jcGDM7ZZCyg7gimp/kv+oR3hrfmBNmtik=; b=VCP503459qXrSIETaUuPCE2HKWYLc/7mp/r/ethrXa7AxUG5Rn3ncKb6MtdbTkdGiOlHlBHBv5diFnWLqZ+2jfoqO9y7yuRhURKL6Ef3VI10rEV5YIvP+QOQfKDJSfejZgLJ8FZmKiuQjPUn+QoJx0OM3GbC3Onj1DIhErHrs8S3Kh6HG3hBBRmZ3qwryw33uBzd9Aroa5KgwPXyaz14NdDr6VaohFwnfO730i1NL1AmKxmj0Ti2+DUQaNk0IZNSNbfQk5ng4t2D/tmSBrv7ZtXBFP7ovE0nZQ03Zofrv30la/DKcGTZRW+yaOy6hWBHDTErhLi0xArSgUOGwD7w5A== 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=bdUoxJy8S/jcGDM7ZZCyg7gimp/kv+oR3hrfmBNmtik=; b=WfjFJre+iA3MlSLGNKvwQzypQ8su1d7NRx/wJhSE2eaaZPO+M7v/OnnOLgPV5cSGndViFxHdj/kORCfgKtr4EVc1bNM0gAscDJMrHIL3aSNIR6OHe1XRzHIROP3sjEYf0IUeDBoBUPw6JlF7hjY1j4X+h2nfACvRcyTkhcBZtkE= 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:48 +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:48 +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 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Date: Fri, 16 Feb 2024 19:47:23 +0000 Message-Id: <20240216194723.391359-6-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240216194723.391359-1-qing.zhao@oracle.com> References: <20240216194723.391359-1-qing.zhao@oracle.com> X-ClientProxiedBy: SN7PR04CA0113.namprd04.prod.outlook.com (2603:10b6:806:122::28) 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: 7a0c5ec4-05c3-4461-68f4-08dc2f2826ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HfwMxUUky3rSsPHm9HFRqC3lDkw9APDwSMkgq70yzZXkclniuFRX4e78QdOtaceVT881o4Pqhk7Wca/6chp2TdYEoftljdJybZLhMYLg3rq55flAKkwsmNCvXg63D9N0T1+kpEQGWwIheICewEUu47VwQ8fcj9yzmEO/1NZG0ACw2zmzKyuHspURomdm6O1cWAnJyztaL61hGWBfg4bz9AmmTlWoMb2gXzN78xAVDLW6lp0eRFcvkRhR6ChXnSRY9Cg9WS8d2aKuK1CcJib1EUQGRlwhXso0R7xzUwYSdP5TA3TNm/smTRZTYe/0Z23mqCxG83qEq7n0pY9ueb1I+o/TVWKwRIJLzVn/czI551h2/D9tjYByqFoyW01izJUKvV8SW+XyHm/00YwxPmA2Ew4jlTQmV3abgnxgXxEX/xpt2iGM2BQ4w9ov5ZmkbBdFLw1d494DrbXJ0NeH8QgMmpPPniS2HbiausUsG+vAb8gvtcj/iJUnAJqGSk34JAaVKw2unIYLDQvKZUldxAxuPjPaRZzpfAGksNrSY+yFkJ4= 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)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(4326008)(8936002)(8676002)(5660300002)(6666004)(2906002)(83380400001)(86362001)(107886003)(1076003)(36756003)(38100700002)(26005)(66556008)(2616005)(66946007)(316002)(66476007)(6506007)(44832011)(478600001)(6512007)(6486002)(84970400001)(41300700001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oyH0JVA6qHSZBS7VWxubJHVMmzst1is6pqG2vu5GhzrC0ULsMaO5L4WVtb6FoUpH+6Wokq43ogrSCrEtOAvTGX27O/niQ3n9G8909KDCFAH/ZpulN3Xg+7UwjAdfzH+DzIQq9hNItLzHNGYNbHtEzM7bYveFpaIvucQ54oA9CP2QkDOc7QBHyZ2Iahf9GOUMir9dQpMh6VqgDlF3v119QMX5m5W1dCI15Nd8Mj2enKaMuX5YU8cXf1v0qnYDjdV1mTN9H8l6scSS5HBre5A7eYSM5YuU58Zx35D/icVXi1J5qfCEvwpTlREsNjs/CqgEGqzpDnjTABG50zSvEu7ZrGqcwz1y6FZOLL7slvW+OjqN7oOVmwstySNhTypPjaPsYUL8hqcdGKjDahR2IXqvPS7+0oTfOqqo+AgnH3Vd0BoeHe7HLoN6QFT1Ol1H9Zyn208OA1c4TU18rl4brr1ccoK/w1w9MLARmEMVDpNzVCjgg0/g31Dii8kISJ6RmPliIk+VOz2tpK3IuL4pP4xPqddl6UpOZGcfs6flip6z1NQAq0wWEZVmwqAKiNMm+MqR/nsXU+9h96h6Urfg2ScSNCWd/R9EwJE02/JRGCTQMfb46dNDZ4HDIjjGNSDMp9F3OYsrnCIxLevcLcm3fm3ClN1TMZXrfEDWKYv+tMakT/nh9d87mMsjfQAlKHD6G91acu0048aLPG3mLFDCmDkaP6TlNDCg2l5ILQFXx0haBGJ7E4l46wEHDHMd5+feetbkRUxfb4IsnyAhsWYZsp05copheKLPah2sMI0bwD3QLyJ6zzPhf2BLuCr0ufvDQ5VDYxV+l+dINEQ8OsDCW/eMoTs52utqamokGJAhVUEyEnCT3uO9ME6jU9c05P4uN/HX200jwfP9amDP753usbYwvGLzXJbPYu8BzJBXKtrU9rGBBLUmUxvoNi8ibJcLWCFt4iaIi9KKgWSwf7388I2GWK9VTo8eABJYKB6Z1nTTpwUgcHY3110fHzwrlO5hB+mIokSAVenfJwHr7OwiIKhRdW+iXwC1eAIB/t+SIqTWguBNF6s/qCfwcBHYFmPjrbwFsBjtbTM1ukBT7rudAg0i80M86+VpHG2VckWNodGvzlu6JODDOMSGGCTEjx2CmfZzl2G/eQM7BKoKt5rHudTf7qdGGtnR1V8U8o2M8i3aai01KPYbVjZ9wuQl9lUM23EzPWCt3lUl5WDFYVwS6LEYGnrury0tvFfXhUb2a9TtRUqhcp95WjyRKEjlu2eK8rfWZuf6e4JYgsC59gtgP5ZYWJHvupovkVU2j/rgtAZ8pEH5QwjqK2cYuFUoRn/Nlfx+C52W3+2pV2VLJzbBSpdsPAXrFUftHzJTE2UlFM6s/IOAEED5L6VUDe97hRxRpWpTPT7fKdK1UW7z7Xgnq1x2WaKx9AaFR8p+HAMCcUzk/fAa+ulRWHKwyDCwo2Zn9mpMFenqGzyi5hcj35RU7CKwZaOvbb04qvmKo6ql/Dyii2mb/LHuaqlEIkATNfjK8347YkCp7iUX98sjdbmSPOmYIaV0E4RsHEoJ/Zvjyyi6bkzDaoz7GVrFJ3IzxzS0SBUn X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 8nKSRnunB5jo+6s9AOmUB6r+QgWRVnXjbBnZFU7FoGXcWXqv1PNv156hjq9iGip2F6FQvXeGN1APJD+t+eZKOgalyPsxjCk5w5r0sKHTBl+TePWP6elO25ZM3EIjA/3yjjcQjf9FWgc+mnfth/6grX1+b69pAlkfO4sNdBovi7WKvTENWAikZi+LbgTlro/24m0TNtJxsKbEptcscaXtoRQToYCL+HUryTgc5ngR+RzzCOxOtaqPMoxrdInLn6A54Yt3MdKM1wu2vufzgPzl3PXUaRn4GvFGEe5iWi3Wqvbw22V89pbWhkgdMDQMfhkEju9iIWrU2MhaU6X9N1uKXXtgr1SwvKHQq9cATewd1oxctxBMLGMrsAXgMOeaCfPd8NqVSW0luoWngdSqExmOCjL5KKvKxnnz2qeb4wFZN9piEyMgmrJgi61/sSmjb/0vijKefeDUx5R6NIDccf2All86kQAPR4ft72u1X4mUbLr9eB7q9vkD4K8lUQtbSft+zynVDGUvXNWSLyrnljEGcNwtJfjUoUu8X75E2tCctDt5Lajtjb3xdFFedjzQVtwen8uhsn4wsN0xuEZ36LzopZRUJqmoqpirBQBxfMoR/uk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a0c5ec4-05c3-4461-68f4-08dc2f2826ee 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:47.9591 (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: j/M9qlqOtcTlozXChfojrRCt8bRKyBmUZ7GMG4HFbgTAs9OkVpquOdWmL/T2zb0raIdqdSvWhmFbTmY4EF/gQA== 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 malwarescore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402160154 X-Proofpoint-GUID: cWI9V_HdKtsvNT2ntohwON7e8vtRS_xG X-Proofpoint-ORIG-GUID: cWI9V_HdKtsvNT2ntohwON7e8vtRS_xG X-Spam-Status: No, score=-10.8 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_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 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 to carry the TYPE of the flexible array. Such information is needed during tree-object-size.cc. We cannot use the result type or the type of the 1st argument of the routine .ACCESS_WITH_SIZE to decide the element type of the original array due to possible type casting in the source code. gcc/c/ChangeLog: * c-typeck.cc (build_access_with_size_for_counted_by): Add the 6th argument to .ACCESS_WITH_SIZE. gcc/ChangeLog: * tree-object-size.cc (access_with_size_object_size): Use the type of the 6th argument for the type of the element. gcc/testsuite/ChangeLog: * gcc.dg/flex-array-counted-by-6.c: New test. --- gcc/c/c-typeck.cc | 11 +++-- .../gcc.dg/flex-array-counted-by-6.c | 46 +++++++++++++++++++ gcc/tree-object-size.cc | 16 ++++--- 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/flex-array-counted-by-6.c diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index a29a7d7ec029..c17ac6862546 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2608,7 +2608,8 @@ build_counted_by_ref (tree datum, tree subdatum, tree *counted_by_type) to: - (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1)) + (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1, + (TYPE_OF_ARRAY *)0)) NOTE: The return type of this function is the POINTER type pointing to the original flexible array type. @@ -2620,6 +2621,9 @@ build_counted_by_ref (tree datum, tree subdatum, tree *counted_by_type) The 4th argument of the call is a constant 0 with the TYPE of the object pointed by COUNTED_BY_REF. + The 6th argument of the call is a constant 0 with the pointer TYPE + to the original flexible array type. + */ static tree build_access_with_size_for_counted_by (location_t loc, tree ref, @@ -2632,12 +2636,13 @@ build_access_with_size_for_counted_by (location_t loc, tree ref, tree call = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE, - result_type, 5, + result_type, 6, array_to_pointer_conversion (loc, ref), counted_by_ref, build_int_cst (integer_type_node, 1), build_int_cst (counted_by_type, 0), - build_int_cst (integer_type_node, -1)); + build_int_cst (integer_type_node, -1), + build_int_cst (result_type, 0)); /* Wrap the call with an INDIRECT_REF with the flexible array type. */ call = build1 (INDIRECT_REF, TREE_TYPE (ref), call); SET_EXPR_LOCATION (call, loc); diff --git a/gcc/testsuite/gcc.dg/flex-array-counted-by-6.c b/gcc/testsuite/gcc.dg/flex-array-counted-by-6.c new file mode 100644 index 000000000000..65a401796479 --- /dev/null +++ b/gcc/testsuite/gcc.dg/flex-array-counted-by-6.c @@ -0,0 +1,46 @@ +/* test the attribute counted_by and its usage in + * __builtin_dynamic_object_size. when the type of the flexible array member + * is casting to another type. */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#include "builtin-object-size-common.h" + +typedef unsigned short u16; + +struct info { + u16 data_len; + char data[] __attribute__((counted_by(data_len))); +}; + +struct foo { + int a; + int b; +}; + +static __attribute__((__noinline__)) +struct info *setup () +{ + struct info *p; + size_t bytes = 3 * sizeof(struct foo); + + p = (struct info *)malloc (sizeof (struct info) + bytes); + p->data_len = bytes; + + return p; +} + +static void +__attribute__((__noinline__)) report (struct info *p) +{ + struct foo *bar = (struct foo *)p->data; + EXPECT(__builtin_dynamic_object_size((char *)(bar + 1), 1), 16); + EXPECT(__builtin_dynamic_object_size((char *)(bar + 2), 1), 8); +} + +int main(int argc, char *argv[]) +{ + struct info *p = setup(); + report(p); + return 0; +} diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 630b0a7aaa4b..c3098c521a43 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -763,17 +763,21 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, 2: the number of bytes; 4th argument TYPE_OF_SIZE: A constant 0 with the TYPE of the object refed by REF_TO_SIZE + 6th argument: A constant 0 with the pointer TYPE to the original flexible + array type. - the size of the element can be retrived from the result type of the call, - which is the pointer to the array type. */ + the size of the element can be retrived from the TYPE of the 6th argument + of the call, which is the pointer to the array type. */ static tree access_with_size_object_size (const gcall *call, int object_size_type) { gcc_assert (gimple_call_internal_p (call, IFN_ACCESS_WITH_SIZE)); - /* result type is a pointer type to the original flexible array type. */ - tree result_type = gimple_call_return_type (call); - gcc_assert (POINTER_TYPE_P (result_type)); - tree element_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (result_type))); + /* the type of the 6th argument type is the pointer TYPE to the original + flexible array type. */ + tree pointer_to_array_type = TREE_TYPE (gimple_call_arg (call, 5)); + gcc_assert (POINTER_TYPE_P (pointer_to_array_type)); + tree element_type = TREE_TYPE (TREE_TYPE (pointer_to_array_type)); + tree element_size = TYPE_SIZE_UNIT (element_type); tree ref_to_size = gimple_call_arg (call, 1); unsigned int type_of_size = TREE_INT_CST_LOW (gimple_call_arg (call, 2)); tree type = TREE_TYPE (gimple_call_arg (call, 3));