From patchwork Thu Sep 26 21:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1989959 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=NqAJG3Nr; 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 4XF6D759ttz1xst for ; Fri, 27 Sep 2024 07:28:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89C2E3858D29 for ; Thu, 26 Sep 2024 21:28:53 +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 5E28D3858D28 for ; Thu, 26 Sep 2024 21:28:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E28D3858D28 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 5E28D3858D28 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=1727386117; cv=none; b=LIdoG7DDWude0M2ea702A7RUVS0RAtt2FzDcUbzasztTCnpF2s+V3j+jByGQUy8E1dU/w3MRXAgkO9HoDolIOyYycYEknZ1eFOunUngqY5KoyW/WOyVGxSEYfQtCiBjgN6cew3tO5267E8C4FD9vFTLjMGxs4r5rfBO89zkneR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727386117; c=relaxed/simple; bh=403qCpAMTSsMqD0DEw71oXQy4Ct2W1k1CyLEz10Rq9w=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=g5oVcyRtsUsnVIq4ePDnYZ0Y0GhvgTTS76MlSvtlp7AWaRLRq9DKLpeStfMWuKfmsgz5UNO6LvDjKiv7db20oCZLJ27x+9PGP8xXFSbjQt4xn1cEsPsYUEJG3XRxE42x8G0LqL2IpExlYgLal//2u7tRoaZev9Z+INihdyzSIJ8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727386115; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=kIRYqyYGaSFdAfqKnePY83qWocMRxeyqZa3rgLTKSdc=; b=NqAJG3NrB85Rg2xAs83iQLRUD2Gp1RRDoEQTxpeMAP3e8y5dIPNREvsejXL7eyByU5W3jG VYd3uXJeEHm4yfhrFxHK6tPcK9M7wRLuDuJSRThtUC0guP2h4v/haniQH0dwL4NsMVeh/O UQahhaB+YtUC6AiaJr6NJNkeGDRIjnw= Received: from mx-prod-mc-02.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-12-uu-ozar7PeeImj8N3umvyg-1; Thu, 26 Sep 2024 17:28:33 -0400 X-MC-Unique: uu-ozar7PeeImj8N3umvyg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C18DB196E012 for ; Thu, 26 Sep 2024 21:28:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.61]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4E5CA195605A; Thu, 26 Sep 2024 21:28:32 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 48QLSTPw1114226 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 26 Sep 2024 23:28:29 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 48QLSTUR1113722; Thu, 26 Sep 2024 23:28:29 +0200 Date: Thu, 26 Sep 2024 23:28:28 +0200 From: Jakub Jelinek To: David Malcolm , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] diagnostic: Save/restore diagnostic context history and push/pop state for PCH [PR116847] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The following patch on top of the just posted cleanup patch saves/restores the m_classification_history and m_push_list vectors for PCH. Without that as the testcase shows during parsing of the templates we don't report ignored diagnostics, but after loading PCH header when instantiating those templates those warnings can be emitted. This doesn't show up on x86_64-linux build because configure injects there -fcf-protection -mshstk flags during library build (and so also during PCH header creation), but make check doesn't use those flags and so the PCH header is ignored. Bootstrapped on i686-linux so far, bootstrap/regtest on x86_64-linux and i686-linux still pending, ok for trunk if it passes it? 2024-09-26 Jakub Jelinek PR libstdc++/116847 gcc/ * diagnostic.h (diagnostic_option_classifier): Add pch_save and pch_restore method declarations. (diagnostic_context): Add pch_save and pch_restore inline method definitions. * diagnostic.cc (diagnostic_option_classifier::pch_save): New method. (diagnostic_option_classifier::pch_restore): Likewise. gcc/c-family/ * c-pch.cc: Include diagnostic.h. (c_common_write_pch): Call global_dc->pch_save. (c_common_read_pch): Call global_dc->pch_restore. gcc/testsuite/ * g++.dg/pch/pr116847.C: New test. * g++.dg/pch/pr116847.Hs: New test. Jakub --- gcc/diagnostic.h.jj 2024-09-26 15:42:05.696731787 +0200 +++ gcc/diagnostic.h 2024-09-26 17:32:16.419161700 +0200 @@ -256,6 +256,9 @@ public: diagnostic_t update_effective_level_from_pragmas (diagnostic_info *diagnostic) const; + int pch_save (FILE *); + int pch_restore (FILE *); + private: /* Each time a diagnostic's classification is changed with a pragma, we record the change and the location of the change in an array of @@ -551,6 +554,18 @@ public: const char *, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0); + int + pch_save (FILE *f) + { + return m_option_classifier.pch_save (f); + } + + int + pch_restore (FILE *f) + { + return m_option_classifier.pch_restore (f); + } + private: void error_recursion () ATTRIBUTE_NORETURN; --- gcc/diagnostic.cc.jj 2024-09-26 16:11:51.664502977 +0200 +++ gcc/diagnostic.cc 2024-09-26 22:59:05.204135316 +0200 @@ -156,6 +156,46 @@ diagnostic_option_classifier::fini () m_push_list.release (); } +/* Save the diagnostic_option_classifier state to F for PCH + output. Returns 0 on success, -1 on error. */ + +int +diagnostic_option_classifier::pch_save (FILE *f) +{ + unsigned int lengths[2] = { m_classification_history.length (), + m_push_list.length () }; + if (fwrite (lengths, sizeof (lengths), 1, f) != 1 + || fwrite (m_classification_history.address (), + sizeof (diagnostic_classification_change_t), + lengths[0], f) != lengths[0] + || fwrite (m_push_list.address (), sizeof (int), + lengths[1], f) != lengths[1]) + return -1; + return 0; +} + +/* Read the diagnostic_option_classifier state from F for PCH + read. Returns 0 on success, -1 on error. */ + +int +diagnostic_option_classifier::pch_restore (FILE *f) +{ + unsigned int lengths[2]; + if (fread (lengths, sizeof (lengths), 1, f) != 1) + return -1; + gcc_checking_assert (m_classification_history.is_empty ()); + gcc_checking_assert (m_push_list.is_empty ()); + m_classification_history.safe_grow (lengths[0]); + m_push_list.safe_grow (lengths[1]); + if (fread (m_classification_history.address (), + sizeof (diagnostic_classification_change_t), + lengths[0], f) != lengths[0] + || fread (m_push_list.address (), sizeof (int), + lengths[1], f) != lengths[1]) + return -1; + return 0; +} + /* Save all diagnostic classifications in a stack. */ void --- gcc/c-family/c-pch.cc.jj 2024-02-01 16:00:37.149739756 +0100 +++ gcc/c-family/c-pch.cc 2024-09-26 18:12:31.097700113 +0200 @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. #include "c-pragma.h" #include "langhooks.h" #include "hosthooks.h" +#include "diagnostic.h" /* This is a list of flag variables that must match exactly, and their names for the error message. The possible values for *flag_var must @@ -178,7 +179,8 @@ c_common_write_pch (void) cpp_write_pch_state (parse_in, pch_outfile); timevar_pop (TV_PCH_CPP_SAVE); - if (fseek (pch_outfile, 0, SEEK_SET) != 0 + if (global_dc->pch_save (pch_outfile) < 0 + || fseek (pch_outfile, 0, SEEK_SET) != 0 || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1) fatal_error (input_location, "cannot write %s: %m", pch_file); @@ -359,6 +361,10 @@ c_common_read_pch (cpp_reader *pfile, co linemap_line_start (line_table, saved_loc.line, 0); timevar_pop (TV_PCH_CPP_RESTORE); + + if (global_dc->pch_restore (f) < 0) + fatal_error (input_location, "cannot read %s: %m", name); + fclose (f); if (cpp_result != 0) --- gcc/testsuite/g++.dg/pch/pr116847.C.jj 2024-09-26 18:29:02.679292807 +0200 +++ gcc/testsuite/g++.dg/pch/pr116847.C 2024-09-26 18:27:42.679374530 +0200 @@ -0,0 +1,10 @@ +// { dg-do compile { target c++11 } } + +#include "pr116847.H" + +int a = S<0>::bar (); + +int +main () +{ +} --- gcc/testsuite/g++.dg/pch/pr116847.Hs.jj 2024-09-26 18:28:58.866344362 +0200 +++ gcc/testsuite/g++.dg/pch/pr116847.Hs 2024-09-26 18:27:35.579470530 +0200 @@ -0,0 +1,8 @@ +[[deprecated]] int foo () { return 42; } +template +struct S { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +static int bar () { return foo (); } +#pragma GCC diagnostic pop +};