From patchwork Wed Jul 24 22:18:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1964554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=J3j86a2p; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WTpMl63QSz1ybY for ; Thu, 25 Jul 2024 08:19:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7744F385C6CF for ; Wed, 24 Jul 2024 22:19:10 +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 ESMTP id 99666385AC29 for ; Wed, 24 Jul 2024 22:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99666385AC29 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 99666385AC29 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=1721859521; cv=none; b=cgOIFVUIyhb9oOk5MtxMxvsEJq0hFmCEnV/e4N1HpafsbPdy/vTPjBHCJFgC6mrfqXr21FNewC/clvjrq7zJoG/QR8pFB6WDdmTASjTO4TxN94Q1AgohYBfsbQqVutoArJ3T7wWup2JAZxul1FhNVhtJEWXuRWueY93qApa2dno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721859521; c=relaxed/simple; bh=rkHo+wze58PZR6EQEVJnQvCDG9tq4Hww+mmQvLkKvXA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=AkDIp1May/xytwYiu8E/jhTZb8MxKYi99n6Egqu9M8MiO0HPnFH31lWAx8boghn7EvbX9reumlE0baBIVcyY2w/IPX83tncG5SvSNrqknPdLS0pFboawoLKcfakEVv7nWI8+Fz7hWOmT2XwkFPEfBRoGZnQ/kovICQC4oKLXK+o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721859518; 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=0yhvAoE4YvZjTVVHpKeDnfMgzyoALKcpjCUEl66xKe0=; b=J3j86a2poGxwTfD+fzu3ul7bNE8LUrlYimGFrgvv2ExvqziAUcpifDvlrfzVUVAbSvE3Gp a6DIMAsclu2S8XepxsEXQ0NfYPV15Ddu03Tc5467x7N5rm2wTR8tXq/zB92cksyGx5pK29 mF2CPqvtztNnolCyZOdaQOooAYUUX50= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-y9QjMNcKPty9NoOy4qlnJQ-1; Wed, 24 Jul 2024 18:18:37 -0400 X-MC-Unique: y9QjMNcKPty9NoOy4qlnJQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22DA91955D54 for ; Wed, 24 Jul 2024 22:18:35 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.33.183]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CAFA61955F40; Wed, 24 Jul 2024 22:18:27 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed 00/16] Revamp of JSON/SARIF output Date: Wed, 24 Jul 2024 18:18:08 -0400 Message-Id: <20240724221824.585054-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 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~incoming=patchwork.ozlabs.org@gcc.gnu.org The following patch kit overhauls various aspects of JSON/SARIF output: * patch 1: adds a simpler json::value::dump () method to make it easier to debug JSON-handling code * patches 2-9 are cleanups/refactorings of the json-handling code and the JSON/SARIF output formats with no functional change intended. Among other things, they make it more type-safe (useful when enforcing a schema), and use std::unique_ptr in many places to indicate ownership. * patches 10-16: add new functionality to our SARIF output whilst building out selftest coverage for it. See the individual patches for more details. Lightly tested with valgrind. Successfully bootstrapped with GCC 4.8.5 on powerpc64le-unknown-linux-gnu (cfarm135). 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 r15-2278-g6baa26c3d6ceec through r15-2293-g142003df61b45b. David Malcolm (16): json: add dump overload for easier debugging json: add array::append_string analyzer: reduce use of naked "new" for json dumps gcov: reduce use of naked "new" for json output diagnostics: SARIF output: add sarif_object subclasses throughout diagnostics: output formats: use references for non-null pointers json: support std::unique_ptr in array::append and object::set diagnostics: SARIF output: use std::unique_ptr throughout diagnostics: JSON output: use std::unique_ptr throughout diagnostics: SARIF output: potentially add escaped renderings of source (§3.3.4) diagnostics: SARIF output: add "workingDirectory" property (§3.20.19) diagnostics: SARIF output: add "arguments" property (§3.20.2) diagnostics: SARIF output: add "{start,end}TimeUtc" properties (§§3.20.7-8) diagnostics: SARIF output: add "annotations" property (§3.28.6) diagnostics: add selftests for SARIF output diagnostics: SARIF output: tweak output for UNKNOWN_LOCATION gcc/Makefile.in | 1 + gcc/analyzer/call-string.cc | 9 +- gcc/analyzer/checker-event.cc | 5 +- gcc/analyzer/constraint-manager.cc | 12 +- gcc/analyzer/diagnostic-manager.cc | 14 +- gcc/analyzer/engine.cc | 13 +- gcc/analyzer/program-point.cc | 11 +- gcc/analyzer/program-state.cc | 2 +- gcc/analyzer/sm.cc | 2 +- gcc/analyzer/store.cc | 6 +- gcc/analyzer/supergraph.cc | 21 +- gcc/diagnostic-format-json.cc | 167 +- gcc/diagnostic-format-sarif.cc | 1738 ++++++++++++----- gcc/diagnostic-format-sarif.h | 9 +- gcc/diagnostic-show-locus.cc | 98 +- gcc/diagnostic.cc | 19 +- gcc/diagnostic.h | 25 +- gcc/dumpfile.cc | 1 + gcc/gcc-rich-location.h | 17 - gcc/gcc.cc | 3 +- gcc/gcov.cc | 5 +- gcc/jit/jit-playback.cc | 6 +- gcc/json.cc | 36 +- gcc/json.h | 45 + gcc/optinfo-emit-json.cc | 5 +- gcc/optinfo.cc | 1 + gcc/opts.cc | 3 +- gcc/selftest-diagnostic-show-locus.h | 82 + gcc/selftest-diagnostic.cc | 14 + gcc/selftest-diagnostic.h | 10 + gcc/selftest-json.cc | 163 ++ gcc/selftest-json.h | 141 ++ gcc/selftest-run-tests.cc | 1 + gcc/selftest.h | 1 + .../diagnostic-format-sarif-file-1.c | 11 + ...diagnostic-format-sarif-file-Wbidi-chars.c | 17 + .../diagnostic_plugin_test_show_locus.c | 1 + gcc/text-range-label.h | 42 + gcc/timevar.cc | 1 + gcc/toplev.cc | 14 +- gcc/tree-diagnostic-client-data-hooks.cc | 1 + gcc/unique-argv.h | 67 + libcpp/include/rich-location.h | 31 +- libcpp/line-map.cc | 28 + 44 files changed, 2179 insertions(+), 720 deletions(-) create mode 100644 gcc/selftest-diagnostic-show-locus.h create mode 100644 gcc/selftest-json.cc create mode 100644 gcc/selftest-json.h create mode 100644 gcc/text-range-label.h create mode 100644 gcc/unique-argv.h