From patchwork Fri Jan 6 11:33:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 62797 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 4DE853857B98 for ; Fri, 6 Jan 2023 11:34:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E006C3858D28 for ; Fri, 6 Jan 2023 11:33:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E006C3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B10B0250B9; Fri, 6 Jan 2023 11:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673004834; h=from:from:reply-to: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=X5sZf1Ab2IigYpyrf/3tZmjBCO1i7g1ukxJrrb5LNLg=; b=zExKpaMtkuz4S565ncNJIWw8w8ThAt067t4/P0DinqGHnWme7FywaV4T84TK//johaVZg2 7Aekg4EczoCX/q3sxoBJ9fLUnsVeyGX5M4KfXDtIlsVh8s+kZLtzzbM0CVhQ1L6vYMlQ7E w+bWMDX8P74PqQTk7r6QK5NjKp/sqZ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673004834; h=from:from:reply-to: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=X5sZf1Ab2IigYpyrf/3tZmjBCO1i7g1ukxJrrb5LNLg=; b=F07UyotxywjnqKZmqRVjwi5JReHyjq4uB6msZXoDfq3OZjvLvMtB7i6cXiGp2r2HivonLF aOPfGqKD8bH0h7Cw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8E71B13596; Fri, 6 Jan 2023 11:33:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EW28ICIHuGPqJQAAMHmgww (envelope-from ); Fri, 06 Jan 2023 11:33:54 +0000 Message-ID: <60f9fd2b-211e-c1d5-e17a-1fab1ee51338@suse.cz> Date: Fri, 6 Jan 2023 12:33:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] diagnostics: fix crash with -fdiagnostics-format=json-file To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: David Malcolm X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR middle-end/106133 gcc/ChangeLog: * diagnostic.cc (diagnostic_output_format_init): If -fdiagnostics-format=json-file and -E is used, then base_file_name is null and we should not emit anything. --- gcc/diagnostic.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index c90c14e993e..fe7d121e340 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -2277,6 +2277,9 @@ diagnostic_output_format_init (diagnostic_context *context, const char *base_file_name, enum diagnostics_output_format format) { + if (base_file_name == NULL) + return; + switch (format) { default: