From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 53EFB384AB69 for ; Wed, 10 Apr 2024 20:56:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53EFB384AB69 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 53EFB384AB69 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=1712782581; cv=none; b=jsjEtPmL6iOyN/RnBHMNTCvg1+ToIsowzx06vMRZoMT4DjK4uCpyJVZASjus0auiIUj0noMdyfp+e8g4TMnLakK4jqYcjoLlj50lVSPrjSTp0IowlvNXNmsePj5xmEmFfUxK5AhMefLT/9r2LNo4R3tKVnu1GPzgd20iAq6ERWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712782581; c=relaxed/simple; bh=0r4mKl6aNLINPi280vdxWDKPCX+t7ZhKwj/CC9sFTk8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=CC1fKNpDk6Pt4b4Zz0TBv701yy/44GPMpB2+1Fx92EUab3hVXfW7eYod05Oi0vuNoM8EvhnK0dl4SGmT11wIS1+dJINJFjv29u/Bzv5HrwhgZgeu263lSSD5ngrXMYZoD8eoOw9VDa39bM8+4gVu36B3ggVKbdKpJpu5JVBn/Ss= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712782571; 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=TFzuhFn4OZREWlFli4I4ci8EmYGSuwOFYA9umaaVoMI=; b=bsuj+9SrXUuADIt54xzibLu+ysRTD+JIreZ9WWDq17GTO14tfhiAb1KQ3v1a0Vlcrck5D8 tFkCijUI25sr7+dfDGVwMq0BrFZdVgdRdXe3lotnvJe9uZD0loXafe1hXC9MEmlGv1XLcX LmHNWVWBkg6VXgCr0XNB7dhU3iK/kpU= 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-98-0uUq9yQoOEizIfBsybgEtw-1; Wed, 10 Apr 2024 16:56:09 -0400 X-MC-Unique: 0uUq9yQoOEizIfBsybgEtw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 DEFE83C1E9C1 for ; Wed, 10 Apr 2024 20:56:08 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.33.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5F9A1121306; Wed, 10 Apr 2024 20:56:08 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: add SARIF property bags to -Wanalyzer-overlapping-buffers Date: Wed, 10 Apr 2024 16:56:07 -0400 Message-Id: <20240410205607.335758-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.7 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_H4,RCVD_IN_MSPIKE_WL,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 List-Id: Tested lightly by hand. 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-9899-g7a49d5dc0ef345. gcc/analyzer/ChangeLog: * call-details.cc: Include "diagnostic-format-sarif.h". (overlapping_buffers::overlapping_buffers): Add params for new fields. (overlapping_buffers::maybe_add_sarif_properties): New. (overlapping_buffers::m_byte_range_a): New field. (overlapping_buffers::byte_range_b): New field. (overlapping_buffers::m_num_bytes_read_sval): New field. (call_details::complain_about_overlap): Pass new params to overlapping_buffers ctor. * ranges.cc (symbolic_byte_offset::to_json): New. (symbolic_byte_range::to_json): New. * ranges.h (symbolic_byte_offset::to_json): New decl. (symbolic_byte_range::to_json): New decl. Signed-off-by: David Malcolm --- gcc/analyzer/call-details.cc | 33 ++++++++++++++++++++++++++++++--- gcc/analyzer/ranges.cc | 15 +++++++++++++++ gcc/analyzer/ranges.h | 4 ++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/gcc/analyzer/call-details.cc b/gcc/analyzer/call-details.cc index 5b145a2ce638..ca47953f1461 100644 --- a/gcc/analyzer/call-details.cc +++ b/gcc/analyzer/call-details.cc @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" #include "make-unique.h" +#include "diagnostic-format-sarif.h" #if ENABLE_ANALYZER @@ -425,8 +426,14 @@ class overlapping_buffers : public pending_diagnostic_subclass { public: - overlapping_buffers (tree fndecl) - : m_fndecl (fndecl) + overlapping_buffers (tree fndecl, + const symbolic_byte_range &byte_range_a, + const symbolic_byte_range &byte_range_b, + const svalue *num_bytes_read_sval) + : m_fndecl (fndecl), + m_byte_range_a (byte_range_a), + m_byte_range_b (byte_range_b), + m_num_bytes_read_sval (num_bytes_read_sval) { } @@ -469,8 +476,25 @@ public: m_fndecl); } + 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/overlapping_buffers/" + props.set (PROPERTY_PREFIX "bytes_range_a", + m_byte_range_a.to_json ()); + props.set (PROPERTY_PREFIX "bytes_range_b", + m_byte_range_b.to_json ()); + props.set (PROPERTY_PREFIX "num_bytes_read_sval", + m_num_bytes_read_sval->to_json ()); +#undef PROPERTY_PREFIX + } + private: tree m_fndecl; + symbolic_byte_range m_byte_range_a; + symbolic_byte_range m_byte_range_b; + const svalue *m_num_bytes_read_sval; }; @@ -517,7 +541,10 @@ call_details::complain_about_overlap (unsigned arg_idx_a, if (!byte_range_a.intersection (byte_range_b, *model).is_true ()) return; - ctxt->warn (make_unique (get_fndecl_for_call ())); + ctxt->warn (make_unique (get_fndecl_for_call (), + byte_range_a, + byte_range_b, + num_bytes_read_sval)); } } // namespace ana diff --git a/gcc/analyzer/ranges.cc b/gcc/analyzer/ranges.cc index ffdd0d4c5722..659ada7609d6 100644 --- a/gcc/analyzer/ranges.cc +++ b/gcc/analyzer/ranges.cc @@ -103,6 +103,12 @@ symbolic_byte_offset::dump (bool simple) const pp_flush (&pp); } +json::value * +symbolic_byte_offset::to_json () const +{ + return m_num_bytes_sval->to_json (); +} + tree symbolic_byte_offset::maybe_get_constant () const { @@ -156,6 +162,15 @@ symbolic_byte_range::dump (bool simple, region_model_manager &mgr) const pp_flush (&pp); } +json::value * +symbolic_byte_range::to_json () const +{ + json::object *obj = new json::object (); + obj->set ("start", m_start.to_json ()); + obj->set ("size", m_size.to_json ()); + return obj; +} + bool symbolic_byte_range::empty_p () const { diff --git a/gcc/analyzer/ranges.h b/gcc/analyzer/ranges.h index 92d963b7a2bc..aca4554bde69 100644 --- a/gcc/analyzer/ranges.h +++ b/gcc/analyzer/ranges.h @@ -39,6 +39,8 @@ public: void dump_to_pp (pretty_printer *pp, bool) const; void dump (bool) const; + json::value *to_json () const; + bool operator== (const symbolic_byte_offset &other) const { return m_num_bytes_sval == other.m_num_bytes_sval; @@ -70,6 +72,8 @@ public: region_model_manager &mgr) const; void dump (bool, region_model_manager &mgr) const; + json::value *to_json () const; + bool empty_p () const; symbolic_byte_offset get_start_byte_offset () const -- 2.26.3