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 A99703858003 for ; Tue, 10 Aug 2021 22:26:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A99703858003 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17AMBfhK031445; Tue, 10 Aug 2021 22:26:41 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3abwqgrmng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Aug 2021 22:26:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 17AMGT7O177362; Tue, 10 Aug 2021 22:26:40 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2106.outbound.protection.outlook.com [104.47.55.106]) by aserp3030.oracle.com with ESMTP id 3abx3ukbq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Aug 2021 22:26:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ThAeg3gNb/8CaTnbvtrwpmlcIbbeq+I6JdiE71BntfVSmlyO3DZLn/eAHjCTwThx0ltYeldJmee+803bxSCzyofJ1cnT0CJMiHq5s8paDJji54ZbzDQ9xv8z6wUwdccQOiaQQbkcZETpMDLzcQ8fn2t6hupIYysfVdeG7qKjZskb8w+nI9t188aFIivbitANChhDt1cCmQWGlmBTx28+vPvcaGnf0wSZe2KKeembUOli7nJnTfo0td8LU2lDRMPDwZcs+cOw+jr4QQ1kHbGQ6kr/FOiDFaGbqoMSvL+FwCViPRrjszFtDCqkyiWSaAHidYoQkKnPx9p00buFa3Jlog== 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-SenderADCheck; bh=vUDOztrNtr+KX8Tcy96InVPUA/a76ZTfF8oyCm9dwbc=; b=L58WWg+IQcWZ2SmnVVWp8T09H48UuLoBRq9qZ2aNdmYZJM1/TlLj/tJMwiA2pcv3WXvMoRBtGIMAByiubzWNpiU7X4WdAX9eDjWG94C0yUs/FRxRD1sCz9eIJjXaPYVr2htxRRzP2UVHZYPcECGFGBG7bkRff3I7/q17Qy4t0TTOlt2XTP8q4A+78T0IpyHUep/yGL3e/mP8IPvJ7JE8hV2dN2tT76IqHLcWCJiItz1AknMDEYXy/XyMuaxZUtCUc2avjNYb9hXuQxiMhPz4PDCUfoegNtBt/5GiviC1Bu/1fEkV/6h+UGHOS6vGIcwNIMnLSK5Ykdp4AfIJGwIM6w== 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 Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by CH0PR10MB5243.namprd10.prod.outlook.com (2603:10b6:610:dc::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.13; Tue, 10 Aug 2021 22:26:37 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::f463:6b71:2491:d547]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::f463:6b71:2491:d547%9]) with mapi id 15.20.4415.014; Tue, 10 Aug 2021 22:26:37 +0000 From: Qing Zhao To: Qing Zhao , Richard Biener CC: Jakub Jelinek , Nick Alcock via Gcc-patches , Kees Cook Subject: Re: [patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc Thread-Topic: [patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc Thread-Index: AQHXgpcfj6SO0Rka1UmU0GU91mFncqtrSzIAgAApjACAAPr8gIAAZYMAgAAKVgCAAAy9gIAABZoAgABR/YCAACR6AA== Date: Tue, 10 Aug 2021 22:26:37 +0000 Message-ID: References: <52E29277-1403-4755-901A-528116C43FB8@oracle.com> <58ADBC0C-9D44-485B-BB5A-B072664B9C4F@oracle.com> <6FD42B95-F73D-4B75-B83A-BAC4925B1714@oracle.com> In-Reply-To: <6FD42B95-F73D-4B75-B83A-BAC4925B1714@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3608.120.23.2.7) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6d8dbc8c-3a77-49b4-0570-08d95c4deb30 x-ms-traffictypediagnostic: CH0PR10MB5243: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: oSDcIjunpcXtMZwJE+viuC15qwn5khkDetNEfcztibiP+n/LRiXsMjkYWDjBqNu338EAtlIdxITCrTX7dsCFAeVr5tklMyZc6aOPFO16NDuauB3V8oR+aRDIlG6mLETDv/y5mF2fS15RqzplNYBSmp42B7BZe5hNVhKsXCEAU58FOM3PjcV49qDIK+Z4Vkw/dUqHz47sdzy+KODs8E34TPSAqOyg/LrBoDKHPbwA+DmFYMFtLsNXasdbaCK+LYXS3lfnB62CNh5iUKrraA7QubjJNQTfEQVekg4Ir0HAYoIO45Eo8qlDn7bkYhhY05wQ3yK+7VJsHFMmUwuowvOM4s/4WTrydfhSfr6kbA8UUh9u70+2+58NJvydh6cSDm4RqnFCld9woYeNzZYGi6Y5L1+ce4VNbelPLFSGh2BGc42xLD050NOhUjbaaWGsRzIhtpx0UJEpOXUb0qPGOI+QIKKWjVRBTvVWEO8fjTlRVAPDyileMdowH8mpkomiehByKITqPYpV4NsMJIdk4vlytcNznLvJLUNCESdTABi+EVpPTYI9gfPKq3+rGuV+2882cDPaclQJ6AUu0tFFN6mOTo1S5qi9UFzdL2wdbQGuT6aoGdPtBgbQYPJIBQeL855E1p3rOHvv0gC3JOTb/aurc8A/GzF3XxeGxJwgnoFApBlEHCEM5yht5BNQqe323527VvFcdTjfU7zh0u/SrQSzlcatG6r807AW+Q1N984yDvY6RsL7u3aCE6NTWjbMkjIrG83SzsybpGvwmHKAv6P0FA== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4344.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(366004)(396003)(376002)(346002)(39860400002)(86362001)(44832011)(8676002)(53546011)(110136005)(316002)(122000001)(36756003)(6506007)(2616005)(5660300002)(71200400001)(83380400001)(4326008)(54906003)(478600001)(186003)(38100700002)(8936002)(66946007)(6512007)(66556008)(33656002)(64756008)(91956017)(6486002)(66476007)(66446008)(38070700005)(2906002)(76116006)(45980500001)(266184004); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?BUwqej9ZFwTPgFIOFvHTLqxuZqcklLHtu/ZDXesJm5jfNQugF1jBtS+h0g4b?= =?us-ascii?Q?tMcJmu2EqJ+1W9yHkooxBnvB5NGsWLeOQciWvKElYCF2OYnE8aJvH58+2qrp?= =?us-ascii?Q?do8prQ8A5tzy/yoO5IFTbl3zndMw5F9a/SO7UvfApmo9aNdN8KhfjyK0hGqk?= =?us-ascii?Q?iOtcyTcULKcWdOxq7598PXwZsDmpMnjtuN32ebiUip85/ToMrIn5nrI4hbdM?= =?us-ascii?Q?vP3XrFHMQVlHvhMdaz5ClIXUNlMylbvKy8K+bgKa9Il0+z109m6e+bzL9M8S?= =?us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gdks8MO8v7uD2j?= =?us-ascii?Q?+xeexKRMovCmd2BFGxXfk/MlIVxJpiks0H0odGx74v8eBrsJ8GLDYlTj+twu?= =?us-ascii?Q?pTZK01Ks9T7BqBFCfls7R5xhf6fed4+J1xA/u6YNTU98rxS58TmmWs5UxB9y?= =?us-ascii?Q?CebepueaCjynH90Mzf2fVfU7YjuCLYcmcPU+AS1BESvNxh/Sb4G6m8m642aQ?= =?us-ascii?Q?jrjbD9o95S1Mtl8D29YzgjzaiI9r?= Content-Type: text/plain; charset="us-ascii" Content-ID: <6EFBD222A6F90B4A924F40162C9DE8BD@namprd10.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d8dbc8c-3a77-49b4-0570-08d95c4deb30 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Aug 2021 22:26:37.6331 (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: 2HAMZ6Xta9BZ4ENrMRlsJRJHOp8poLQhK9hXxs6pckxzwVcG45mCTVChmNBjAL/YsqMFMkz51l1nNLyVTraxJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5243 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10072 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108100147 X-Proofpoint-ORIG-GUID: hyhq2Pb_-3caZAYUQ439kHJO2ZXqTrVk X-Proofpoint-GUID: hyhq2Pb_-3caZAYUQ439kHJO2ZXqTrVk X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Aug 2021 22:26:54 -0000 > On Aug 10, 2021, at 3:16 PM, Qing Zhao via Gcc-patches wrote: >=20 > Hi, Richard, >=20 >> On Aug 10, 2021, at 10:22 AM, Richard Biener wrote: >>>>=20 >>>> Especially in the VLA case but likely also in general (though unlikely >>>> since usually the receiver of initializations are simple enough). I'd >>>> expect the VLA case end up as >>>>=20 >>>> *ptr_to_decl =3D .DEFERRED_INIT (...); >>>>=20 >>>> where *ptr_to_decl is the DECL_VALUE_EXPR of the decl. >>>=20 >>> So, for the following small testing case: >>>=20 >>> =3D=3D=3D=3D >>> extern void bar (int); >>>=20 >>> void foo(int n) >>> { >>> int arr[n]; >>> bar (arr[2]); >>> return; >>> } >>> =3D=3D=3D=3D=3D >>>=20 >>> If I compile it with -ftrivial-auto-var-init=3Dzero -fdump-tree-gimple = -S -o auto-init-11.s -fdump-rtl-expand, the *.gimple dump is: >>>=20 >>> =3D=3D=3D=3D=3D >>> void foo (int n) >>> { >>> int n.0; >>> sizetype D.1950; >>> bitsizetype D.1951; >>> sizetype D.1952; >>> bitsizetype D.1953; >>> sizetype D.1954; >>> int[0:D.1950] * arr.1; >>> void * saved_stack.2; >>> int arr[0:D.1950] [value-expr: *arr.1]; >>>=20 >>> saved_stack.2 =3D __builtin_stack_save (); >>> try >>> { >>> n.0 =3D n; >>> _1 =3D (long int) n.0; >>> _2 =3D _1 + -1; >>> _3 =3D (sizetype) _2; >>> D.1950 =3D _3; >>> _4 =3D (sizetype) n.0; >>> _5 =3D (bitsizetype) _4; >>> _6 =3D _5 * 32; >>> D.1951 =3D _6; >>> _7 =3D (sizetype) n.0; >>> _8 =3D _7 * 4; >>> D.1952 =3D _8; >>> _9 =3D (sizetype) n.0; >>> _10 =3D (bitsizetype) _9; >>> _11 =3D _10 * 32; >>> D.1953 =3D _11; >>> _12 =3D (sizetype) n.0; >>> _13 =3D _12 * 4; >>> D.1954 =3D _13; >>> arr.1 =3D __builtin_alloca_with_align (D.1954, 32); >>> arr =3D .DEFERRED_INIT (D.1952, 2, 1); >>> _14 =3D (*arr.1)[2]; >>> bar (_14); >>> return; >>> } >>> finally >>> { >>> __builtin_stack_restore (saved_stack.2); >>> } >>> } >>>=20 >>> =3D=3D=3D=3D >>>=20 >>> You think that the above .DEFEERED_INIT is not correct? >>> It should be: >>>=20 >>> *arr.1 =3D .DEFERRED_INIT (D.1952. 2, 1); >>>=20 >>> ? >>=20 >> Yes. >>=20 >=20 > I updated gimplify.c for VLA and now it emits the call to .DEFERRED_INIT = as: >=20 > arr.1 =3D __builtin_alloca_with_align (D.1954, 32); > *arr.1 =3D .DEFERRED_INIT (D.1952, 2, 1); >=20 > However, this call triggered the assertion failure in verify_gimple_call = of tree-cfg.c because the LHS is not a valid LHS.=20 > Then I modify tree-cfg.c as: >=20 > diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c > index 330eb7dd89bf..180d4f1f9e32 100644 > --- a/gcc/tree-cfg.c > +++ b/gcc/tree-cfg.c > @@ -3375,7 +3375,11 @@ verify_gimple_call (gcall *stmt) > } >=20 > tree lhs =3D gimple_call_lhs (stmt); > + /* For .DEFERRED_INIT call, the LHS might be an indirection of > + a pointer for the VLA variable, which is not a valid LHS of > + a gimple call, we ignore the asssertion on this. */=20 > if (lhs > + && (!gimple_call_internal_p (stmt, IFN_DEFERRED_INIT)) > && (!is_gimple_reg (lhs) > && (!is_gimple_lvalue (lhs) > || verify_types_in_gimple_reference >=20 > The assertion failure in tree-cfg.c got resolved, but I got another asser= tion failure in operands_scanner::get_expr_operands (tree *expr_p, int flag= s), line 945: >=20 > 939 /* If we get here, something has gone wrong. */ > 940 if (flag_checking) > 941 { > 942 fprintf (stderr, "unhandled expression in get_expr_operands():\= n"); > 943 debug_tree (expr); > 944 fputs ("\n", stderr); > 945 gcc_unreachable (); > 946 } >=20 > Looks like that the gimple statement: > *arr.1 =3D .DEFERRED_INIT (D.1952, 2, 1); >=20 > Is not valid. i.e, the LHS should not be an indirection to a pointer.=20 >=20 > How to resolve this issue? I came up with the following solution: Define the IFN_DEFERRED_INIT function as: LHS =3D DEFERRED_INIT (SIZE of the DECL, INIT_TYPE, IS_VLA); if IS_VLA is false, the LHS is the DECL itself, if IS_VLA is true, the LHS is the pointer to this DECL that created by gimplify_vla_decl. The benefit of this solution are: 1. Resolved the invalid IR issue; 2. The call stmt carries the address of the VLA natually; The issue with this solution is: For VLA and non-VLA, the LHS will be different,=20 Do you see any other potential issues with this solution? thanks. Qing