From patchwork Tue Jan 30 13:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 194175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1220031dyb; Tue, 30 Jan 2024 05:32:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHC9NWgO0/iu2N73mkwUMV4ZmtQN3Lb0i5hH56uSyL/6BJ6L4W9ELGwiAvi2VjrhHEQlzKL X-Received: by 2002:a05:620a:8cc:b0:781:5fbf:eeb4 with SMTP id z12-20020a05620a08cc00b007815fbfeeb4mr7163601qkz.37.1706621537076; Tue, 30 Jan 2024 05:32:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706621537; cv=pass; d=google.com; s=arc-20160816; b=J7HAcuEK6+K3jiDGdn8fNxi7+dTjfi5wY/FvO3A3Ddedt/HCgK/oLf/rIYRuIOYp3n B1XFIzLw7jhAbIcNrqUdPz/Op7GidRuVYsUmdA4+5xhi58qsqzaxl+RRFoP30k83vPVO y77J6d8AZKYwkPYixBzOecVuJ4wN2jgnsTlZOcbGEBF7QFQl0aDVq1FGPg98NXp9gaCF XAGmRZxckBj9LLuFEzX5rI++cLnKhzZxkiq/nHs+JsxxxVMuL5/aSTOyuLNR7v33croY KCZ8EGacrtTs3p2+ty+IGyVGSXQVsBFHvIEZDxNjXy68d7dGsMbZkKX7WAM8cLPxVl7v Kaag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=3xwrLZ+jHOkj/8/ju1UwWaKnaKOIujiVgNKpKE+YXvY=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=HH0+laOvS6X9qx9xyBrTkrF7G6bVDwlrmTkDgdWnRmlb5EJdfHgqNEDQFna4c86kRw x7/ApPltf+xkNfvKM0M7FJFU1a8r0wD4oKnvRExcAJx31/vh+53YBxKBCrMK6ZITKXGP nKsuPgRlXhdC5bOYt17dczRf+g5NGGHSEiKpxZPKIzbL5XFekJSElQp8vvH5Bw7ubOx9 0XNEvCoB/FKkOeQR+W+KeA/OkoquqJnd7hzsmrG69qfkMlyybm/jdYGiRlHA20p/1gTb HYC+mIRkoL7npsKzBGyN+BcqsON/BEUiThKzekGMd5s8I1NCGIYAmZTzrHFkXBnnH/4e r4bw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LK6Iam0W; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o5-20020a05620a2a0500b00783c5dcda57si1329248qkp.76.2024.01.30.05.32.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 05:32:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LK6Iam0W; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1C5F385828F for ; Tue, 30 Jan 2024 13:32:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 169D5385828F for ; Tue, 30 Jan 2024 13:31:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 169D5385828F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 169D5385828F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706621484; cv=none; b=LkOdwtQVuTrDTFD1N7rjzAhx2Q5AuLc8hM4tTm5kYZPt4M/9OGcNSl3yaKat/lraDQ1glIDEqJIF4FIHLT91ZuVnp51mUuNXlX7xVf5uTSBDiKHx6jj+EpOoAuni+o5XifvWHnodD5HinxxkiTq1juCITWCzJCmPdOv4y2c9Wvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706621484; c=relaxed/simple; bh=9O/CGPEa2M8yfpLXKDv0uuy18Rue/9/Sz4uKYtSW7B4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=SloQ/xZ8uTgCEDoUWfTD7Tf3zfyKdhSOOQkzlLiUl/laeUwUvzRsZzD/CAde9MrVa4wOV/XZCou5kgsy3wnqpvMMDHCDsnJQbunfSnJZeWGxWOQw0L00Ghn2fF7usmlGJkIdUAujwh9xX1gFbOGdpnpWRG9qKmJdhTZYghUAMhQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706621482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3xwrLZ+jHOkj/8/ju1UwWaKnaKOIujiVgNKpKE+YXvY=; b=LK6Iam0Wm6daCGWoBL0x74OPdj+G1mGMTclwWpQPHEjqMu5zutEqo4hHh3KY1smWfEZjus Iw4+FHxDRZzC2uD1W9thZ/kjKa67/lhBWHSmk0lAhNIs9wnKfgQ2FXvjCqMqbHS88f4b00 2WxzrouRLNzf9Rh57PlR/oj0DjWJ1TQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-fRx2JG9zP9uPLFZP3LhH9Q-1; Tue, 30 Jan 2024 08:31:21 -0500 X-MC-Unique: fRx2JG9zP9uPLFZP3LhH9Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id E29CA383008A for ; Tue, 30 Jan 2024 13:31:20 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.32.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id B80832B7; Tue, 30 Jan 2024 13:31:20 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: add SARIF property bag to -Wanalyzer-allocation-size Date: Tue, 30 Jan 2024 08:31:19 -0500 Message-Id: <20240130133119.1875785-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789522384783493458 X-GMAIL-MSGID: 1789522384783493458 This is useful for debugging the analyzer. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Successful run of analyzer integration tests on x86_64-pc-linux-gnu. Pushed to trunk as r14-8626-g181f753dc4afa9. gcc/analyzer/ChangeLog: * region-model.cc (dubious_allocation_size::dubious_allocation_size): Add "capacity_sval" param. Drop unused ctor. (dubious_allocation_size::maybe_add_sarif_properties): New. (dubious_allocation_size::m_capacity_sval): New field. (region_model::check_region_size): Pass capacity svalue to dubious_allocation_size ctor. Signed-off-by: David Malcolm --- gcc/analyzer/region-model.cc | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index dbb2149dbd46..ba82f46c1887 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -3113,16 +3113,15 @@ class dubious_allocation_size { public: dubious_allocation_size (const region *lhs, const region *rhs, + const svalue *capacity_sval, tree expr, const gimple *stmt) - : m_lhs (lhs), m_rhs (rhs), m_expr (NULL_TREE), m_stmt (stmt), + : m_lhs (lhs), m_rhs (rhs), + m_capacity_sval (capacity_sval), m_expr (expr), + m_stmt (stmt), m_has_allocation_event (false) - {} - - dubious_allocation_size (const region *lhs, const region *rhs, - tree expr, const gimple *stmt) - : m_lhs (lhs), m_rhs (rhs), m_expr (expr), m_stmt (stmt), - m_has_allocation_event (false) - {} + { + gcc_assert (m_capacity_sval); + } const char *get_kind () const final override { @@ -3196,9 +3195,21 @@ public: interest->add_region_creation (m_rhs); } + void maybe_add_sarif_properties (sarif_object &result_obj) + const final override + { + sarif_property_bag &props = result_obj.get_or_create_properties (); +#define PROPERTY_PREFIX "gcc/analyzer/dubious_allocation_size/" + props.set (PROPERTY_PREFIX "lhs", m_lhs->to_json ()); + props.set (PROPERTY_PREFIX "rhs", m_rhs->to_json ()); + props.set (PROPERTY_PREFIX "capacity_sval", m_capacity_sval->to_json ()); +#undef PROPERTY_PREFIX + } + private: const region *m_lhs; const region *m_rhs; + const svalue *m_capacity_sval; const tree m_expr; const gimple *m_stmt; bool m_has_allocation_event; @@ -3437,7 +3448,7 @@ region_model::check_region_size (const region *lhs_reg, const svalue *rhs_sval, && !capacity_compatible_with_type (cst_cap, pointee_size_tree, is_struct)) ctxt->warn (make_unique (lhs_reg, rhs_reg, - cst_cap, + capacity, cst_cap, ctxt->get_stmt ())); } break; @@ -3451,7 +3462,7 @@ region_model::check_region_size (const region *lhs_reg, const svalue *rhs_sval, tree expr = get_representative_tree (capacity); ctxt->warn (make_unique (lhs_reg, rhs_reg, - expr, + capacity, expr, ctxt->get_stmt ())); } }