Message ID | 20230217222603.2485714-1-qing.zhao@oracle.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp97975wrn; Fri, 17 Feb 2023 14:27:04 -0800 (PST) X-Google-Smtp-Source: AK7set9FmyQ60dyp6gwNFX4pVxUwFF3X/mocqXhKy6UNEVtmCW+9Lb+1r0zuDEW1if4Qv3xbTI8O X-Received: by 2002:a17:907:f81:b0:877:a3c4:807b with SMTP id kb1-20020a1709070f8100b00877a3c4807bmr1756831ejc.68.1676672824697; Fri, 17 Feb 2023 14:27:04 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e5-20020a170906748500b00881cca91716si7702907ejl.704.2023.02.17.14.27.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 14:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yvxwDR1n; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38D28385781F for <ouuuleilei@gmail.com>; Fri, 17 Feb 2023 22:27:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38D28385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676672823; bh=iEgoLyH9WTcrOXdnM2XmBAe+VOmH4hu9EFWo1uZiqAY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yvxwDR1nF4KeRA9v0+z4oj4hfTRV03/fvVmbnKPpK37q7cewQaD/Mu+MZODC+Mf1I d96ppFzPx5e10pJEMrFOkkck7mrct5SKW+pM5weTebYCOqzRAoVEiwgjJ8Zev+MLuG 1VE9XJKnImyifAkpDh0oCvo/jgJuvmuHNtIphH3I= 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 819843858291 for <gcc-patches@gcc.gnu.org>; Fri, 17 Feb 2023 22:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 819843858291 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31HLhxDV005849; Fri, 17 Feb 2023 22:26:15 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3np1t3q118-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Feb 2023 22:26:15 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 31HLBI4R015412; Fri, 17 Feb 2023 22:26:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3np1far4j0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Feb 2023 22:26:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hAFl0Jdajcbj5P2XTewD5Vyih1IKrK4NjqUmDWWjB+6te2o0bqa7Bbyt5cFVtnzVc2pl+TqLwKyA6jQnbzVxugRGhwpH0Y9ikuduhP7y+e9P1f80slVew3Stvy7J/oSHA6UJgGzAGP2ktqA7jUWoEi8vKVf20ZWHP5iuB1OyNNkSjHSuzHwqi6HFK3lR9Anvgbutmtgc62JJQiW2cVZb/jt0yVykiAPdE4lpUKxugRVrM8kBT33ShFANxQAQCbffcc0pyWXr2JE50R7qFgjU/7ePqL2tmy7XjRb6y01x+zvfyhiVpnzWtAJxYou5fPQGVIhjDA+feTl39pnxfTGrsw== 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=iEgoLyH9WTcrOXdnM2XmBAe+VOmH4hu9EFWo1uZiqAY=; b=Iy4RHs2xWKAfJYBy6+sB7EPcQCmwJuThh/TpztgTb/BSe0MoxwFPFWXlKN+wWYtqlHvxgknVKCU9oy40CtPhP5ewyN+fB+AmlBYsadxvJAtBBQGkVEyvOjjq9HRFzZfLhvnDFVQ8HHVqs7dKMNupCBwiLhUqVGeDNKy1N3IVMB15O8kMJvNOwZ6Duo1l+qox3J+Rye636+mNb0MvMtHVPe3oNFoK3qKjeBHdv+4gtP/eLbcplMJWIm9LzjCeTqIAeubA9TCe1z+R4NIS4xeF2IAn05yVXTItAcqhjhBYyo7wXB/1LTibcdxmmAiCNQvB5mZwbzdeFFDj2VLRgn+ToQ== 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 BLAPR10MB4834.namprd10.prod.outlook.com (2603:10b6:208:307::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.12; Fri, 17 Feb 2023 22:26:12 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::7030:ed2e:20d0:cd5b]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::7030:ed2e:20d0:cd5b%7]) with mapi id 15.20.6134.013; Fri, 17 Feb 2023 22:26:12 +0000 To: rguenther@suse.de Cc: gcc-patches@gcc.gnu.org, Qing Zhao <qing.zhao@oracle.com> Subject: [PATCH] Fixing PR107411 Date: Fri, 17 Feb 2023 22:26:03 +0000 Message-Id: <20230217222603.2485714-1-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: DM6PR11CA0060.namprd11.prod.outlook.com (2603:10b6:5:14c::37) To CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR10MB4344:EE_|BLAPR10MB4834:EE_ X-MS-Office365-Filtering-Correlation-Id: ac77739c-fd4a-4441-b95d-08db1135f9e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qD3A+W4FbVGnKoWvT6STZc7N04ekOx908z/OXK2SY/LOKzuM9qX9bJFTUXw5PTn4ptduvIT/6ssCQ3YMqfEiuuPQHlNHftfrUij9Ms1zG32Yibmm3+/e1qvBT/cxjpE1p9leLasNs9fYqcCjGuGXY5yZlNIHFlEVeiPh8BZOcAFwbOYbu01DvEzQmxkc4DCvZt5LIDdg+i2cM5FaVB+pOC6ueYsX3jbmHS7k3WK5M4x12YqlepPY7N2Z4vf2wis6gsdrnwvbih+niGF4Oqa+4GZLeJ8QdYThMBVhVxiD0+Ij6gFJhxLu2uzKf2lhgEJmRtyy8VmyBqXt104Z2OAGJzHP1mWEBJu3c6IpbTYXfWvOhwKv8oAeSwg/Bo/VRCMQf9tS8HiYpyBO9xtKg1xGkvTps9JYqt4DAT7YIG44OKMsETtAcUMa3+1SBA7d4oZ6iard/9acfrTkD3K6PrbR2xcnM0XRU5WIvWRW01L8rmnZPTKtw826zJq+Cl9ICOQ9IT9LWANHY/nSMG07y0k4Fqoa/HDB/VwFUWiUWur6HYSJDr2EfYfDHG5kDP/fkqtWK45C22mXCTQ/RRmSGDF7752vmRg7EplHVWB9y0aQPUvsUNCsG0PRtgOBD6BPtcfauoTQ0lVDbwthr1Dpxtqm6A== 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:(13230025)(366004)(136003)(376002)(346002)(39860400002)(396003)(451199018)(8936002)(6506007)(1076003)(5660300002)(2616005)(38100700002)(83380400001)(316002)(107886003)(6666004)(26005)(36756003)(186003)(41300700001)(6512007)(6486002)(86362001)(6916009)(478600001)(66556008)(66946007)(66476007)(4326008)(8676002)(2906002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Ne/3cN7RMnIm9c/rMhzsrOnePiP1?= =?utf-8?q?TV4NbvrIeIJJs1IaxFp+bWJgo5IWNb8uZlJs2dGPgGwBGXZ5wprYDNJ8xPNrF4+rv?= =?utf-8?q?Mhg9T71mIbkbwdAB7ZN3MhuzOlz5a7K/TxkmwuJ1OS7mrBQgOcp1sJCxHj7G+Mh0R?= =?utf-8?q?bM9EhYnWCG5EeLiPY5SdWsZ+D4UFbjPl/EbhKmV3PvhrqM4BXdZ4YXdeE9fLSr/hg?= =?utf-8?q?yeS3X5cSh6x9ff7/cTsky9eWzwOV8l7nvPCzaxe4tOnYeV8FZTTvndUnPpQY9ueV7?= =?utf-8?q?1GIWLJTyB+HMrMgJvGp7zYwsGow5OZ+QgEd928frKyTaKxT3/Bjc9D2pQHD3ocOCE?= =?utf-8?q?2k8y/74SfY7NOLBGrG24WXHjKv1QX9d+1OH1OpXSLG88D5JjalgT+2CBAVEWy0PNy?= =?utf-8?q?WigO2PBT3DpHvvwPv4LFl7zloqMOJh4OPIjP4aJak4k4u9ZAM9rlTaZL/tib6S27G?= =?utf-8?q?jZMttUtNBKIqDqAVHHuUZfbYJJ37B71bfFasr2irOCYM4Tf43o4aWc0lUGPY8gOLu?= =?utf-8?q?w5kQCT844/zPztHOEoVB/c2nGI9CWwLCxJkiYkhlt58bD8RvnDcYf1r/6D8YKeVfo?= =?utf-8?q?ZXJQAr5sEbnPaoUZUD8gwRqbtojpFgRsW5ztsxyV5JluzvvU5dunX/HXBNWRJAi21?= =?utf-8?q?YUAA3prIQPoZd8wzWzadRkvdVkBlnRc66/K16MvwF+iJZ0+xbS5YC4/1gjD88L3Wl?= =?utf-8?q?B2rC5dqE78+g3HXXIR+Sy2jBqUbcmtadQEhwV/Wd/Ou1nqsRDlVZnVTzCNxbTqP8h?= =?utf-8?q?COpxyxPvPBhqPLsv58fbmJ3XllN4Mxl+0OYKKSrB5YT9E/x1WQzXr9e4Qq4rX58rN?= =?utf-8?q?zk+tvn+qTXpJOmFp96tVj+B6smyPzbWqojlZLJbntxNy2UwGhWkgl3mtLbVehyLef?= =?utf-8?q?4b+L1VT7E3f+CC64wqSRWG1hOsKxM20mxl89/OQlfTJSPASGHe8Z6tk8vS1rJc+kX?= =?utf-8?q?8FcxHTVpn5+Um6iRorBg4anvzs3tkGFjdybv4hTsWxrfCMoZ2e9g17A/joSOpbmhh?= =?utf-8?q?nXlBOOWefZdEV8u4NEES9sDcnfhuklEGWx1Uwgo9r4tqwRgdmo1Q43yfRcCler763?= =?utf-8?q?39ToTbtmStzI0ydEWdRZNge8TMUqyADoNNj4qEk7xnJZ93cV7LFhJ+GhBtomUm9px?= =?utf-8?q?1lmBpDldp89hdHpM+6L9wsw+4S8NcwlLxfgfEcpDPoE0YeA2SHYSBmfbL2lFblrfy?= =?utf-8?q?QWPlCmeyl+IXjo19AgUEnNd6w8mf0wgvqBqIW/rnLgoTp6o4nkOTQ4+f/Wh28anQQ?= =?utf-8?q?qFAPNPndqHACPn8Pt8tmp/15FJAhR8BEVCotbY8Ee3TVSUbEGsmgxYesSmaufMz8+?= =?utf-8?q?+PyDzGb+TMtQ5XAdm5SYkQE9OWnzoYxKBFhtH2MqxWKTohUVBqg3DZyhOaceh2g4M?= =?utf-8?q?nIaCzDUX53yzQ3C7I/M+0UNA9PljgaAAWERiDT2j8bI9ywhMHN61AV8gNYYh+tGrk?= =?utf-8?q?w+eg8Y9740WNfZjrcz6q1N0yuZXjg56ZLx7+wdB2U2hSHrTHNXVFWjXfoiNgkjJTX?= =?utf-8?q?HiVE2kfS9klI?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Ny8H5Y4N8Uh6hpxEvP8I6cKCE5uFpwZ2saP/XSLZZCW8HrJGBaxm+RDRziEq9uipmAKToreSuQrDCzbu0Mlpn+Qg7ZpN698tkNSKd7ZOE0DXMNOQpyb7rc2oqykRDAZme79uifKx09cmuyxy1S4i2M66woI/bPCJutXm+pYVEK/z0T7b8EHS1c7vvUDIoc22IzYYzy07+XCq7EVhc8rxxC7iGdZhQkAGzBvtadxehFIT+DYvbcf6e5ZNTNjx5YJF+SL85nN5EdZzeaGRKRqx1bABJG16p7GMqapWP5A5KnkzR09/K2xikIWJGRO2UjxNp1SsTVfS+8KbEi6o6DqVtIdJy88tH4cT4lyNHOeuFJuXpPSE0niOIOe8uttPVtT4QLmp43jufSQB4rLLasFa7XubXQmE7lgwwieQhgpBzXK+6e6oodFQ7Cz3MhNnem1OH6tZLF5VS/2yqmC0+iEZThchtQINWj7QZ/2BAqilYRPOZ4WP6hyx+Q84zGVjHlmsCjblp3C35e8cuqSy7iEBn7WM4i4TgmnHoqpso+6sEWV25OGhzo25hz53x8xn2XiVNOOSTwi8UGIIvYLBGTBJODhFM6coZ8HeMkBYPmxzIsc6ZdCl7WVSuN2tSGMraqoLyZ6/xcU367Vx1cta9gAulbSzZknW/RLlocF1qik/2350k4R98U671QUnUBUsGbA6TXQc1a/aNHUqmJQyNJP6N1VvO3HLx5AxWAyMNw7JB4is8tooEwLnGq7F9xAQK66owWnfsK8vQyVkuwDXDb3ufQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac77739c-fd4a-4441-b95d-08db1135f9e9 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2023 22:26:12.8246 (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: 9Qu1Yyusy4+IrlyTlN3oRccew7yFT7oLHZb9V8reGyAWbasDRgB8RqPtneQjF/5dwHWGTyIf0Ktn23mEvHmHJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4834 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-17_15,2023-02-17_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302170195 X-Proofpoint-GUID: xS-NaDt4tQ46TVT9XBzn5mChk6il3CI0 X-Proofpoint-ORIG-GUID: xS-NaDt4tQ46TVT9XBzn5mChk6il3CI0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Qing Zhao <qing.zhao@oracle.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758118883913405639?= X-GMAIL-MSGID: =?utf-8?q?1758118883913405639?= |
Series |
Fixing PR107411
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Qing Zhao
Feb. 17, 2023, 10:26 p.m. UTC
This is a bug in tree-ssa-uninit.cc. When doing the following: /* Ignore the call to .DEFERRED_INIT that define the original var itself as the following case: temp = .DEFERRED_INIT (4, 2, “alt_reloc"); alt_reloc = temp; In order to avoid generating warning for the fake usage at alt_reloc = temp. */ We need to compare the var name inside the .DEFERRED_INIT call (the 3rd argument) and the name for the LHS variable. if they are the same, we will NOT report the warning. There is one issue when we get the name for the LHS variable. when the variable doesn't have a DECL_NAME (it's not a user declared variable, which is the case for this bug): _1 = .DEFERRED_INIT (4, 2, &"D.2389"[0]); D.2389 = _1; The current checking just ignores this case, and still report the warning. The fix is very simple, when getting the name for the LHS variable, we should consider this case and come up with the name the same way as we construct the 3rd argument for the call to .DEFERRED_INIT (please refer to the routine "gimple_add_init_for_auto_var") The patch has been bootstrapped and regression tested on both x86 and aarch64. Okay for committing? thanks. Qing PR middle-end/107411 gcc/ChangeLog: PR middle-end/107411 * tree-ssa-uninit.cc (warn_uninit): Handle the case when the LHS varaible of a .DEFERRED_INIT call doesn't have a DECL_NAME. gcc/testsuite/ChangeLog: PR middle-end/107411 * g++.dg/pr107411.C: New test. --- gcc/testsuite/g++.dg/pr107411.C | 10 ++++++++++ gcc/tree-ssa-uninit.cc | 27 ++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr107411.C
Comments
On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote: > + else if (!DECL_NAME (lhs_var)) > + { > + char *lhs_var_name_str > + = xasprintf ("D.%u", DECL_UID (lhs_var)); Why xasprintf? D.%u can be sprintfed into a fixed size automatic buffer, say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size of the buffer. Then you don't need to free it... > + if (strcmp (lhs_var_name_str, var_name_str) == 0) > + { > + free (lhs_var_name_str); > + return; > + } > + free (lhs_var_name_str); > + } > + } > gcc_assert (var_name_str && var_def_stmt); > } > } > -- > 2.31.1 Jakub
> On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <jakub@redhat.com> wrote: > > On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote: >> + else if (!DECL_NAME (lhs_var)) >> + { >> + char *lhs_var_name_str >> + = xasprintf ("D.%u", DECL_UID (lhs_var)); > > Why xasprintf? Just emulated the code in “gimple_add_init_for_auto_var” without thinking too much. -:) > D.%u can be sprintfed into a fixed size automatic buffer, > say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size > of the buffer. Then you don't need to free it... xasprintf is "like a sprintf but provided a pointer to malloc’d storage (without fail)”. If free the pointer properly, then it should be okay, right? In addition to “no need to free”, what other benefit to use sprintf other than xasprintf? Qing > >> + if (strcmp (lhs_var_name_str, var_name_str) == 0) >> + { >> + free (lhs_var_name_str); >> + return; >> + } >> + free (lhs_var_name_str); >> + } >> + } >> gcc_assert (var_name_str && var_def_stmt); >> } >> } >> -- >> 2.31.1 > > Jakub
On Mon, Feb 20, 2023 at 03:04:51PM +0000, Qing Zhao via Gcc-patches wrote: > > > > On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <jakub@redhat.com> wrote: > > > > On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote: > >> + else if (!DECL_NAME (lhs_var)) > >> + { > >> + char *lhs_var_name_str > >> + = xasprintf ("D.%u", DECL_UID (lhs_var)); > > > > Why xasprintf? > > Just emulated the code in “gimple_add_init_for_auto_var” without thinking too much. -:) > > D.%u can be sprintfed into a fixed size automatic buffer, > > say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size > > of the buffer. Then you don't need to free it... > > xasprintf is "like a sprintf but provided a pointer to malloc’d storage (without fail)”. If free the pointer properly, then it should be okay, right? > In addition to “no need to free”, what other benefit to use sprintf other than xasprintf? xasprintf+free being significantly slower, exactly because it needs to malloc and free later, where both are fairly expensive functions. The glibc asprintf for short strings like the above uses a ~ 200 byte static buffer, stores in there, later mallocs the needed amount of memory and copies it there (so again, another waste because the string needs to be copied around), while for longer it can do perhaps many allocations and realloc at the end to the right size. The libiberty function actually performs the printing twice, once without writing result anywhere to compute size, then malloc, then again into the malloced buffer. Jakub
> On Feb 20, 2023, at 10:17 AM, Jakub Jelinek <jakub@redhat.com> wrote: > > On Mon, Feb 20, 2023 at 03:04:51PM +0000, Qing Zhao via Gcc-patches wrote: >> >> >>> On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <jakub@redhat.com> wrote: >>> >>> On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote: >>>> + else if (!DECL_NAME (lhs_var)) >>>> + { >>>> + char *lhs_var_name_str >>>> + = xasprintf ("D.%u", DECL_UID (lhs_var)); >>> >>> Why xasprintf? >> >> Just emulated the code in “gimple_add_init_for_auto_var” without thinking too much. -:) >>> D.%u can be sprintfed into a fixed size automatic buffer, >>> say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size >>> of the buffer. Then you don't need to free it... >> >> xasprintf is "like a sprintf but provided a pointer to malloc’d storage (without fail)”. If free the pointer properly, then it should be okay, right? >> In addition to “no need to free”, what other benefit to use sprintf other than xasprintf? > > xasprintf+free being significantly slower, exactly because it needs to > malloc and free later, where both are fairly expensive functions. > The glibc asprintf for short strings like the above uses a ~ 200 byte > static buffer, stores in there, later mallocs the needed amount of memory > and copies it there (so again, another waste because the string needs to be > copied around), while for longer it can do perhaps many allocations and > realloc at the end to the right size. > The libiberty function actually performs the printing twice, once without > writing result anywhere to compute size, then malloc, then again into the > malloced buffer. Okay, thanks a lot for the info. I will replace xasprintf with sprintf for this patch. Qing > > Jakub >
diff --git a/gcc/testsuite/g++.dg/pr107411.C b/gcc/testsuite/g++.dg/pr107411.C new file mode 100644 index 00000000000..7eefecae4f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr107411.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-Werror=uninitialized -ftrivial-auto-var-init=zero" } */ +int t(); +void f(int); + +void j() +{ + const int& e = t(); + f(e); +} diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index c555cf5cd50..b4218900f66 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -224,8 +224,6 @@ warn_uninit (opt_code opt, tree t, tree var, gimple *context, at alt_reloc = temp. */ tree lhs_var = NULL_TREE; - tree lhs_var_name = NULL_TREE; - const char *lhs_var_name_str = NULL; /* Get the variable name from the 3rd argument of call. */ tree var_name = gimple_call_arg (var_def_stmt, 2); @@ -239,11 +237,26 @@ warn_uninit (opt_code opt, tree t, tree var, gimple *context, else if (TREE_CODE (gimple_assign_lhs (context)) == SSA_NAME) lhs_var = SSA_NAME_VAR (gimple_assign_lhs (context)); } - if (lhs_var - && (lhs_var_name = DECL_NAME (lhs_var)) - && (lhs_var_name_str = IDENTIFIER_POINTER (lhs_var_name)) - && (strcmp (lhs_var_name_str, var_name_str) == 0)) - return; + if (lhs_var) + { + /* Get the name string for the LHS_VAR. + Refer to routine gimple_add_init_for_auto_var. */ + if (DECL_NAME (lhs_var) + && (strcmp (IDENTIFIER_POINTER (DECL_NAME (lhs_var)), + var_name_str) == 0)) + return; + else if (!DECL_NAME (lhs_var)) + { + char *lhs_var_name_str + = xasprintf ("D.%u", DECL_UID (lhs_var)); + if (strcmp (lhs_var_name_str, var_name_str) == 0) + { + free (lhs_var_name_str); + return; + } + free (lhs_var_name_str); + } + } gcc_assert (var_name_str && var_def_stmt); } }