From patchwork Wed Feb 24 16:59:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1443975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=IXGbk2ff; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dm2G94X6jz9sS8 for ; Thu, 25 Feb 2021 03:59:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54773395042F; Wed, 24 Feb 2021 16:59:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 5A12738708EC for ; Wed, 24 Feb 2021 16:59:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5A12738708EC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x730.google.com with SMTP id x124so2839456qkc.1 for ; Wed, 24 Feb 2021 08:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=si15cZI906umHaHVrDsC4RY3Q50vVA4mNo2tUvU3Izg=; b=IXGbk2ffRHCjbIai6buc6kDVoCy/j4JFMg9yejopu1gsBMF2PrtHhZMGBbNIisyaoZ zxlvVso3PpT/hy9P1ypHQA+k6FUfJKKfY6U+2t9WZfA6UmH4BmtRfugImGkAPWiJ++HV /tt8gDAbGDcYAXBHiJ1yzDzyLlSAfvfy5o+MYi9DTUxABpHnqn8s73xYb13NvTedSTeY OPKogQPv1v0IHrZr2WhuWPDOOKzqtT7q995rB58KNgYCTbbxNZ3cqbPRHwv/5+GR8uF9 TkC+IcJYJNUFa45hokgVMhHgEzKgY9QViVhVE1fzI3G7pVPobE2VmRBT8Luz0F8ItUaX GOew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=si15cZI906umHaHVrDsC4RY3Q50vVA4mNo2tUvU3Izg=; b=iW4j5ThHgWqXLU/I6nfwBj0XlJUyZ+/m0fz17IiBS/uHlbG6bLLX7v4nHd1K07qCVh SNQ0X+mMWL+Z943ptSZb6UA0f/jWYH6V6+xom/Hif+yPRxBAhYv+1SuOxBDtYW/0KO8Z e6TajUtquTCZcwGtVdz/gwraUAj99VdaBVB/FVrLyllLo75fqR3QjFlvVDOqs+ZOUbfp 1Axj/KPrizf1Ay/tmTRSn9yy6nqJNSUTBUWokXSoOJE8dQf51BleLqDScTsXo0ANmpmU 7MSPC32NjPRlqLI0yO77VpzAi1WuXxf6V4tO0o9DIOHWnju7usPoRGSNRB/BTR63nNlx IGvw== X-Gm-Message-State: AOAM530JRV1zvwuMjy7Y1OUs0UvxoOEjDhUBobZE8Z3hC3DKO+ncz9Xc Ky5QebMMWnNt0ufJD06YvZA= X-Google-Smtp-Source: ABdhPJy29tzmEp/xTkqO90x/t5Xh7MCJesr/Cr/J/QYt4qMNndmZE/47th/ite816DfuySys8HDb1g== X-Received: by 2002:a05:620a:22ed:: with SMTP id p13mr29899556qki.249.1614185979956; Wed, 24 Feb 2021 08:59:39 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:2c94:8b30:36b0:69d? ([2620:10d:c091:480::1:c7a4]) by smtp.googlemail.com with ESMTPSA id h3sm38684qtp.8.2021.02.24.08.59.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Feb 2021 08:59:38 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: modules & -fpreprocessed [PR 99072] Message-ID: Date: Wed, 24 Feb 2021 11:59:37 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" When we read preprocessed source, we deal with a couple of special location lines at the start of the file. These provide information about the original filename of the source and the current directory, so we can process the source in the same manner. When updating that code, I had a somewhat philosophical question: Should the line table contain evidence of the filename the user provided to the compiler? I figured to leave it there, as it did no harm. But this defect shows an issue. It's in the line table and our (non optimizing) line table serializer emits that filename. Which means if one re-preprocesses the original source to a differently-named intermediate file, the resultant CMI is different. Boo. That's a difference that doesn't matter, except the CRC matching then fails. We should elide the filename, so that one can preprocess to mktemp intermediate filenames for whatever reason. This patch takes the approach of expunging it from the line table -- so the line table will end up with exactly the same form. That seems a better bet than trying to fix up mismatching line tables in CMI emission. PR c++/99072 libcpp/ * init.c (read_original_filename): Expunge all evidence of the original filename. gcc/testsuite/ * g++.dg/modules/pr99072.H: New. diff --git c/gcc/testsuite/g++.dg/modules/pr99072.H w/gcc/testsuite/g++.dg/modules/pr99072.H new file mode 100644 index 00000000000..eda0c07f9e2 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99072.H @@ -0,0 +1,10 @@ +# 0 "REALNAME" +# 0 "" +# 0 "" +# 0 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 0 "" 2 +# 1 "REALNAME" + +// { dg-additional-options {-fmodule-header -fpreprocessed -fdump-lang-module-lineno} } +// { dg-final { scan-lang-dump { 4 source file names\n Source file\[0\]=REALNAME\n Source file\[1\]=\n Source file\[2\]=\n Source file\[3\]=/usr/include/stdc-predef.h\n} module } } diff --git c/libcpp/init.c w/libcpp/init.c index 17b0d251cda..68ed2c761b9 100644 --- c/libcpp/init.c +++ w/libcpp/init.c @@ -752,6 +752,23 @@ read_original_filename (cpp_reader *pfile) if (_cpp_handle_directive (pfile, token->flags & PREV_WHITE)) { read_original_directory (pfile); + + auto *penult = &linemap_check_ordinary + (LINEMAPS_LAST_MAP (pfile->line_table, false))[-1]; + if (penult[1].reason == LC_RENAME_VERBATIM) + { + /* Expunge any evidence of the original linemap. */ + pfile->line_table->highest_location + = pfile->line_table->highest_line + = penult[0].start_location; + + penult[1].start_location = penult[0].start_location; + penult[1].reason = penult[0].reason; + penult[0] = penult[1]; + pfile->line_table->info_ordinary.used--; + pfile->line_table->info_ordinary.cache = 0; + } + return true; } }