From patchwork Fri Jul 22 14:27:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Lange X-Patchwork-Id: 1659608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=tim-lange.me header.i=@tim-lange.me header.a=rsa-sha256 header.s=default2108 header.b=k6CAZ+pB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LqBcf5KZcz9sGq for ; Sat, 23 Jul 2022 00:28:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA9953835417 for ; Fri, 22 Jul 2022 14:28:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from www523.your-server.de (www523.your-server.de [159.69.224.22]) by sourceware.org (Postfix) with ESMTPS id B898A3857C5D for ; Fri, 22 Jul 2022 14:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B898A3857C5D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tim-lange.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tim-lange.me DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tim-lange.me; s=default2108; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=gSRq7gtXQLIl59CvCtYMjhzd/HivQC/dhpHy/Y/6M7c=; b=k6CAZ+pBavZ22+a4MoB8yH+iFa 6h4m3xJAsECsv48IkqGWQc5V2Li1w7lLOGncmm9/3WV6lnyfg3C420i4ukHqYupbeS7zfFGAk2k89 4/+SIpDknnZCCk/RWFd23URKIGLgAMg4qzUdAQW1Wd5PHFxchwSVseGEzPi0YbEEifNVX1euG9/Vp LotAC2L2rBDbajiZTjHjw3aRUxFt8LJ8qvugCbaPz2811DYfaR9Ibn6TVM7W/IIPs6dbw7qMZOjRm d7pS4uSE/a71j1dFNvb7S7j71o3911X5H66Ypt7AGCs97+f1NrI8zK77IFhvPVb2OfviOkeWsYyd8 84lPR2xg==; Received: from sslproxy03.your-server.de ([88.198.220.132]) by www523.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1oEtdD-000G0A-Ht; Fri, 22 Jul 2022 16:27:55 +0200 Received: from [2a02:908:1861:d6a0::f4e2] (helo=fedora..) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEtdD-000INz-Bg; Fri, 22 Jul 2022 16:27:55 +0200 From: Tim Lange To: gcc-patches@gcc.gnu.org, dmalcolm@redhat.com Subject: [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394] Date: Fri, 22 Jul 2022 16:27:07 +0200 Message-Id: <20220722142707.178390-1-mail@tim-lange.me> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Authenticated-Sender: mail@tim-lange.me X-Virus-Scanned: Clear (ClamAV 0.103.6/26609/Fri Jul 22 09:56:47 2022) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, SPF_HELO_NONE, SPF_PASS, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Lange Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch unifies the handling of zero capacity regions for structs and other types in the allocation size checker. Regression-tested on x86_64 Linux. 2022-07-22 Tim Lange gcc/analyzer/ChangeLog: PR analyzer/106394 * region-model.cc (capacity_compatible_with_type): Always return true if alloc_size is zero. gcc/testsuite/ChangeLog: PR analyzer/106394 * gcc.dg/analyzer/pr106394.c: New test. --- gcc/analyzer/region-model.cc | 2 +- gcc/testsuite/gcc.dg/analyzer/pr106394.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr106394.c -- 2.36.1 diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 8b7b4e1f697..e01c30407c4 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -2956,7 +2956,7 @@ capacity_compatible_with_type (tree cst, tree pointee_size_tree, unsigned HOST_WIDE_INT alloc_size = TREE_INT_CST_LOW (cst); if (is_struct) - return alloc_size >= pointee_size; + return alloc_size == 0 || alloc_size >= pointee_size; return alloc_size % pointee_size == 0; } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr106394.c b/gcc/testsuite/gcc.dg/analyzer/pr106394.c new file mode 100644 index 00000000000..96bb175fc14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr106394.c @@ -0,0 +1,19 @@ +struct msm_gpu { + // [...snip...] + const struct msm_gpu_perfcntr *perfcntrs; + // [...snip...] +}; + +struct msm_gpu_perfcntr { + // [...snip...] + const char *name; +}; + +static const struct msm_gpu_perfcntr perfcntrs[] = {}; + +struct msm_gpu *test(struct msm_gpu *gpu) { + // [...snip...] + gpu->perfcntrs = perfcntrs; + // [...snip...] + return gpu; +}