From patchwork Tue Apr 9 11:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= X-Patchwork-Id: 88234 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 322CE3858294 for ; Tue, 9 Apr 2024 11:44:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) by sourceware.org (Postfix) with ESMTPS id B106A3858C39 for ; Tue, 9 Apr 2024 11:43:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B106A3858C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B106A3858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.103.80.155 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712663019; cv=none; b=PSLIVwgPztuF+6uevMhk4Bcj3O2IX5tODD+6ajQK9MvSGgKKL5ShmkKlmihyQH+ej2efI1QQ1CZ8/GrrwpXfpCH3z9qtcD+zgCUmSqtAkHTJ3sbvaZTcGmk7xK7WIcyNbwoJXC4qssseQv4wYd52AsH5zulFWKrS75+vVNBEtHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712663019; c=relaxed/simple; bh=oBXIJeeFEjbR+rQrHjYkqukqqwar5AC6sImrzhLvxRo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=eqCBytoyVfI3E/8FdV6O0SCveyIsWlF/ewoO8ngXATGwfQAydtJdl+lmcCWSmWPRSwDgDe74lUF1XYnIIVm87QYt60VuOqa6YjHljgRYU4q4sO8FdGIUG1HV8IMfjoe44eqdkylKG5D/YpEgAaEy+4aF8lyvl9y/uJIuEZHEJAg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 999DA2096DD7; Tue, 9 Apr 2024 13:43:35 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:mime-version:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20160331; t=1712663012; x=1714477413; bh=nDEcNFtqleSwqdUPBxg UPTgBQWyGI4CUYzz1MVQd5T0=; b=gyMXC2ViFyAcen3yWy0rzsvt7+WPj6znRnl ncL8DKVO9hDAxyL8WD89DyhwaLo7NU4SPK/26Kzcwg/77EiQvRi9m0bn757ftkEJ VkOUnLvlBfwlkni1pczRY4u+XevdYXR85MyT1whrcTVn3WbgzYFcONkM+B04t7dk +hiuYfK7dtHHbE07wckk1eFQfL9Lj7r5s/PfW7iAK5BaWM/vaCBw4NmElKzQSfAV vu6UQ46Jhz7iOUfWvMSSEMwKout/D85pZ8b627SnjmNNSNEayGSSHb78cyuPfj/y OcMVqpMa/A//zj883ILYtPf7u4vsmdUzeVtPGUWxv00A2zPMygF75KehW5uwb/Lp NADdJ5kbVZ12/2dKM0gPChvP9mPXPJWZg4AgZ8qfSJ7HfXHhOnn0YDktzJyp004n ZnSKXV33kVl5Fp/YEHcZjfrnC/08AhHosWSDQddF7sBGDRMhjQZK60PS/DjBtVOn Qq0N0Jv4Ij9omhLrN5UG6SMvEVxnlHpOgYsf2qJLXFc6Gmt4w0fXyCRqDEGj5L3I +V0CJuoQ+Bu7Gx/cDAVr5011+I5ez7Jig7Bhv0O8gozjFfS7K5dAkepaMS5zvi/f FftRAZ0JI865CYkaeyji1F6UKNBFqsGTkc+h7PrratilL8sa8nHo7gbz/76E2xY8 QKf52Lv8= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id Jc7CixQk9HE1; Tue, 9 Apr 2024 13:43:32 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 794082096DD3; Tue, 9 Apr 2024 13:43:32 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 11177211B0D7; Tue, 9 Apr 2024 13:43:32 +0200 (CEST) From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, hubicka@ucw.cz, zsojka@seznam.cz, =?utf-8?q?J=C3=B8rg?= =?utf-8?q?en_Kvalsvik?= Subject: [PATCH] Guard function->cond_uids access [PR114601] Date: Tue, 9 Apr 2024 13:43:15 +0200 Message-Id: <20240409114315.356573-1-j@lambda.is> MIME-Version: 1.0 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 PR114601 shows that it is possible to reach the condition_uid lookup without having also created the fn->cond_uids, through compiler-generated conditionals. Consider all lookups on non-existing maps misses, which they are from the perspective of the source code, to avoid the NULL access. PR gcov-profile/114601 gcc/ChangeLog: * tree-profile.cc (condition_uid): Guard fn->cond_uids access. gcc/testsuite/ChangeLog: * gcc.misc-tests/gcov-pr114601.c: New test. --- gcc/testsuite/gcc.misc-tests/gcov-pr114601.c | 11 +++++++++++ gcc/tree-profile.cc | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-pr114601.c diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr114601.c b/gcc/testsuite/gcc.misc-tests/gcov-pr114601.c new file mode 100644 index 00000000000..72248c8fd25 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-pr114601.c @@ -0,0 +1,11 @@ +/* PR gcov-profile/114601 */ +/* { dg-do compile } */ +/* { dg-options "-fcondition-coverage -finstrument-functions-once" } */ + +/* -finstrument-functions-once inserts a hidden conditional expression into + this function which otherwise has none. This caused a crash on looking up + the condition as the cond->expr map is not created unless it necessary. */ +void +empty (void) +{ +} diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index b85111624fe..b87c121790c 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -359,12 +359,17 @@ condition_index (unsigned flag) min-max, etc., which leaves ghost identifiers in basic blocks that do not end with a conditional jump. They are not really meaningful for condition coverage anymore, but since coverage is unreliable under optimization anyway - this is not a big problem. */ + this is not a big problem. + + The cond_uids map in FN cannot be expected to exist. It will only be + created if it is needed, and a function may have gconds even though there + are none in source. This can be seen in PR gcov-profile/114601, when + -finstrument-functions-once is used and the function has no conditions. */ unsigned condition_uid (struct function *fn, basic_block b) { gimple *stmt = gsi_stmt (gsi_last_bb (b)); - if (!safe_is_a (stmt)) + if (!safe_is_a (stmt) || !fn->cond_uids) return 0; unsigned *v = fn->cond_uids->get (as_a (stmt));