From patchwork Tue Jun 6 20:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 104108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3662836vqr; Tue, 6 Jun 2023 13:52:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7438fIBljnn3OyrT5u7bgyg3LpVWXMaBpaYWOp0qMcFF8S6KkpR7zzjasfT7na3W4e2pfQ X-Received: by 2002:aa7:dad9:0:b0:514:bcfd:6e2a with SMTP id x25-20020aa7dad9000000b00514bcfd6e2amr3930213eds.2.1686084778792; Tue, 06 Jun 2023 13:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686084778; cv=none; d=google.com; s=arc-20160816; b=QdhbeJsMtfYmLtI214jm4xdm4mcxKtEaBDtIBFUk7C4319w/ETfDZsatmGjhOtKcg0 BUmMLH6+Cx2IIc8vUMqhi3mb33UmpT8wqMVKAhqmTidassChM95g3IdT87p9R4iC2EHN PTi3nSu9mLFzP53JoNx92Onrdf3T1xXBtyHlF95G5/afY5bGxJtiy4OukB4lIrhd1iRc bq9LkNNWNvHpYfCKCluF0wvVTbnXBiiohbAYRNpirbKbnPRUssfAkBcJCufw7yDoYpOV P4NSOunCNbF8aEQ26KO6QcOb2z7IbiPyllsmQ3XJuQArlSGz479jRJNHCqyxTmqPE1bp JiLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=REXHb1SA1zX3JaNOuBOM4dldKzP8DRyzfZx6ICOG4Vs=; b=FrwmmnC8YViRbRK+0weZBVDukE2kpeRxLL5M57X8gbu6Ld6MVXfQvZ0t1ZALlhp684 Xht7ABz2DUlp+ol60lLBhgKMGkdQ9okffxhSbzoHc0bWk1RQeSSyDzG6MnufTLJjeLw3 kbwhMUw+mIHdKKFI1+zRkyhENcygSqK2+LS5XEc3OLkAYjrE0yNOUNXDHdxOQ0ZI5K0G SU2wBUTx2MeDa0qZ8ptlZBZGr/oP/nNgsqgiI06ySDEuo8S7+YV+TCC5cZOPJOPve80X d7bOeR/lq43uxM3UFWxPylbrPi7A9Zg050bPLZ1PnnEc+AiYr+b3MAeHa3ctRcFkLaUO mz/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eas0+HKo; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n8-20020a056402514800b00514b886ef57si7047974edd.383.2023.06.06.13.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:52:58 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=eas0+HKo; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E54503844077 for ; Tue, 6 Jun 2023 20:51:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E54503844077 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686084685; bh=REXHb1SA1zX3JaNOuBOM4dldKzP8DRyzfZx6ICOG4Vs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=eas0+HKolOjgdKbbyy7nxywrO0huFdJ+cQrnwpQXkaZ3Rdh4D7MDiN2TwvpbDnph3 VgQQM4VX7o0PCegVhHGlXqM5qw43RxVt+Dk9ApNJMs3xgcCMkWj601Q5pCch2RsbQV 7OWNpiumx55zsonQkY2DXJgq7IwYBVCETBzDTmGQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id C54613858281 for ; Tue, 6 Jun 2023 20:50:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C54613858281 Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-6261cb1208eso44316836d6.0 for ; Tue, 06 Jun 2023 13:50:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686084635; x=1688676635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=REXHb1SA1zX3JaNOuBOM4dldKzP8DRyzfZx6ICOG4Vs=; b=kGJc/IOa8LxDbJhI9bcWaDKHobDO5aQUo5gDgKt1Z1L+sbsH4jwSQt4Hlu+eaTIsnU yzq5RfXrFkxOxXkDl59wdjlow4nAmj5nf+q57ioGUODJXH6Zf1HbNcN4WX92zJPWu/9q naf90Y7mURtX7vjbbTE0fQLCs8xG3+61sROiCJpwQ1ZaqsmoQ2Y0tbvlNTSzVT0Okk/T oTV30qwnFUthVy7wYUSgsoBEtaVlaj4My2bJDg16IZqkexyKiC3Ppn+Ns9SxbcE1uzL3 dDMYIp50wJRzwYpKxB7zjbcr0guznxQmqcTlgVU555+iT6iK+xR5YLDLyzbA2BiiFE8B Mp9g== X-Gm-Message-State: AC+VfDyOBYbWXRkesIQpLbboo2mDd71D7hbXDDFPsZbSi9a0+wvU/BzD L6jk7YYlU3vNHPtZslwLTZKQ/wJx2uHcPBJYezRQaQ== X-Received: by 2002:a05:6214:2a84:b0:625:86ed:8aab with SMTP id jr4-20020a0562142a8400b0062586ed8aabmr874774qvb.14.1686084635112; Tue, 06 Jun 2023 13:50:35 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id w2-20020ac84d02000000b003f6a0fa022bsm5831228qtv.51.2023.06.06.13.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:50:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v6 1/4] libcpp: reject codepoints above 0x10FFFF Date: Tue, 6 Jun 2023 16:50:22 -0400 Message-Id: <20230606205025.3164738-2-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230606205025.3164738-1-ben.boeckel@kitware.com> References: <20230606205025.3164738-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767988032832158982?= X-GMAIL-MSGID: =?utf-8?q?1767988032832158982?= Unicode does not support such values because they are unrepresentable in UTF-16. libcpp/ * charset.cc: Reject encodings of codepoints above 0x10FFFF. UTF-16 does not support such codepoints and therefore all Unicode rejects such values. Signed-off-by: Ben Boeckel --- libcpp/charset.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libcpp/charset.cc b/libcpp/charset.cc index d7f323b2cd5..3b34d804cf1 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -1886,6 +1886,13 @@ cpp_valid_utf8_p (const char *buffer, size_t num_bytes) int err = one_utf8_to_cppchar (&iter, &bytesleft, &cp); if (err) return false; + + /* Additionally, Unicode declares that all codepoints above 0010FFFF are + invalid because they cannot be represented in UTF-16. + + Reject such values.*/ + if (cp >= 0x10FFFF) + return false; } /* No problems encountered. */ return true; From patchwork Tue Jun 6 20:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 104110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3663904vqr; Tue, 6 Jun 2023 13:55:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PzLoHIRnLPNAyvxBM3nd7Tai3be65IZ80Il6M/XSZTVmhMN+qY4Or0EODzHcXoZGMF52L X-Received: by 2002:aa7:cc12:0:b0:514:9f5a:e2c3 with SMTP id q18-20020aa7cc12000000b005149f5ae2c3mr2429628edt.35.1686084943366; Tue, 06 Jun 2023 13:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686084943; cv=none; d=google.com; s=arc-20160816; b=xyCCA7HxmJOMGZxeasB/wv8MblIvoQfgM0jVy4Z06irSJ7UguUVVww4PvaFl5LzUXS T9Fz2zKmepDk3LSzJgifMvUCwqbXfoyomqdyDy2qyJMAl9At5fELXj3zs5ozmdgebRih mgdDFMENRjKv+R4UAjSlqkJuFjdsPkojTXVW8CPFSARkdq2Z2QmMSvQAuZRh96MWnOZ8 OYtL8X9FJ64Z02n9gqYgyIEilt0iD9piun2bHs92YydsboqijA0qnZMLC7+K5DtY7VB9 5/xnWk8Pc2AsU7pIVVdt8x143FYfGl0hRM2WHui6Rq+lcStIVl5stMl0MNySuZqyR2/b t95w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=nICs02tYe4wMvutIzpqx1jcgxEj3zARkfrZZ/Hzefi4=; b=bsDf0uDu4Z1uEtHFFhf0KvIv+XfQVjD1impnzviRkzA1WpUB9t18Nmyz88mJxEcGjp 6bpbdzi7UTk8sQS2AN/sZLxcqfKlMetAMTsPk6KY+ocb2kX0cRs4xLZcHJ+n1AqQZJVt ujucmi0gKb4PikrX86HRiMhm5n6u5BjeqEPMwKn7L2lFToR8SAFpmkv9Tl6I1j8rgeUl auP7uRlyTTFjrPFRwIDaO7IjB0uUqKjA8wABlewMqQQYn8z1aFI5STRGbDR3Z7b+ZzFc jGL6+VuhW8lqOzUSzfrENRmF7OOyhX3ciHmB0c6+c3HeJ6BzzlInS+fgroMRckQ7nnLr XMPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UqlAKMdM; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dy26-20020a05640231fa00b00514b31a1147si6640397edb.133.2023.06.06.13.55.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:55:43 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=UqlAKMdM; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98FCC3853D23 for ; Tue, 6 Jun 2023 20:52:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98FCC3853D23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686084742; bh=nICs02tYe4wMvutIzpqx1jcgxEj3zARkfrZZ/Hzefi4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=UqlAKMdMveUrlBssPiOiZmijscZDPgOTimeZtjKlajV72MxZx1hIbi5efZnrEnnx/ PKxJe7ZlKsDhnkkiZ78L5PS6iwrERbtze+aas7nxVOtsj/c1k+mfpeN7vNCrSCivWS dXFd50AkwPjDYr68OpBiAxtjXsSTBowZgatWOMvM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id C928538582BC for ; Tue, 6 Jun 2023 20:50:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C928538582BC Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-75d4094f9baso354641285a.1 for ; Tue, 06 Jun 2023 13:50:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686084638; x=1688676638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nICs02tYe4wMvutIzpqx1jcgxEj3zARkfrZZ/Hzefi4=; b=TpPviyvlMXk+kdHkJU5TANdXr+gLwGien4Bc3Jg7HW4zIbJmfN5aM3M7l/XcHNfAoj hDTZNO6DHSnIgsTngbMmFoK1eq3cMq3wWx4wMn7WZI4LFKaLnqSbgd52KP150aPSon0f NJOw+hUKNdxITfMjDQvFGgagjolMF7l1ScJwsMLM7u9syh0CVKJbRwFssTfvhmG5+aAi /iRxFPPoMH+MNlgQWOBdTSE2TDaTN8G9oXtv0zGuyj0JTNGeaOGUw4fZhRtFZU/OWvwP PY4BowH/PVH6esMbKUOzx2tOwC2FanCnC4SLfn4dhSbb9e6v1vGC1Z0Enwdr100wQK7U pFjg== X-Gm-Message-State: AC+VfDz1arCeChXZXgb5YbP8Yw2x7fpisJAEOpn6PWtL4UBfQvIk+sak kkD+Zjx73D+XyOx1uf/xeb3dkelTqXVfN5MaUXk7dQ== X-Received: by 2002:a05:620a:3ac7:b0:75e:bc40:7546 with SMTP id ss7-20020a05620a3ac700b0075ebc407546mr994798qkn.3.1686084637692; Tue, 06 Jun 2023 13:50:37 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id h14-20020a05620a10ae00b0075bb2aa9a67sm5149673qkk.59.2023.06.06.13.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:50:37 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v6 2/4] p1689r5: initial support Date: Tue, 6 Jun 2023 16:50:23 -0400 Message-Id: <20230606205025.3164738-3-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230606205025.3164738-1-ben.boeckel@kitware.com> References: <20230606205025.3164738-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767988205516796128?= X-GMAIL-MSGID: =?utf-8?q?1767988205516796128?= This patch implements support for [P1689R5][] to communicate to a build system the C++20 module dependencies to build systems so that they may build `.gcm` files in the proper order. Support is communicated through the following three new flags: - `-fdeps-format=` specifies the format for the output. Currently named `p1689r5`. - `-fdeps-file=` specifies the path to the file to write the format to. - `-fdeps-target=` specifies the `.o` that will be written for the TU that is scanned. This is required so that the build system can correlate the dependency output with the actual compilation that will occur. CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0) using an experimental feature selection (to allow for future usage evolution without committing to how it works today). While it remains experimental, docs may be found in CMake's documentation for experimental features. Future work may include using this format for Fortran module dependencies as well, however this is still pending work. [P1689R5]: https://isocpp.org/files/papers/P1689R5.html [cmake-experimental]: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst TODO: - header-unit information fields Header units (including the standard library headers) are 100% unsupported right now because the `-E` mechanism wants to import their BMIs. A new mode (i.e., something more workable than existing `-E` behavior) that mocks up header units as if they were imported purely from their path and content would be required. - non-utf8 paths The current standard says that paths that are not unambiguously represented using UTF-8 are not supported (because these cases are rare and the extra complication is not worth it at this time). Future versions of the format might have ways of encoding non-UTF-8 paths. For now, this patch just doesn't support non-UTF-8 paths (ignoring the "unambiguously represetable in UTF-8" case). - figure out why junk gets placed at the end of the file Sometimes it seems like the file gets a lot of `NUL` bytes appended to it. It happens rarely and seems to be the result of some `ftruncate`-style call which results in extra padding in the contents. Noting it here as an observation at least. libcpp/ * include/cpplib.h: Add cpp_deps_format enum. (cpp_options): Add format field (cpp_finish): Add dependency stream parameter. * include/mkdeps.h (deps_add_module_target): Add new preprocessor parameter used for C++ module tracking. * init.cc (cpp_finish): Add new preprocessor parameter used for C++ module tracking. * mkdeps.cc (mkdeps): Implement P1689R5 output. gcc/ * doc/invoke.texi: Document -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. gcc/c-family/ * c-opts.cc (c_common_handle_option): Add fdeps_file variable and -fdeps-format=, -fdeps-file=, and -fdeps-target= parsing. * c.opt: Add -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. gcc/cp/ * module.cc (preprocessed_module): Pass whether the module is exported to dependency tracking. gcc/testsuite/ * g++.dg/modules/depflags-f-MD.C: New test. * g++.dg/modules/depflags-f.C: New test. * g++.dg/modules/depflags-fi.C: New test. * g++.dg/modules/depflags-fj-MD.C: New test. * g++.dg/modules/depflags-fj.C: New test. * g++.dg/modules/depflags-fjo-MD.C: New test. * g++.dg/modules/depflags-fjo.C: New test. * g++.dg/modules/depflags-fo-MD.C: New test. * g++.dg/modules/depflags-fo.C: New test. * g++.dg/modules/depflags-j-MD.C: New test. * g++.dg/modules/depflags-j.C: New test. * g++.dg/modules/depflags-jo-MD.C: New test. * g++.dg/modules/depflags-jo.C: New test. * g++.dg/modules/depflags-o-MD.C: New test. * g++.dg/modules/depflags-o.C: New test. * g++.dg/modules/p1689-1.C: New test. * g++.dg/modules/p1689-1.exp.json: New test expectation. * g++.dg/modules/p1689-2.C: New test. * g++.dg/modules/p1689-2.exp.json: New test expectation. * g++.dg/modules/p1689-3.C: New test. * g++.dg/modules/p1689-3.exp.json: New test expectation. * g++.dg/modules/p1689-4.C: New test. * g++.dg/modules/p1689-4.exp.json: New test expectation. * g++.dg/modules/p1689-5.C: New test. * g++.dg/modules/p1689-5.exp.json: New test expectation. * g++.dg/modules/modules.exp: Load new P1689 library routines. * g++.dg/modules/test-p1689.py: New tool for validating P1689 output. * lib/modules.exp: Support for validating P1689 outputs. Signed-off-by: Ben Boeckel --- gcc/c-family/c-opts.cc | 40 +++- gcc/c-family/c.opt | 12 + gcc/cp/module.cc | 3 +- gcc/doc/invoke.texi | 15 ++ gcc/testsuite/g++.dg/modules/depflags-f-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-f.C | 1 + gcc/testsuite/g++.dg/modules/depflags-fi.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fj-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fj.C | 4 + .../g++.dg/modules/depflags-fjo-MD.C | 4 + gcc/testsuite/g++.dg/modules/depflags-fjo.C | 5 + gcc/testsuite/g++.dg/modules/depflags-fo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-j-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-j.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-o-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-o.C | 3 + gcc/testsuite/g++.dg/modules/modules.exp | 1 + gcc/testsuite/g++.dg/modules/p1689-1.C | 18 ++ gcc/testsuite/g++.dg/modules/p1689-1.exp.json | 27 +++ gcc/testsuite/g++.dg/modules/p1689-2.C | 16 ++ gcc/testsuite/g++.dg/modules/p1689-2.exp.json | 16 ++ gcc/testsuite/g++.dg/modules/p1689-3.C | 14 ++ gcc/testsuite/g++.dg/modules/p1689-3.exp.json | 16 ++ gcc/testsuite/g++.dg/modules/p1689-4.C | 14 ++ gcc/testsuite/g++.dg/modules/p1689-4.exp.json | 14 ++ gcc/testsuite/g++.dg/modules/p1689-5.C | 14 ++ gcc/testsuite/g++.dg/modules/p1689-5.exp.json | 14 ++ gcc/testsuite/g++.dg/modules/test-p1689.py | 222 ++++++++++++++++++ gcc/testsuite/lib/modules.exp | 71 ++++++ libcpp/include/cpplib.h | 12 +- libcpp/include/mkdeps.h | 17 +- libcpp/init.cc | 13 +- libcpp/mkdeps.cc | 149 +++++++++++- 36 files changed, 745 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fi.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.exp.json create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.exp.json create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.exp.json create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.exp.json create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.exp.json create mode 100644 gcc/testsuite/g++.dg/modules/test-p1689.py create mode 100644 gcc/testsuite/lib/modules.exp diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index c68a2a27469..3958aa7c7f2 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -77,6 +77,9 @@ static bool verbose; /* Dependency output file. */ static const char *deps_file; +/* Enhanced dependency output file. */ +static const char *fdeps_file; + /* The prefix given by -iprefix, if any. */ static const char *iprefix; @@ -360,6 +363,23 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, deps_file = arg; break; + case OPT_fdeps_format_: + if (!strcmp (arg, "p1689r5")) + cpp_opts->deps.format = DEPS_FMT_P1689R5; + else + error ("%<-fdeps-format=%> unknown format %<%s%>", arg); + break; + + case OPT_fdeps_file_: + deps_seen = true; + fdeps_file = arg; + break; + + case OPT_fdeps_target_: + deps_seen = true; + defer_opt (code, arg); + break; + case OPT_MF: deps_seen = true; deps_file = arg; @@ -1272,6 +1292,7 @@ void c_common_finish (void) { FILE *deps_stream = NULL; + FILE *fdeps_stream = NULL; /* Note that we write the dependencies even if there are errors. This is useful for handling outdated generated headers that now trigger errors @@ -1300,9 +1321,24 @@ c_common_finish (void) locations with input_location, which would be incorrect now. */ override_libcpp_locations = false; + if (cpp_opts->deps.format != DEPS_FMT_NONE) + { + if (!fdeps_file) + fdeps_stream = out_stream; + else if (fdeps_file[0] == '-' && fdeps_file[1] == '\0') + fdeps_stream = stdout; + else + { + fdeps_stream = fopen (fdeps_file, "w"); + if (!fdeps_stream) + fatal_error (input_location, "opening dependency file %s: %m", + fdeps_file); + } + } + /* For performance, avoid tearing down cpplib's internal structures with cpp_destroy (). */ - cpp_finish (parse_in, deps_stream); + cpp_finish (parse_in, deps_stream, fdeps_stream); if (deps_stream && deps_stream != out_stream && deps_stream != stdout && (ferror (deps_stream) || fclose (deps_stream))) @@ -1374,6 +1410,8 @@ handle_deferred_opts (void) if (opt->code == OPT_MT || opt->code == OPT_MQ) deps_add_target (deps, opt->arg, opt->code == OPT_MQ); + else if (opt->code == OPT_fdeps_target_) + deps_add_output (deps, opt->arg, true); } } diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 3333cddeece..0e5dcbe3dab 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -256,6 +256,18 @@ MT C ObjC C++ ObjC++ Joined Separate MissingArgError(missing makefile target after %qs) -MT Add a target that does not require quoting. +fdeps-format= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing format after %qs) +Format for output dependency information. Supported (\"p1689r5\"). + +fdeps-file= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing output path after %qs) +File for output dependency information. + +fdeps-target= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing path after %qs) +-fdeps-target=obj.o Output file for the compile step. + P C ObjC C++ ObjC++ Do not generate #line directives. diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index ecde98d69b4..c80f139eb82 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -19832,7 +19832,8 @@ preprocessed_module (cpp_reader *reader) && (module->is_interface () || module->is_partition ())) deps_add_module_target (deps, module->get_flatname (), maybe_add_cmi_prefix (module->filename), - module->is_header()); + module->is_header (), + module->is_exported ()); else deps_add_module_dep (deps, module->get_flatname ()); } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9130104af22..41952739b62 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2807,6 +2807,21 @@ is @option{-fpermitted-flt-eval-methods=c11}. The default when in a GNU dialect (@option{-std=gnu11} or similar) is @option{-fpermitted-flt-eval-methods=ts-18661-3}. +@opindex fdeps-file +@item -fdeps-file=@var{file} +Where to write structured dependency information. + +@opindex fdeps-format +@item -fdeps-format=@var{format} +The format to use for structured dependency information. @samp{p1689r5} is the +only supported format right now. Note that when this argument is specified, the +output of @samp{-MF} is stripped of some information (namely C++ modules) so +that it does not use extended makefile syntax not understood by most tools. + +@opindex fdeps-target +@item -fdeps-target=@var{file} +Analogous to @option{-MT} but for structured dependency information. + @opindex fplan9-extensions @item -fplan9-extensions Accept some non-standard constructs used in Plan 9 code. diff --git a/gcc/testsuite/g++.dg/modules/depflags-f-MD.C b/gcc/testsuite/g++.dg/modules/depflags-f-MD.C new file mode 100644 index 00000000000..2bd980c0047 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-f-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-f.C b/gcc/testsuite/g++.dg/modules/depflags-f.C new file mode 100644 index 00000000000..126e691601c --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-f.C @@ -0,0 +1 @@ +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fi.C b/gcc/testsuite/g++.dg/modules/depflags-fi.C new file mode 100644 index 00000000000..81a1e62719a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fi.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-format=invalid } + +// { dg-prune-output "error: '-fdeps-format=' unknown format 'invalid'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C new file mode 100644 index 00000000000..f85b294123a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fj.C b/gcc/testsuite/g++.dg/modules/depflags-fj.C new file mode 100644 index 00000000000..153d6f24c34 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fj.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C new file mode 100644 index 00000000000..39870d40204 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C @@ -0,0 +1,4 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-target=depflags-1.C } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fjo.C b/gcc/testsuite/g++.dg/modules/depflags-fjo.C new file mode 100644 index 00000000000..c58ee836d89 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fjo.C @@ -0,0 +1,5 @@ +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-target=depflags-1.C } +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C new file mode 100644 index 00000000000..6da03f9133f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fo.C b/gcc/testsuite/g++.dg/modules/depflags-fo.C new file mode 100644 index 00000000000..5deb27a4598 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fo.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-j-MD.C b/gcc/testsuite/g++.dg/modules/depflags-j-MD.C new file mode 100644 index 00000000000..cb4acf7090f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-j-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.json } diff --git a/gcc/testsuite/g++.dg/modules/depflags-j.C b/gcc/testsuite/g++.dg/modules/depflags-j.C new file mode 100644 index 00000000000..680eb502f2a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-j.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-file=depflags-3.json } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C new file mode 100644 index 00000000000..3f88d078e2d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-jo.C b/gcc/testsuite/g++.dg/modules/depflags-jo.C new file mode 100644 index 00000000000..47eff5fcd23 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-jo.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-file=depflags-3.json } +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-o-MD.C b/gcc/testsuite/g++.dg/modules/depflags-o-MD.C new file mode 100644 index 00000000000..1b67558b687 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-o-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-o.C b/gcc/testsuite/g++.dg/modules/depflags-o.C new file mode 100644 index 00000000000..38d645081b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-o.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/modules.exp b/gcc/testsuite/g++.dg/modules/modules.exp index dc302d3d0af..b6929544c59 100644 --- a/gcc/testsuite/g++.dg/modules/modules.exp +++ b/gcc/testsuite/g++.dg/modules/modules.exp @@ -28,6 +28,7 @@ # { dg-module-do [link|run] [xfail] [options] } # link [and run] load_lib g++-dg.exp +load_lib modules.exp # If a testcase doesn't have special options, use these. global DEFAULT_CXXFLAGS diff --git a/gcc/testsuite/g++.dg/modules/p1689-1.C b/gcc/testsuite/g++.dg/modules/p1689-1.C new file mode 100644 index 00000000000..3654c924b44 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-1.C @@ -0,0 +1,18 @@ +// { dg-additional-options -E } +// { dg-additional-options -MT } +// { dg-additional-options p1689-1.json } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-1.o } +// { dg-additional-options -fdeps-file=p1689-1.json } + +// Export a module that uses modules, re-exports modules, and partitions. + +export module foo; +export import foo:part1; +import foo:part2; + +export import bar; + +// { dg-final { run-check-p1689-valid p1689-1.json p1689-1.exp.json } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-1.exp.json b/gcc/testsuite/g++.dg/modules/p1689-1.exp.json new file mode 100644 index 00000000000..c5648ac7ae5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-1.exp.json @@ -0,0 +1,27 @@ +{ + "rules": [ + { + "primary-output": "p1689-1.o", + "provides": [ + { + "logical-name": "foo", + "is-interface": true + } + ], + "requires": [ + "__P1689_unordered__", + { + "logical-name": "bar" + }, + { + "logical-name": "foo:part1" + }, + { + "logical-name": "foo:part2" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-2.C b/gcc/testsuite/g++.dg/modules/p1689-2.C new file mode 100644 index 00000000000..e32cd88f5a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-2.C @@ -0,0 +1,16 @@ +// { dg-additional-options -E } +// { dg-additional-options -MT } +// { dg-additional-options p1689-2.json } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-2.o } +// { dg-additional-options -fdeps-file=p1689-2.json } + +// Export a module partition that uses modules. + +export module foo:part1; + +#include + +// { dg-final { run-check-p1689-valid p1689-2.json p1689-2.exp.json } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-2.exp.json b/gcc/testsuite/g++.dg/modules/p1689-2.exp.json new file mode 100644 index 00000000000..6901172f277 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-2.exp.json @@ -0,0 +1,16 @@ +{ + "rules": [ + { + "primary-output": "p1689-2.o", + "provides": [ + { + "logical-name": "foo:part1", + "is-interface": true + } + ], + "requires": [] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-3.C b/gcc/testsuite/g++.dg/modules/p1689-3.C new file mode 100644 index 00000000000..d0962cd432d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-3.C @@ -0,0 +1,14 @@ +// { dg-additional-options -E } +// { dg-additional-options -MT } +// { dg-additional-options p1689-3.json } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-3.o } +// { dg-additional-options -fdeps-file=p1689-3.json } + +// Provide a module partition. + +module foo:part2; + +// { dg-final { run-check-p1689-valid p1689-3.json p1689-3.exp.json } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-3.exp.json b/gcc/testsuite/g++.dg/modules/p1689-3.exp.json new file mode 100644 index 00000000000..5a40beacd22 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-3.exp.json @@ -0,0 +1,16 @@ +{ + "rules": [ + { + "primary-output": "p1689-3.o", + "provides": [ + { + "logical-name": "foo:part2", + "is-interface": false + } + ], + "requires": [] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-4.C b/gcc/testsuite/g++.dg/modules/p1689-4.C new file mode 100644 index 00000000000..a1935579074 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-4.C @@ -0,0 +1,14 @@ +// { dg-additional-options -E } +// { dg-additional-options -MT } +// { dg-additional-options p1689-4.json } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-4.o } +// { dg-additional-options -fdeps-file=p1689-4.json } + +// Module implementation unit. + +module foo; + +// { dg-final { run-check-p1689-valid p1689-4.json p1689-4.exp.json } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-4.exp.json b/gcc/testsuite/g++.dg/modules/p1689-4.exp.json new file mode 100644 index 00000000000..b119f5654b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-4.exp.json @@ -0,0 +1,14 @@ +{ + "rules": [ + { + "primary-output": "p1689-4.o", + "requires": [] + { + "logical-name": "foo" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-5.C b/gcc/testsuite/g++.dg/modules/p1689-5.C new file mode 100644 index 00000000000..f42933856a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-5.C @@ -0,0 +1,14 @@ +// { dg-additional-options -E } +// { dg-additional-options -MT } +// { dg-additional-options p1689-5.json } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-5.o } +// { dg-additional-options -fdeps-file=p1689-5.json } + +// Use modules, don't provide anything. + +import bar; + +// { dg-final { run-check-p1689-valid p1689-5.json p1689-5.exp.json } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-5.exp.json b/gcc/testsuite/g++.dg/modules/p1689-5.exp.json new file mode 100644 index 00000000000..18704ac8820 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-5.exp.json @@ -0,0 +1,14 @@ +{ + "rules": [ + { + "primary-output": "p1689-5.o", + "requires": [ + { + "logical-name": "bar" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/test-p1689.py b/gcc/testsuite/g++.dg/modules/test-p1689.py new file mode 100644 index 00000000000..2f07cc361aa --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/test-p1689.py @@ -0,0 +1,222 @@ +import json + + +# Parameters. +ALL_ERRORS = False +REPLACEMENTS = {} + + +def _print_path(path): + '''Format a JSON path for output.''' + return '/'.join(path) + + +def _report_error(msg): + '''Report an error.''' + full_msg = 'ERROR: ' + msg + if ALL_ERRORS: + print(full_msg) + else: + raise RuntimeError(full_msg) + + +def _error_type_mismatch(path, actual, expect): + '''Report that there is a type mismatch.''' + _report_error('type mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_unknown_type(path, typ): + '''Report that there is an unknown type in the JSON object.''' + _report_error('unknown type at %s: "%s"' % (_print_path(path), typ)) + + +def _error_length_mismatch(path, actual, expect): + '''Report a length mismatch in an object or array.''' + _report_error('length mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_unexpect_value(path, actual, expect): + '''Report a value mismatch.''' + _report_error('value mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_extra_key(path, key): + '''Report on a key that is unexpected.''' + _report_error('extra key at %s: "%s"' % (_print_path(path), key)) + + +def _error_missing_key(path, key): + '''Report on a key that is missing.''' + _report_error('extra key at %s: %s' % (_print_path(path), key)) + + +def _compare_object(path, actual, expect): + '''Compare a JSON object.''' + is_ok = True + + if not len(actual) == len(expect): + _error_length_mismatch(path, len(actual), len(expect)) + is_ok = False + + for key in actual: + if key not in expect: + _error_extra_key(path, key) + is_ok = False + else: + sub_error = compare_json(path + [key], actual[key], expect[key]) + if sub_error: + is_ok = False + + for key in expect: + if key not in actual: + _error_missing_key(path, key) + is_ok = False + + return is_ok + + +def _compare_array(path, actual, expect): + '''Compare a JSON array.''' + is_ok = True + + if not len(actual) == len(expect): + _error_length_mismatch(path, len(actual), len(expect)) + is_ok = False + + for (idx, (a, e)) in enumerate(zip(actual, expect)): + sub_error = compare_json(path + [str(idx)], a, e) + if sub_error: + is_ok = False + + return is_ok + + +def _make_replacements(value): + for (old, new) in REPLACEMENTS.values(): + value = value.replace(old, new) + return value + + +def _compare_string(path, actual, expect): + '''Compare a JSON string supporting replacements in the expected output.''' + expect = _make_replacements(expect) + + if not actual == expect: + _error_unexpect_value(path, actual, expect) + return False + else: + print('%s is ok: %s' % (_print_path(path), actual)) + return True + + +def _compare_number(path, actual, expect): + '''Compare a JSON integer.''' + if not actual == expect: + _error_unexpect_value(path, actual, expect) + return False + else: + print('%s is ok: %s' % (_print_path(path), actual)) + return True + + +def _inspect_ordering(arr): + req_ordering = True + + if not arr: + return arr, req_ordering + + if arr[0] == '__P1689_unordered__': + arr.pop(0) + req_ordering = False + + return arr, req_ordering + + +def compare_json(path, actual, expect): + actual_type = type(actual) + expect_type = type(expect) + + is_ok = True + + if not actual_type == expect_type: + _error_type_mismatch(path, actual_type, expect_type) + is_ok = False + elif actual_type == dict: + is_ok = _compare_object(path, actual, expect) + elif actual_type == list: + expect, req_ordering = _inspect_ordering(expect) + if not req_ordering: + actual = set(actual) + expect = set(expect) + is_ok = _compare_array(path, actual, expect) + elif actual_type == str: + is_ok = _compare_string(path, actual, expect) + elif actual_type == float: + is_ok = _compare_number(path, actual, expect) + elif actual_type == int: + is_ok = _compare_number(path, actual, expect) + elif actual_type == bool: + is_ok = _compare_number(path, actual, expect) + elif actual_type == type(None): + pass + else: + _error_unknown_type(path, actual_type) + is_ok = False + + return is_ok + + +def validate_p1689(actual, expect): + '''Validate a P1689 file against an expected output file. + + Returns `False` if it fails, `True` if they are the same. + ''' + with open(actual, 'r') as fin: + actual_content = fin.read() + with open(expect, 'r') as fin: + expect_content = fin.read() + + actual_json = json.loads(actual_content) + expect_json = json.loads(expect_content) + + return compare_json([], actual_json, expect_json) + + +if __name__ == '__main__': + import sys + + actual = None + expect = None + + # Parse arguments. + args = sys.argv[1:] + while args: + # Take an argument. + arg = args.pop(0) + + # Parse out replacement expressions. + if arg == '-r' or arg == '--replace': + replacement = args.pop(0) + (key, value) = replacement.split('=', maxsplit=1) + REPLACEMENTS[key] = value + # Flag to change how errors are reported. + elif arg == '-A' or arg == '--all': + ALL_ERRORS = True + # Required arguments. + elif arg == '-a' or arg == '--actual': + actual = args.pop(0) + elif arg == '-e' or arg == '--expect': + expect = args.pop(0) + + # Validate that we have the required arguments. + if actual is None: + raise RuntimeError('missing "actual" file') + if expect is None: + raise RuntimeError('missing "expect" file') + + # Do the actual work. + is_ok = validate_p1689(actual, expect) + + # Fail if errors are found. + if not is_ok: + sys.exit(1) diff --git a/gcc/testsuite/lib/modules.exp b/gcc/testsuite/lib/modules.exp new file mode 100644 index 00000000000..c7cfda6aae4 --- /dev/null +++ b/gcc/testsuite/lib/modules.exp @@ -0,0 +1,71 @@ +# Copyright (C) 1997-2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Verify various kinds of gcov output: line counts, branch percentages, +# and call return percentages. None of this is language-specific. + +load_lib "target-supports.exp" + +# +# clean-p1689-file -- delete a working file the compiler creates for p1689 +# +# TESTCASE is the name of the test. +# SUFFIX is file suffix + +proc clean-p1689-file { testcase suffix } { + set basename [file tail $testcase] + set base [file rootname $basename] + remote_file host delete $base.$suffix +} + +# +# clean-p1689 -- delete the working files the compiler creates for p1689 +# +# TESTCASE is the name of the test. +# +proc clean-p1689 { testcase } { + clean-p1689-file $testcase "d" + clean-p1689-file $testcase "json" +} + +# Call by dg-final to check a P1689 dependency file + +proc run-check-p1689-valid { depfile template } { + global srcdir subdir + # Extract the test file name from the arguments. + set testcase [file rootname [file tail $depfile]] + + verbose "Running P1689 validation for $testcase in $srcdir/$subdir" 2 + set testcase [remote_download host $testcase] + + set pytest_script "test-p1689.py" + if { ![check_effective_target_recent_python3] } { + unsupported "$pytest_script python3 is missing" + return + } + + verbose "running script" 1 + spawn -noecho python3 $srcdir/$subdir/$pytest_script --all --actual $depfile --expect $srcdir/$subdir/$template + + expect { + -re "ERROR: (\[^\r\n\]*)" { + fail $expect_out(0,string) + exp_continue + } + } + + clean-p1689 $testcase +} diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index a6f0abd894c..6fc907d12a9 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -302,6 +302,9 @@ typedef CPPCHAR_SIGNED_T cppchar_signed_t; /* Style of header dependencies to generate. */ enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM }; +/* Format of header dependencies to generate. */ +enum cpp_deps_format { DEPS_FMT_NONE = 0, DEPS_FMT_P1689R5 }; + /* The possible normalization levels, from most restrictive to least. */ enum cpp_normalize_level { /* In NFKC. */ @@ -589,6 +592,9 @@ struct cpp_options /* Style of header dependencies to generate. */ enum cpp_deps_style style; + /* Format of header dependencies to generate. */ + enum cpp_deps_format format; + /* Assume missing files are generated files. */ bool missing_files; @@ -1112,9 +1118,9 @@ extern void cpp_post_options (cpp_reader *); extern void cpp_init_iconv (cpp_reader *); /* Call this to finish preprocessing. If you requested dependency - generation, pass an open stream to write the information to, - otherwise NULL. It is your responsibility to close the stream. */ -extern void cpp_finish (cpp_reader *, FILE *deps_stream); + generation, pass open stream(s) to write the information to, + otherwise NULL. It is your responsibility to close the stream(s). */ +extern void cpp_finish (cpp_reader *, FILE *deps_stream, FILE *fdeps_stream = NULL); /* Call this to release the handle at the end of preprocessing. Any use of the handle after this function returns is invalid. */ diff --git a/libcpp/include/mkdeps.h b/libcpp/include/mkdeps.h index 920e2791334..33c7437a481 100644 --- a/libcpp/include/mkdeps.h +++ b/libcpp/include/mkdeps.h @@ -53,20 +53,29 @@ extern void deps_add_default_target (class mkdeps *, const char *); /* Adds a module target. The module name and cmi name are copied. */ extern void deps_add_module_target (struct mkdeps *, const char *module, - const char *cmi, bool is_header); + const char *cmi, bool is_header, + bool is_exported); /* Adds a module dependency. The module name is copied. */ extern void deps_add_module_dep (struct mkdeps *, const char *module); +/* Add an output. */ +extern void deps_add_output (struct mkdeps *, const char *, bool); + /* Add a dependency (appears on the right side of the colon) to the deps list. Dependencies will be printed in the order that they were entered with this function. By convention, the first dependency entered should be the primary source file. */ extern void deps_add_dep (class mkdeps *, const char *); -/* Write out a deps buffer to a specified file. The last argument - is the number of columns to word-wrap at (0 means don't wrap). */ -extern void deps_write (const cpp_reader *, FILE *, unsigned int); +/* Write out a deps buffer to a specified file. The third argument + is the number of columns to word-wrap at (0 means don't wrap). + The last argument indicates whether to output extra information + (namely modules). */ +extern void deps_write (const struct cpp_reader *, FILE *, unsigned int); + +/* Write out a deps buffer to a specified file in P1689R5 format. */ +extern void deps_write_p1689r5 (const struct mkdeps *, FILE *); /* Write out a deps buffer to a file, in a form that can be read back with deps_restore. Returns nonzero on error, in which case the diff --git a/libcpp/init.cc b/libcpp/init.cc index c508f06112a..d34fd6fdeef 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -855,7 +855,7 @@ read_original_directory (cpp_reader *pfile) Maybe it should also reset state, such that you could call cpp_start_read with a new filename to restart processing. */ void -cpp_finish (cpp_reader *pfile, FILE *deps_stream) +cpp_finish (struct cpp_reader *pfile, FILE *deps_stream, FILE *fdeps_stream) { /* Warn about unused macros before popping the final buffer. */ if (CPP_OPTION (pfile, warn_unused_macros)) @@ -869,8 +869,15 @@ cpp_finish (cpp_reader *pfile, FILE *deps_stream) while (pfile->buffer) _cpp_pop_buffer (pfile); - if (deps_stream) - deps_write (pfile, deps_stream, 72); + cpp_deps_format deps_format = CPP_OPTION (pfile, deps.format); + if (deps_format == DEPS_FMT_P1689R5 && fdeps_stream) + deps_write_p1689r5 (pfile->deps, fdeps_stream); + + if (CPP_OPTION (pfile, deps.style) != DEPS_NONE + && deps_stream) + { + deps_write (pfile, deps_stream, 72); + } /* Report on headers that could use multiple include guards. */ if (CPP_OPTION (pfile, print_include_names)) diff --git a/libcpp/mkdeps.cc b/libcpp/mkdeps.cc index 8f9585c3c0a..8c554499e41 100644 --- a/libcpp/mkdeps.cc +++ b/libcpp/mkdeps.cc @@ -81,7 +81,8 @@ public: }; mkdeps () - : module_name (NULL), cmi_name (NULL), is_header_unit (false), quote_lwm (0) + : primary_output (NULL), module_name (NULL), cmi_name (NULL) + , is_header_unit (false), is_exported (false), quote_lwm (0) { } ~mkdeps () @@ -90,6 +91,9 @@ public: for (i = targets.size (); i--;) free (const_cast (targets[i])); + free (const_cast (primary_output)); + for (i = outputs.size (); i--;) + free (const_cast (outputs[i])); for (i = deps.size (); i--;) free (const_cast (deps[i])); for (i = vpath.size (); i--;) @@ -103,6 +107,8 @@ public: public: vec targets; vec deps; + const char * primary_output; + vec outputs; vec vpath; vec modules; @@ -110,6 +116,7 @@ public: const char *module_name; const char *cmi_name; bool is_header_unit; + bool is_exported; unsigned short quote_lwm; }; @@ -288,6 +295,21 @@ deps_add_default_target (class mkdeps *d, const char *tgt) } } +/* Adds an output O. We make a copy, so it need not be a permanent + string. */ +void +deps_add_output (struct mkdeps *d, const char *o, bool is_primary) +{ + o = apply_vpath (d, o); + if (is_primary) + { + if (d->primary_output) + d->outputs.push (d->primary_output); + d->primary_output = xstrdup (o); + } else + d->outputs.push (xstrdup (o)); +} + void deps_add_dep (class mkdeps *d, const char *t) { @@ -325,12 +347,13 @@ deps_add_vpath (class mkdeps *d, const char *vpath) void deps_add_module_target (struct mkdeps *d, const char *m, - const char *cmi, bool is_header_unit) + const char *cmi, bool is_header_unit, bool is_exported) { gcc_assert (!d->module_name); d->module_name = xstrdup (m); d->is_header_unit = is_header_unit; + d->is_exported = is_exported; d->cmi_name = xstrdup (cmi); } @@ -395,10 +418,15 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) if (colmax && colmax < 34) colmax = 34; + /* Write out C++ modules information if no other `-fdeps-format=` + * option is given. */ + cpp_deps_format deps_format = CPP_OPTION (pfile, deps.format); + bool write_make_modules_deps = deps_format == DEPS_FMT_NONE; + if (d->deps.size ()) { column = make_write_vec (d->targets, fp, 0, colmax, d->quote_lwm); - if (CPP_OPTION (pfile, deps.modules) && d->cmi_name) + if (write_make_modules_deps && CPP_OPTION (pfile, deps.modules) && d->cmi_name) column = make_write_name (d->cmi_name, fp, column, colmax); fputs (":", fp); column++; @@ -412,7 +440,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) if (!CPP_OPTION (pfile, deps.modules)) return; - if (d->modules.size ()) + if (write_make_modules_deps && d->modules.size ()) { column = make_write_vec (d->targets, fp, 0, colmax, d->quote_lwm); if (d->cmi_name) @@ -423,7 +451,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) fputs ("\n", fp); } - if (d->module_name) + if (write_make_modules_deps && d->module_name) { if (d->cmi_name) { @@ -455,7 +483,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) } } - if (d->modules.size ()) + if (write_make_modules_deps && d->modules.size ()) { column = fprintf (fp, "CXX_IMPORTS +="); make_write_vec (d->modules, fp, column, colmax, 0, ".c++m"); @@ -468,11 +496,118 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) /* Really we should be opening fp here. */ void -deps_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) +deps_write (const struct cpp_reader *pfile, FILE *fp, unsigned int colmax) { make_write (pfile, fp, colmax); } +static void +p1689r5_write_filepath (const char *name, FILE *fp) +{ + if (cpp_valid_utf8_p (name, strlen (name))) + { + fputc ('"', fp); + for (const char* c = name; *c; c++) + { + // Escape control characters. + if (ISCNTRL (*c)) + fprintf (fp, "\\u%04x", *c); + // JSON escape characters. + else if (*c == '"' || *c == '\\') + { + fputc ('\\', fp); + fputc (*c, fp); + } + // Everything else. + else + fputc (*c, fp); + } + fputc ('"', fp); + } + else + { + // TODO: print an error + } +} + +static void +p1689r5_write_vec (const mkdeps::vec &vec, FILE *fp) +{ + for (unsigned ix = 0; ix != vec.size (); ix++) + { + p1689r5_write_filepath (vec[ix], fp); + if (ix < vec.size () - 1) + fputc (',', fp); + fputc ('\n', fp); + } +} + +void +deps_write_p1689r5 (const struct mkdeps *d, FILE *fp) +{ + fputs ("{\n", fp); + + fputs ("\"rules\": [\n", fp); + fputs ("{\n", fp); + + if (d->primary_output) + { + fputs ("\"primary-output\": ", fp); + p1689r5_write_filepath (d->primary_output, fp); + fputs (",\n", fp); + } + + if (d->outputs.size ()) + { + fputs ("\"outputs\": [\n", fp); + p1689r5_write_vec (d->outputs, fp); + fputs ("],\n", fp); + } + + if (d->module_name) + { + fputs ("\"provides\": [\n", fp); + fputs ("{\n", fp); + + fputs ("\"logical-name\": ", fp); + p1689r5_write_filepath (d->module_name, fp); + fputs (",\n", fp); + + fprintf (fp, "\"is-interface\": %s\n", d->is_exported ? "true" : "false"); + + // TODO: header-unit information + + fputs ("}\n", fp); + fputs ("],\n", fp); + } + + fputs ("\"requires\": [\n", fp); + for (size_t i = 0; i < d->modules.size (); i++) + { + if (i != 0) + fputs (",\n", fp); + fputs ("{\n", fp); + + fputs ("\"logical-name\": ", fp); + p1689r5_write_filepath (d->modules[i], fp); + fputs ("\n", fp); + + // TODO: header-unit information + + fputs ("}\n", fp); + } + fputs ("]\n", fp); + + fputs ("}\n", fp); + + fputs ("],\n", fp); + + fputs ("\"version\": 0,\n", fp); + fputs ("\"revision\": 0\n", fp); + + fputs ("}\n", fp); +} + /* Write out a deps buffer to a file, in a form that can be read back with deps_restore. Returns nonzero on error, in which case the error number will be in errno. */ From patchwork Tue Jun 6 20:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 104109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3662933vqr; Tue, 6 Jun 2023 13:53:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69RJPMiRHWXawfNdJ34P46TZrWMqf5YoZuq0QtHH+5U+C0rB90rd3YMjUWo/+trtFtDBGu X-Received: by 2002:a05:6402:2ca:b0:514:969e:7ae3 with SMTP id b10-20020a05640202ca00b00514969e7ae3mr2805056edx.4.1686084794044; Tue, 06 Jun 2023 13:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686084794; cv=none; d=google.com; s=arc-20160816; b=pAh044frI0eMGlKXKDR0bLxDAXDvS3fCEsbjBkIrTJh/LO+k6sBZGave7I4NzvrRnl Vyz5C0tcSN6O5WH2+Ihql47yTE9zq4jFbxanYX1Jqbq6xeb6TiqGnmX3p6kxQ5keksIq vs7nNxVQaswr+WGYupko9MAK2ZbE7ey9fYDWrAkRQc1lnvAf5rxzStqpiSsQV43FqTi2 CTCrVkpZkE9iJyBKlYbHfnOaQdp0Pbm0KdBKlcIEp0I9othLm2kzWNzfKL1UmqfFGK4u 0Ln+3Fi0NUPtlSTybu3XEdJTQHJZYnZ42BdC6S2DAAr1g+PCNE5K8tt+hzkJycwr7P/k aNGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=i5Y3/hSUJAaB9Jm9sMnKQkd1TAoxLZxPZylg5EEDe9M=; b=wS8VvX1oEXvClxEmadu6WfmIS12dbxdmDwFayUyZZ/fpt8NoA2l55Rnh2a8IOJ8E6C XA2+UutIWstJqvS5ULZTwKSzN8dZbISHVCVWQQhUTrVR30Px1XQKBRUOY4kk8rDv4gO9 v7kzITNB4Tt4kJqRfJlnVzdvtrs0N5HMtDs/tviKtAxlqc4swMazBi8FkOxUH/w/NjxJ GGs8Wh8mmqHJ42skPYMuwz/tzMRYOL4Cayk+SZRTqEJuH9lobTgnKvDCJahyv3aE+JGj hsig9ufE2XIY8eiFJ90L7wvVIG3nF7Uxli7lK2OC8WRT18ZMgTmngSagQoXJgMDeyHLJ EG5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jrZsi1h5; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c15-20020a056402120f00b00515b9e4b07bsi7101649edw.642.2023.06.06.13.53.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:53:14 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=jrZsi1h5; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1E493839DE5 for ; Tue, 6 Jun 2023 20:51:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1E493839DE5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686084691; bh=i5Y3/hSUJAaB9Jm9sMnKQkd1TAoxLZxPZylg5EEDe9M=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jrZsi1h5uo0p8X54T6I9qcnl4xMs6xjUNOg4yhJCHUJIZO27MhdLV4vVHQPqEOefx MzXp349nLzfttLamJt0b3Hms7EWvKwZpS0+1gKv07quLndlFL6+/gdNT6c40BycaF0 KCD9VKTXp3TPthFUujcvP3/MB3gw1eHsSd3/fieE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 06A293857353 for ; Tue, 6 Jun 2023 20:50:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06A293857353 Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-75e4497597cso271430585a.2 for ; Tue, 06 Jun 2023 13:50:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686084640; x=1688676640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i5Y3/hSUJAaB9Jm9sMnKQkd1TAoxLZxPZylg5EEDe9M=; b=NG+c2cCkHUOVL/rtVNbSfaLdo9N9INtugSt3GaABF8JKjDSb1ccrP56vXi2Lc46r/B i6o2/rtQJ/dheWpa6MFW+/0refJRH+JYJeZoU/grYUbJIpf9MDG6AHPHv0TuCVzK96a5 StGvLezogEzS0eX9JcFXjBbaPq8ersugwB7IXT3u8sgg+Fb5QoecafXkpq/5Ka5Ih+Qy ACJxKpfkGeIllBcNR1oNWE2uW64WwSGReV9n/ATApu07XDHIFGZ/+eOpj4BWIPEP0ZrR 6DSSXF9MuaipFAqOzUm+lNhbwWC26YXuxqzk7aMBPhTs3QDoqVSk4iRImAv9iXLP3QQ/ miXA== X-Gm-Message-State: AC+VfDwLUj83d1VHDMpuRGttRK4xjI4bW/+2t/pM9TxEwH/yeRZ/L3xs ANVCzj8B5XPZ8s4yuth37jsbPkqx86tzIhzPJTwL0Q== X-Received: by 2002:a05:620a:3187:b0:75d:17d4:8462 with SMTP id bi7-20020a05620a318700b0075d17d48462mr1056620qkb.45.1686084640398; Tue, 06 Jun 2023 13:50:40 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id p18-20020ae9f312000000b0075cad1e5907sm5199470qkg.7.2023.06.06.13.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 13:50:40 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v6 4/4] c++modules: report module mapper files as a dependency Date: Tue, 6 Jun 2023 16:50:25 -0400 Message-Id: <20230606205025.3164738-5-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230606205025.3164738-1-ben.boeckel@kitware.com> References: <20230606205025.3164738-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767988048961570624?= X-GMAIL-MSGID: =?utf-8?q?1767988048961570624?= It affects the build, and if used as a static file, can reliably be tracked using the `-MF` mechanism. gcc/cp/: * mapper-client.cc, mapper-client.h (open_module_client): Accept dependency tracking and track module mapper files as dependencies. * module.cc (make_mapper, get_mapper): Pass the dependency tracking class down. Signed-off-by: Ben Boeckel --- gcc/cp/mapper-client.cc | 4 ++++ gcc/cp/mapper-client.h | 1 + gcc/cp/module.cc | 18 +++++++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc index 39e80df2d25..0ce5679d659 100644 --- a/gcc/cp/mapper-client.cc +++ b/gcc/cp/mapper-client.cc @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-core.h" #include "mapper-client.h" #include "intl.h" +#include "mkdeps.h" #include "../../c++tools/resolver.h" @@ -132,6 +133,7 @@ spawn_mapper_program (char const **errmsg, std::string &name, module_client * module_client::open_module_client (location_t loc, const char *o, + class mkdeps *deps, void (*set_repo) (const char *), char const *full_program_name) { @@ -285,6 +287,8 @@ module_client::open_module_client (location_t loc, const char *o, errmsg = "opening"; else { + /* Add the mapper file to the dependency tracking. */ + deps_add_dep (deps, name.c_str ()); if (int l = r->read_tuple_file (fd, ident, false)) { if (l > 0) diff --git a/gcc/cp/mapper-client.h b/gcc/cp/mapper-client.h index b32723ce296..a3b0b8adc51 100644 --- a/gcc/cp/mapper-client.h +++ b/gcc/cp/mapper-client.h @@ -55,6 +55,7 @@ public: public: static module_client *open_module_client (location_t loc, const char *option, + class mkdeps *, void (*set_repo) (const char *), char const *); static void close_module_client (location_t loc, module_client *); diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index e88ce0a1818..9dbb53d2aaf 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -3969,12 +3969,12 @@ static GTY(()) vec *partial_specializations; /* Our module mapper (created lazily). */ module_client *mapper; -static module_client *make_mapper (location_t loc); -inline module_client *get_mapper (location_t loc) +static module_client *make_mapper (location_t loc, class mkdeps *deps); +inline module_client *get_mapper (location_t loc, class mkdeps *deps) { auto *res = mapper; if (!res) - res = make_mapper (loc); + res = make_mapper (loc, deps); return res; } @@ -14031,7 +14031,7 @@ get_module (const char *ptr) /* Create a new mapper connecting to OPTION. */ module_client * -make_mapper (location_t loc) +make_mapper (location_t loc, class mkdeps *deps) { timevar_start (TV_MODULE_MAPPER); const char *option = module_mapper_name; @@ -14039,7 +14039,7 @@ make_mapper (location_t loc) option = getenv ("CXX_MODULE_MAPPER"); mapper = module_client::open_module_client - (loc, option, &set_cmi_repo, + (loc, option, deps, &set_cmi_repo, (save_decoded_options[0].opt_index == OPT_SPECIAL_program_name) && save_decoded_options[0].arg != progname ? save_decoded_options[0].arg : nullptr); @@ -19504,7 +19504,7 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc, dump.push (NULL); dump () && dump ("Checking include translation '%s'", path); - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); size_t len = strlen (path); path = canonicalize_header_name (NULL, loc, true, path, len); @@ -19620,7 +19620,7 @@ module_begin_main_file (cpp_reader *reader, line_maps *lmaps, static void name_pending_imports (cpp_reader *reader) { - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); if (!vec_safe_length (pending_imports)) /* Not doing anything. */ @@ -20090,7 +20090,7 @@ init_modules (cpp_reader *reader) if (!flag_module_lazy) /* Get the mapper now, if we're not being lazy. */ - get_mapper (cpp_main_loc (reader)); + get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); if (!flag_preprocess_only) { @@ -20300,7 +20300,7 @@ late_finish_module (cpp_reader *reader, module_processing_cookie *cookie, if (!errorcount) { - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); mapper->ModuleCompiled (state->get_flatname ()); } else if (cookie->cmi_name)