From patchwork Wed May 1 16:52:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 89241 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 71CCF384AB6A for ; Wed, 1 May 2024 16:53:19 +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 BCD8F384AB48 for ; Wed, 1 May 2024 16:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCD8F384AB48 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 BCD8F384AB48 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=1714582368; cv=pass; b=OWCFEzj1eDesKYppnRuWocrHlHMzmTeoVNiMkT6z8R9H3cpkuwplWysY9X9mc9PWxku9HvW2osLxPyVun4oD9m94xD3Qaj58AdSfSXwDVytoIckx5hxF46twdGYJqzMSg2KZRVF2Z0t+fhhP0AGDSYQ1O1MT7CWoMUkMLEWSs4w= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714582368; c=relaxed/simple; bh=DqxCyKccp0YyLzT3sv3UM0AomxH0pQktKP7vzQtsyq8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=w3D30bql8W8PZB/HB1i4d2JhWcu/15Ci0Fs9r6X0wYs2sZHcXnaI7KI6TkdXBe7WyGTyYjmAg7gzVUz/zKxx9Jcvq6Ejpo47Sts56mrsxj019y1bhHtjbi3GdRyaFqA+NBjLqkRfy3nWme4jOhmHR+FlxOlmLSzFkGhXCfEoQfA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 441ARmYW022667; Wed, 1 May 2024 16:52:45 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=F8ewRtmekHALVpzyC3c6mWq6PRN+E5jy1llYQJfHoeO5Fk57rJr8p0jB5E2e+AgZEvt5 MTZxIrGjtWIUio8KnoLYgReil14ECKnQFP8A1fdcVl+7I/wvBzJzoIZPP//70LvEO/JN udm5OIYsoOvCuMZr4KPcCnKx8nlQqv/pKqhJbE+AXu+TTb6tNVa9oUdIE3Z1kdi1fRwL hJwe9ryBo0akcaS2Z1jmmL4xeV9diSz5+uVJJN3+tXwWkNi5VmHsOn9kQwLZTdRkAJbz U59KTl+aQi5N00JY0KYtLjxSOEUIT9Ic5hj8jAC5+8nA3o//cggtzyG5bF74mbp3sHx0 lg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv7kdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:44 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 441FsbPO011415; Wed, 1 May 2024 16:52:43 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt9h9pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tu5m76se/hdUAkeLdNfRwfn6Kf2mdI0BJ9ay8a3QJujURQKLwsK06iI6VSQMlzwHayxf40YkshIWqgnvUL1fmshlvo2iTJKkm3vF7od2d+1655PYz8qAtAGGbUv5YJVlC4Oi7gyLXKYLUvBm+PpkOMyqWPkpKLZjMeY4as2o2ITKJ+CmXUGYCNrhMuL3NecCUkIahp2pIztSj99yFA0I16wzmsZtrasgWAKqFF0/Pkzgs+X1/fqVHJOLHUZpVV/71XFi8dwB7vD1VKAdzEVCxlXMFX30F1SyUd+TevWvRUw5a1XzWd/rjsFPkZCBy/a+5Z3qEutwlj+SCfbzGY+jRg== 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=iaRr5UigGYZu1K2tdRlMHznHUM99/9qBh1tjASIBBdvnnMPGj9SSnfLBtjpXexwR6wG4JNOBz9h4fX+XUNOsuUtA5ITY4A1RtO32bwBlVvarjIRG8EsOqpZU4ut+zSRELvRcfVr66OtXb5qnnWZChfq44l7+glvDEd3qUBsTMA0kXctGCQNwkSyTPRHTqnHt/wzzaVztlooEmqTnRxoAsgW0ML3CTghavfr5F6CfLPdsJm5bk6BDSo+M0Up/w6Lroa9j0I+1V5rmfPNRum8Uaw/vgXGeyPze0yFlQdEbqj6WRwpZizu3tjXWEtddXFiiEnaU97mX1xzzKALBfz/35g== 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=NJ/94YCpu1NO0QXOKXq4JbWTgRq+o1VKI5ZxkwEhIdZwcO85MjDU1/NVGqC/n/FUP7PB2fhc9gk2du3lPaEn6l6+LYChSFi54KMPiekWu7g8+XiiTimJB2wZD6vrvd1+oa9TfAhrhUn7QlwoV48DQTfNgJW7Q0pNMwnxOqw8Gjo= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by BLAPR10MB4962.namprd10.prod.outlook.com (2603:10b6:208:327::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28; Wed, 1 May 2024 16:52:40 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc%6]) with mapi id 15.20.7519.035; Wed, 1 May 2024 16:52:40 +0000 From: Qing Zhao To: jason@redhat.com, josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org Cc: uecker@tugraz.at, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v5 2/4] C and C++ FE changes Date: Wed, 1 May 2024 16:52:24 +0000 Message-Id: <20240501165226.2924144-3-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240501165226.2924144-1-qing.zhao@oracle.com> References: <20240501165226.2924144-1-qing.zhao@oracle.com> X-ClientProxiedBy: LO2P265CA0216.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::36) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|BLAPR10MB4962:EE_ X-MS-Office365-Filtering-Correlation-Id: 5301cc40-1fc9-4bf3-328a-08dc69ff1cd5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|376005|1800799015; X-Microsoft-Antispam-Message-Info: 7+FX+pKHsQSoMCjDUsqG+8SGyfuhmxrnuc7Yx2PYfIDdMLJPT3SCHBmDSX5CbCReNR4BRLiiZQge+13/sumHLhcSya3KljMjspH5tn082uzUF5i130IKsBRE49ZIT+KpKHgIcqhsElUEeNC3Dx//96hRHFzQ+BjK24qYmc4+NRmjdum0a3KFLNfsbJNQFd0+HxoAFEu+WyOC6OY9dpNakpAl26b22rLtfk5Es4ToS1OMm4oPeZ6ITaleHFbjSqblna7pGW1F8csU82IRp9pUf99KY7JZIwcWFB5YI3HkSRO52lP0aobaH1kdqUY7QtLu9pwOXmDZh01/JXsh3BpCpKa8SA2CjSIAR637CmlmmMdeP8vsZgfU9yxkdDd8aDN7sNkC5VinEayr6ajW8lHSSiPhSP2J4N0JyCXwbyRcKgSe0niYzcarO8yNKO6CAhb4K/QtsSvJfkw+artaPH1VNP5arHKWDDMaQrN9EttRRH5qFYd6nwDr5DcQVm36pIA/ShXdLkatcMq4Is9gacbTh3ZFzUVQX4+SOAtDHJZHxZW1caJcOQyLQ7R0uNieuVYiK+7bnRISb6KBs3oKNASyjls7/FYeEnwyimItYpD6XAlthQYXJX+4KIxV6M3VSntwYpXccpoo2hQ34eEd9384GlOuIDbkV5FpCn6SM/ZDq9fqkX3iRgGPb91RD3BENVi0S+8PJVxbILm/bp+cibES4QT425G8KJ2I+GLaYKEmOPxFskGgCeLYRzxEnxMUSTbhjLa/T5TpOCH+WZfP2o1/Ht0G1wSHqs4Ajh/EJORTTSN4YSoHVIrpyrEuyrlUg27g4KfvxxZIdF1wzHUJ3VMk+kL8xkYby98tb+tx3J31QJXf/VwhdbqWv1kjXFhjDHnDmx3mnXeGpiYtYfkHKzVQghKLZn7Ft1eSFocz80RcIGvur25MaIfCWDCfBToZhOx4ZBUWc3DuDlBfdaQ6NRClkgt/zB6jhdguDL3Lgz+Y9f59UZgs2TKsx6K+U+iDT9CUMu+a+gqYffxS8tRfQlfziEokX4AwHDdQnPqOxPCdy3dyw70ISFqQAKem1C7lXAxWzo9k6oNzsITcWdKmRoHb/m1FknQkTa1K/kuJYS9DOJTfEdhkCdOdH2fgy9W0fBk3BNP95KBZENPMzayy8gjVHOSvllEXH/QnbojP1YRMoJhRnqncyUK8aNj6jMgx3nP8RHazex3kdEykVhpr8KuIusxrtQEYHcFlctsH3g1aqVk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY8PR10MB6538.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gmFGmTUSygGMhoCAFV5rEwvGxxqERVM8go44nvo09V6wzEUBwJH48chTv0DSzJ0CMJFzEGtpjSIf9Xamuh+2xehKVLW/QJ8PVhoELgO6WucJ3H7fhfksG02cNBq6C66REuIs2e0cPQ4Fv7QWhwwoNma2w5z4bsOjMoAqezubQV3KcfeQtzvL2QksZpzNy5ZOmUNjXKrNQmG5EKJJ7dtHmGI0BwAg/a47F2NrsndNSNdFSbFiY/QbGQrYDjkjItyZwiGpXXv+NkMv7lV23ffHvz1TIBNBM5G7Odey78XOUTCDOkm6x/0sRbYZndAFvLNg8sOlE7YjrchLen2dFSK5vRvzfOEDbMppKSVxcVLiXzXfagsHIRo782+Fk62gX7lKAA2/b6r7B/m6cFOPow9XAyuDlyvJRmzttvz4XNu6sHy71YH0i+ve08c9rUCIgpVRW2zuKxaKGX7RBPhrnEB2RGC0yPIkQbyJSaDivINuGMEGiIBQspYeXvpUlUQluW11rlIL+AGXuQTXmxJhnKzBtMg9GUX5dlwjnBgZYFb2uUIKSIIMyYhrpxHHWN2R+k9tVo0YpMawTrYwc062FK2/07Kv4k2In0J4+Q0jxiZ6p31jG3U2tqkWdniy/oepEt27QRP6iLkozpD2DKkxCKR2MK9FHWGbW4MlRvYqp9sa6YhGszjZSShBNpPteD+/mhiuc+EA9VgjyNjQ7JFVceXgrbJ24l0aUMvPRrD5ahyT8MKJM7iyvwzVUL2TWyrwuEWY6WLibSv/ZuTVtfAecpQV608k8qOqucF/s4EC+G8uuWt/eptm3xX2JLTWPpXLolL5E/bBBKd4HE/SeV2QktFLT9U1qFOWLftGf6zDfKuWm0W4afoeUrtl3V7cHrOzqRGLeY5rqF0583QIMwtrSoTu8yTn9itVAXqQhODSzNBWTYHR+vF8hX3jaaDwCwbfyldA12Ka/euAT9JAdmJy8A5aWeVDdNS5rdaQ59a/1exYQ0x3Ffa2/YL+FLPNCn0r4q0ju65dX0XhzQRivtw40AX3rfjJ70HwNFm0X9uOthA1GPu9TyNEYTxkmtCF+7el1MNyEZgrvI0Z3seLJ41fuhPWH+rkxZTf7HxBL9k1jgOsEOHCKF2bHK7hxYc0HRdntxcw/sW2IFgTizrjRTlWbPoRaVJJaJzEOEf5XzewjlkGbgCHkF05bD3BS5v9lBQuSjWizUvd2f/uQGLLW0j7fnF+giVmWubmaJSgpmyMy1lwHydZHqb4fGAau0vrGpWxEVFEHRVslju1Tnp9CjsjNhg3+zK6m3kxD/D+MQqa492Odwqn1g9a+d+u88CpBwj74sB/E3BVjHip8zp5tM/e/FdlzEyw/0mXlahX9TDoDOaa/GHnM0VrHmPFjIKIQbYFUKjDqz4tucYBggmTBwAxOrX7cuKp7XUIh/vE1WdPL1J13dUeUBln7k6wSWevuOd/UfW4fxQIEr7TT1NTp9j7dTCauNwJzahu/F+ct6Ohz5KkR6yPx7W4Qpa8qvU8EPoZTLN89+KElJvZm6YSNs8bANEhSF5mMhbjoIQma/pPN+PjfCJSkoqI5D3ZZyRU0CljtUlS X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fC4RY9ZxgUAsDpwseVaMnEKG7AKpx9N5a3N3UtLge80uyLA/dCXMBcmlotiLuqFUFD1wiFFYiltmWyxnNcYnmhg6tcoJCMOg+LLYut5pc9U+jmUBMB0PRqCmItzdUOtti5zFpUFaj4fHEWqrT9T8liDZzLvWlyHl4qiqn+MQ6RuRhsYiFpt+HLMXrHi3CtUblfIwK/TS/KnoYKEFxl+ES8asjhALsYiHcyPquy+NOgj42fASNZi0WxpRSlZaD1ZqJUV+wR8iTOyUBQpQFjdG0B2j68kU5sYvRpiV5prvTRtWSk5YdPaqgRZkJ/TDzdR0L8wXaxII6MGHq78ayohK/xtc0hoAWgSz0LrO8fpgFCzobjNX1Gbyp8MpmLZVlCtxc5eA+1qkW3REN7ZYLKeJkCdvCAQU1bbcwiNI8YkqeROVHNtbghU/FjE/f+jlUDy2b9K6Dp3XADJOC0qYl2Q7gUhg7HfgxOX8FuJVDr1vwFSZk8WOA0FYTJELiu8UoyvMwec8mfLF7RxzfZ7njqfnqh+T0QYrYhsHnfntX2vhd0ohMC0miV++ePI39Xzeni3sajOO87xSKbXrd+TUxwIfTh1F+ZnyOVb5595HUxmRZ8o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5301cc40-1fc9-4bf3-328a-08dc69ff1cd5 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 16:52:40.3627 (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: sk/nBoKBkG3OPKXRR5oVYmUHiW3kKjUSwCRdgb/S7VrqkmaKKxgEvHsTUpvOFWgnzkKJk9GSI10BwpNYjajW1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4962 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-01_16,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405010118 X-Proofpoint-GUID: d1tFzV_JvScMa-IPrEbvBs8k5_rrDVfm X-Proofpoint-ORIG-GUID: d1tFzV_JvScMa-IPrEbvBs8k5_rrDVfm X-Spam-Status: No, score=-11.6 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_H4, RCVD_IN_MSPIKE_WL, 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 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 support flexible array members in unions and alone in structures. Adjust testcases for flexible array member in union and alone in structure extension. gcc/c/ChangeLog: * c-decl.cc (finish_struct): Change errors to pedwarns for the cases flexible array members in union or alone in structures. gcc/cp/ChangeLog: * class.cc (diagnose_flexarrays): Change error to pdewarn for the case flexible array members alone in structures. * decl.cc (grokdeclarator): Change error to pdewarn for the case flexible array members in unions. gcc/ChangeLog: * stor-layout.cc (place_union_field): Use zero sizes for flexible array member fields. gcc/testsuite/ChangeLog: * c-c++-common/builtin-clear-padding-3.c: Adjust testcase. * g++.dg/ext/flexary12.C: Likewise. * g++.dg/ext/flexary19.C: Likewise. * g++.dg/ext/flexary2.C: Likewise. * g++.dg/ext/flexary3.C: Likewise. * g++.dg/ext/flexary36.C: Likewise. * g++.dg/ext/flexary4.C: Likewise. * g++.dg/ext/flexary5.C: Likewise. * g++.dg/ext/flexary8.C: Likewise. * g++.dg/torture/pr64280.C: Likewise. * gcc.dg/20050620-1.c: Likewise. * gcc.dg/940510-1.c: Likewise. --- gcc/c/c-decl.cc | 16 ++---- gcc/cp/class.cc | 11 ++-- gcc/cp/decl.cc | 7 ++- gcc/stor-layout.cc | 9 +++- .../c-c++-common/builtin-clear-padding-3.c | 10 ++-- gcc/testsuite/g++.dg/ext/flexary12.C | 6 +-- gcc/testsuite/g++.dg/ext/flexary19.C | 42 +++++++-------- gcc/testsuite/g++.dg/ext/flexary2.C | 2 +- gcc/testsuite/g++.dg/ext/flexary3.C | 2 +- gcc/testsuite/g++.dg/ext/flexary36.C | 2 +- gcc/testsuite/g++.dg/ext/flexary4.C | 54 +++++++++---------- gcc/testsuite/g++.dg/ext/flexary5.C | 4 +- gcc/testsuite/g++.dg/ext/flexary8.C | 8 +-- gcc/testsuite/g++.dg/torture/pr64280.C | 2 +- gcc/testsuite/gcc.dg/20050620-1.c | 2 +- gcc/testsuite/gcc.dg/940510-1.c | 4 +- 16 files changed, 91 insertions(+), 90 deletions(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 345090dae38b..947f3cd589eb 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9471,11 +9471,8 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, if (flexible_array_member_type_p (TREE_TYPE (x))) { if (TREE_CODE (t) == UNION_TYPE) - { - error_at (DECL_SOURCE_LOCATION (x), - "flexible array member in union"); - TREE_TYPE (x) = error_mark_node; - } + pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic, + "flexible array member in union is a GCC extension"); else if (!is_last_field) { error_at (DECL_SOURCE_LOCATION (x), @@ -9483,12 +9480,9 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, TREE_TYPE (x) = error_mark_node; } else if (!saw_named_field) - { - error_at (DECL_SOURCE_LOCATION (x), - "flexible array member in a struct with no named " - "members"); - TREE_TYPE (x) = error_mark_node; - } + pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic, + "flexible array member in a struct with no named " + "members is a GCC extension"); } if (pedantic && TREE_CODE (t) == RECORD_TYPE diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 5f258729940b..0c8afb72550f 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -7624,6 +7624,7 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem) bool diagd = false; const char *msg = 0; + const char *msg_fam = 0; if (TYPE_DOMAIN (TREE_TYPE (fmem->array))) { @@ -7649,15 +7650,19 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem) if (fmem->after[0]) msg = G_("flexible array member %qD not at end of %q#T"); else if (!fmem->first) - msg = G_("flexible array member %qD in an otherwise empty %q#T"); + msg_fam = G_("flexible array member %qD in an otherwise" + " empty %q#T is a GCC extension"); - if (msg) + if (msg || msg_fam) { location_t loc = DECL_SOURCE_LOCATION (fmem->array); diagd = true; auto_diagnostic_group d; - error_at (loc, msg, fmem->array, t); + if (msg) + error_at (loc, msg, fmem->array, t); + else + pedwarn (loc, OPT_Wpedantic, msg_fam, fmem->array, t); /* In the unlikely event that the member following the flexible array member is declared in a different class, or the member diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 65ab64885ff8..9a91c6f80da1 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14566,10 +14566,9 @@ grokdeclarator (const cp_declarator *declarator, if (ctype && (TREE_CODE (ctype) == UNION_TYPE || TREE_CODE (ctype) == QUAL_UNION_TYPE)) - { - error_at (id_loc, "flexible array member in union"); - type = error_mark_node; - } + pedwarn (id_loc, OPT_Wpedantic, + "flexible array member in union is a GCC extension"); + else { /* Array is a flexible member. */ diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc index e34be19689c0..10c0809914cd 100644 --- a/gcc/stor-layout.cc +++ b/gcc/stor-layout.cc @@ -1245,13 +1245,18 @@ place_union_field (record_layout_info rli, tree field) && TYPE_TYPELESS_STORAGE (TREE_TYPE (field))) TYPE_TYPELESS_STORAGE (rli->t) = 1; + /* We might see a flexible array member field (with no DECL_SIZE_UNIT), use + zero size for such field. */ + tree field_size_unit = DECL_SIZE_UNIT (field) + ? DECL_SIZE_UNIT (field) + : build_int_cst (sizetype, 0); /* We assume the union's size will be a multiple of a byte so we don't bother with BITPOS. */ if (TREE_CODE (rli->t) == UNION_TYPE) - rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field)); + rli->offset = size_binop (MAX_EXPR, rli->offset, field_size_unit); else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE) rli->offset = fold_build3 (COND_EXPR, sizetype, DECL_QUALIFIER (field), - DECL_SIZE_UNIT (field), rli->offset); + field_size_unit, rli->offset); } /* A bitfield of SIZE with a required access alignment of ALIGN is allocated diff --git a/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c b/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c index d16cc6aad05f..a4f49f26db14 100644 --- a/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c +++ b/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c @@ -2,14 +2,12 @@ /* { dg-do compile } */ /* { dg-options "" } */ -union U { int a; char b[] __attribute__((aligned (2 * sizeof (int)))); }; /* { dg-error "flexible array member in union" } */ +union U { int a; char b[] __attribute__((aligned (2 * sizeof (int)))); }; struct V { int a; union U b; }; -struct W { int a; union U b; int c; }; void -foo (union U *u, struct V *v, struct W *w) +foo (union U *u, struct V *v) { - __builtin_clear_padding (u); - __builtin_clear_padding (v); - __builtin_clear_padding (w); + __builtin_clear_padding (u); /* { dg-error "flexible array member" "does not have well defined padding bits" } */ + __builtin_clear_padding (v); /* { dg-error "flexible array member" "does not have well defined padding bits" } */ } diff --git a/gcc/testsuite/g++.dg/ext/flexary12.C b/gcc/testsuite/g++.dg/ext/flexary12.C index b0964948731d..6ba4b6417135 100644 --- a/gcc/testsuite/g++.dg/ext/flexary12.C +++ b/gcc/testsuite/g++.dg/ext/flexary12.C @@ -6,7 +6,7 @@ // { dg-options "-Wno-pedantic" } struct A { - int a []; // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." } + int a []; }; void f1 () @@ -40,7 +40,7 @@ void f2 () } struct D { - int a []; // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." } + int a []; D (); }; @@ -52,7 +52,7 @@ D::D (): // { dg-error "initializer for flexible array member" } template struct C { - T a []; // { dg-error "flexible array member" } + T a []; }; void f3 () diff --git a/gcc/testsuite/g++.dg/ext/flexary19.C b/gcc/testsuite/g++.dg/ext/flexary19.C index abfbc43028af..9a06f9ca758f 100644 --- a/gcc/testsuite/g++.dg/ext/flexary19.C +++ b/gcc/testsuite/g++.dg/ext/flexary19.C @@ -12,7 +12,7 @@ struct S1 // The following declares a named data member of an unnamed struct // (i.e., it is not an anonymous struct). struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -21,7 +21,7 @@ struct S2 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[1]; }; @@ -30,7 +30,7 @@ struct S3 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[]; }; @@ -39,7 +39,7 @@ struct S4 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[2]; }; @@ -48,7 +48,7 @@ struct S5 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[1][2]; }; @@ -57,7 +57,7 @@ struct S6 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[][2]; }; @@ -66,7 +66,7 @@ struct S7 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s; }; @@ -75,7 +75,7 @@ struct S8 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s; }; @@ -84,7 +84,7 @@ struct S9 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s[1]; }; @@ -93,7 +93,7 @@ struct S10 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s[]; }; @@ -102,7 +102,7 @@ struct S11 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[1]; }; @@ -111,7 +111,7 @@ struct S12 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[]; }; @@ -120,7 +120,7 @@ struct S13 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[2]; }; @@ -129,7 +129,7 @@ struct S14 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } &s; }; @@ -138,7 +138,7 @@ struct S15 int i; typedef struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } T15; }; @@ -159,8 +159,8 @@ struct S17 { int i; - union { // anonymous union - int a[]; // { dg-error "flexible array member in union" } + union { // { dg-warning "invalid use" } + int a[]; // { dg-warning "flexible array member in union" } }; }; @@ -209,7 +209,7 @@ struct S22 struct S22S { static int i; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -218,7 +218,7 @@ struct S23 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" } static int i; // { dg-error "static data member" } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } }; }; @@ -227,7 +227,7 @@ struct S24 static int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -252,7 +252,7 @@ struct S26 }; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; diff --git a/gcc/testsuite/g++.dg/ext/flexary2.C b/gcc/testsuite/g++.dg/ext/flexary2.C index c0253777a1e9..7095a3b0fb2d 100644 --- a/gcc/testsuite/g++.dg/ext/flexary2.C +++ b/gcc/testsuite/g++.dg/ext/flexary2.C @@ -13,7 +13,7 @@ struct A { struct B { B() {} - A a[]; // { dg-error "extension|flexible array .* in an otherwise empty" } + A a[]; }; struct C { diff --git a/gcc/testsuite/g++.dg/ext/flexary3.C b/gcc/testsuite/g++.dg/ext/flexary3.C index 8344b42dd163..7785c9b190a4 100644 --- a/gcc/testsuite/g++.dg/ext/flexary3.C +++ b/gcc/testsuite/g++.dg/ext/flexary3.C @@ -11,7 +11,7 @@ // { dg-options "" } struct s { - char c[]; // { dg-error "flexible array member .* in an otherwise empty" } + char c[]; }; int main() diff --git a/gcc/testsuite/g++.dg/ext/flexary36.C b/gcc/testsuite/g++.dg/ext/flexary36.C index 5bb827cfd0e0..87d6fb092100 100644 --- a/gcc/testsuite/g++.dg/ext/flexary36.C +++ b/gcc/testsuite/g++.dg/ext/flexary36.C @@ -25,7 +25,7 @@ struct { union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; int b; } du = { 1 }; diff --git a/gcc/testsuite/g++.dg/ext/flexary4.C b/gcc/testsuite/g++.dg/ext/flexary4.C index bd28cf55de2b..a87b7e71edb6 100644 --- a/gcc/testsuite/g++.dg/ext/flexary4.C +++ b/gcc/testsuite/g++.dg/ext/flexary4.C @@ -11,79 +11,79 @@ #include "flexary.h" struct Sx { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; // Verify that non-data members or static data members either before // or after a flexible array member in an otherwise empty struct don't // suppress the diagnostic. struct Sx2 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; typedef int I; }; struct Sx3 { typedef int I; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx4 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; enum E { e }; }; struct Sx5 { enum E { e }; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx6 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; static int i; }; struct Sx7 { static int i; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx8 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; Sx8 () { } }; struct Sx9 { Sx9 () { } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx10 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; virtual ~Sx10 () { } }; struct Sx11 { virtual ~Sx11 () { } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx12 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; virtual void foo () = 0; }; struct Sx13 { virtual void foo () = 0; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx14 { - int a[][1]; // { dg-error "in an otherwise empty" } + int a[][1]; }; struct Sx15 { typedef int A[]; - A a; // { dg-error "in an otherwise empty" } + A a; }; // Verify also that a zero-size array doesn't suppress the diagnostic. @@ -91,7 +91,7 @@ struct Sx16 { // a_0 below is diagnosed with -Wpedantic only and emits // warning: ISO C++ forbids zero-size arrays int a_0 [0]; - int a_x []; // { dg-error "in an otherwise empty" } + int a_x []; }; struct Sx17 { @@ -123,7 +123,7 @@ struct Sx19 { // so doesn't contribute its member to that of the enclosing struct. struct Sx20 { struct S { int i; }; - int a_x []; // { dg-error "in an otherwise empty" } + int a_x []; }; struct Sx21 { @@ -148,12 +148,12 @@ struct Sx24 { struct Sx25 { struct S { }; - S a_x []; // { dg-error "flexible array member" } + S a_x []; }; struct Sx26 { struct { } - a_x []; // { dg-error "flexible array member" } + a_x []; }; struct Sx27 { @@ -193,13 +193,13 @@ struct Sx32 { ASSERT_AT_END (Sx32, a); struct Sx33 { - int a []; // { dg-error "otherwise empty" } + int a []; friend int foo (); }; struct Sx34 { friend int foo (); - int a []; // { dg-error "otherwise empty" } + int a []; }; // Verify that intervening non-field declarations of members other @@ -277,7 +277,7 @@ ASSERT_AT_END (Sx44, a); struct S_S_S_x { struct A { struct B { - int a[]; // { dg-error "flexible array member" } + int a[]; } b; } a; }; @@ -300,7 +300,7 @@ struct NotAnon1 { // The following is not an anonymous struct -- the type is unnamed // but the object has a name. struct { - int bad[]; // { dg-error "otherwise empty" } + int bad[]; } name; }; @@ -328,7 +328,7 @@ ASSERT_AT_END (Anon3, good); struct Anon4 { struct { - int in_empty_struct[]; // { dg-error "in an otherwise empty" } + int in_empty_struct[]; }; }; @@ -366,7 +366,7 @@ struct Six { ASSERT_AT_END (Six, a); class Cx { - int a[]; // { dg-error "flexible array member" } + int a[]; }; class Cix { @@ -390,7 +390,7 @@ struct S0i { struct S_a0_ax { int a0[0]; - int ax[]; // { dg-error "flexible array member" } + int ax[]; }; struct S_a0_i_ax { @@ -417,7 +417,7 @@ struct Si_ax_a0 { struct S_u0_ax { union { } u[0]; - int ax[]; // { dg-error "flexible array member" } + int ax[]; }; struct S_a1_s2 { diff --git a/gcc/testsuite/g++.dg/ext/flexary5.C b/gcc/testsuite/g++.dg/ext/flexary5.C index d5ec13204966..3fb88c0e8a2c 100644 --- a/gcc/testsuite/g++.dg/ext/flexary5.C +++ b/gcc/testsuite/g++.dg/ext/flexary5.C @@ -13,7 +13,7 @@ struct S_no_diag: T { template struct STx_1: T { - char a[]; // { dg-error "flexible array member" } + char a[]; }; template @@ -37,7 +37,7 @@ struct E1: E<0>, E<1> { }; struct E2: E<2>, E<3> { }; struct D1: E1, E2 { - char a[]; // { dg-error "flexible array member" } + char a[]; }; struct NE { size_t i; }; diff --git a/gcc/testsuite/g++.dg/ext/flexary8.C b/gcc/testsuite/g++.dg/ext/flexary8.C index 7a1811deaff2..a0477f0fa410 100644 --- a/gcc/testsuite/g++.dg/ext/flexary8.C +++ b/gcc/testsuite/g++.dg/ext/flexary8.C @@ -4,26 +4,26 @@ union U_i_ax { int i; - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; struct SU1 { union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; struct SU2 { int n; union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; struct SU3 { union { int n; - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; diff --git a/gcc/testsuite/g++.dg/torture/pr64280.C b/gcc/testsuite/g++.dg/torture/pr64280.C index 5c569e864b4c..1ea70c4e766e 100644 --- a/gcc/testsuite/g++.dg/torture/pr64280.C +++ b/gcc/testsuite/g++.dg/torture/pr64280.C @@ -15,7 +15,7 @@ public: typedef int jmp_buf[]; struct C { - jmp_buf cond_; // { dg-error "flexible array member" } + jmp_buf cond_; }; class F { diff --git a/gcc/testsuite/gcc.dg/20050620-1.c b/gcc/testsuite/gcc.dg/20050620-1.c index befdd9636500..0a9e1d478454 100644 --- a/gcc/testsuite/gcc.dg/20050620-1.c +++ b/gcc/testsuite/gcc.dg/20050620-1.c @@ -5,7 +5,7 @@ void foo (void) { - struct { int i[]; } u; /* { dg-error "flexible array member" } */ + struct { int i[]; } u; } void diff --git a/gcc/testsuite/gcc.dg/940510-1.c b/gcc/testsuite/gcc.dg/940510-1.c index 46183831d096..9bcd7881f715 100644 --- a/gcc/testsuite/gcc.dg/940510-1.c +++ b/gcc/testsuite/gcc.dg/940510-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ /* { dg-options "-std=c89 -pedantic" } */ struct { int a[]; } x = { 0 }; /* { dg-warning "ISO C90 does not support flexible array members" } */ -/* { dg-error "flexible array member in a struct with no named members" "" { target *-*-* } .-1 } */ - +/* { dg-warning "flexible array member in a struct with no named members is a GCC extension" "" { target *-*-* } .-1 } */ +/* { dg-warning "initialization of a flexible array member" "" { target *-*-* } .-2 } */