From patchwork Wed Nov 27 04:44:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 101943 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 4CEE53858D37 for ; Wed, 27 Nov 2024 04:46:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CEE53858D37 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VN18G1Gd 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 9D47F3858416 for ; Wed, 27 Nov 2024 04:45:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D47F3858416 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 9D47F3858416 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=1732682729; cv=none; b=H1BiaDKuUdGY8O4TROLJ/6ZCcY5oYHOOWEj/P2CEI48BgU5fdam99zjOxK9N94fvJYAdHJCpoHt2qqlX+FvRGjWJuxycxU068wHxqPv/Jl6HPeLRGEAFEXfn788A4ueJqPHXqBBl4ZHGEuQzBq7ZavEVKiFWZyLS6XUc/MKess4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732682729; c=relaxed/simple; bh=pUlk6XYdNsPgTuwAHnFoSlxj3NILS3BBavCrDvz+n1E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n5QZ/LghyxiDrcl61ljMF9AJbChQv/3cPltByOE6OwlHJp9yA1ZonLHV+7GX2ke5cn+l2X7Feb/DZS5b9yp7zrQczkU8W5yTLhPDDqyLIAlQ5wXd+7+ZkiYDSC+cw8PsOU4olJLIlKHUb4GOmFM/AQUF89M953x6aqiUiyqfGzI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D47F3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732682729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N9eT3E+j5mlhaxFY2uItTzCwph3h2/DAkOuX9zVconU=; b=VN18G1GdOkpWmiWwWkdAW4L1vMyDOm16xNQaB5IJ7N5UHEzle8pddj8ALFA77M9YRxBt2p +m0G33ALFLNdQhTNeVH+DNFxrSKhjMZ41kcoDa4+6mE38DmrPtlOjM/pjAbbQZv8ncnNa5 xLvdV01MHl+Z5By/ttA8SD1GtNCn3EI= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-a95HrlLVMuuUIvvHpfDF3A-1; Tue, 26 Nov 2024 23:45:27 -0500 X-MC-Unique: a95HrlLVMuuUIvvHpfDF3A-1 X-Mimecast-MFC-AGG-ID: a95HrlLVMuuUIvvHpfDF3A Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-466b72ca44eso3345221cf.0 for ; Tue, 26 Nov 2024 20:45:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732682726; x=1733287526; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N9eT3E+j5mlhaxFY2uItTzCwph3h2/DAkOuX9zVconU=; b=n4vDA5tQ9mpR2SkK8msvaKd5NGq+OPlAVMNYxBJ8JHKIttndPCgts2arcl/dOWs9nT SMgYLU5OyYQxWkBXcMHtXzgaYmyfyxx5/YBdVFpHFHC1DCleYJ+xGgT/cyS8b30nvOl4 K2QmJrJHI4/kP3GK2x/q+lBEDzKs2c5hrs+FKgMd2A27i7+pqacCv5BUVfa9GWw1EepR fiBjpToEC/1rc5bYeDfFNAWSahjgP98k8eMEaiqbIQYPZnxu0U4AO0sL8mlfyKm/nhlO U9f9VUxHmuAdMulAIVIPeNDa6/M5sCT1uoXF6mvFwbJ2qpMR4rkpyTImKDCrs7phelmD gviw== X-Gm-Message-State: AOJu0YzTwjK2GdCDPncibdkpVLiW8sO37verAZdHVzkfvaF3EN/BTcHG l2SDacNVq5isHfvjdzpY+ZCGB9KMsSdRKskrqvW5zjDQmbheZvYe7n2M3mU79a0OGDJ46CXNOtf haaO9C7wIiKOeyoT6llhv/ROFBpM2kziFT15Uf+PKOtHBJnyr3LTmwt8nakWGT8+V8txDxd1zrz NEXkXe8Mj2XmLLcMtAyZfvoENawQ08gbngVeg= X-Gm-Gg: ASbGncv6FsWRKaOd3lVXf9yOnKzEnIEKBsOJ9BoNtC5LkTN/eE9UrEWWq2BveZCeNd1 ZCz7evIfuNX2wNPJtW/G6JQj4Q/AOI05o+PC85AiPlRv272iCZF2oJ08tJgBUw+9TO+yl0BBdgk Y5FSBTpnQovg4GN20ekXBJXGTdDtK3PpZ5Wx9f82gL89tw8LZ7XuuigwhTD+YWXhz0OIaCs5xpy l1gHiCmOgjQsLR1m6uBbKOAV1NrX2qym+2yPLfGLZK37uymXqNdA0yZwmTxDZYHwR1BVSiRqzn1 TQ0Gyji2VkaMRH4oB/9ghNMpbnbR0q++ke6pGdTHeTyXpBoekv2NSAf8+FS/KXeifWQ1Zj/THXN iamk= X-Received: by 2002:a05:622a:4013:b0:466:adac:3f41 with SMTP id d75a77b69052e-466b36893c6mr33937461cf.50.1732682726251; Tue, 26 Nov 2024 20:45:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHl3i801/Xr61KbxUJTSc7jgkXR/L+tn3Ce2R1gkW9QG7iU8ZljQNybZYtfKa3Ouw80LCdeOQ== X-Received: by 2002:a05:622a:4013:b0:466:adac:3f41 with SMTP id d75a77b69052e-466b36893c6mr33937161cf.50.1732682725691; Tue, 26 Nov 2024 20:45:25 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4653c47f065sm66851061cf.61.2024.11.26.20.45.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 20:45:24 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] libcpp: modules and -include again Date: Tue, 26 Nov 2024 23:44:58 -0500 Message-ID: <20241127044522.3073603-1-jason@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FyHqIiHjklYSlQ7a_ZxL4lp630nD9Ccbd2yp195e_XY_1732682726 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- I enabled include translation to header units in r15-1104-ga29f481bbcaf2b, but it seems that patch wasn't sufficient, as any diagnostics in the main source file would show up as coming from the header instead. Fixed by setting buffer->file for leaving the file transition that my previous patch made us enter. And don't push a buffer of newlines, in this case that messes up line numbers instead of aligning them. libcpp/ChangeLog: * files.cc (_cpp_stack_file): Handle -include of header unit more specially. gcc/testsuite/ChangeLog: * g++.dg/modules/dashinclude-1_b.C: Add an #error. * g++.dg/modules/dashinclude-1_a.H: Remove dg-module-do run. --- gcc/testsuite/g++.dg/modules/dashinclude-1_b.C | 2 ++ libcpp/files.cc | 10 ++++++++-- gcc/testsuite/g++.dg/modules/dashinclude-1_a.H | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) base-commit: 819f67a2f633d2000f09119f0e19b784ea0a4bd8 diff --git a/gcc/testsuite/g++.dg/modules/dashinclude-1_b.C b/gcc/testsuite/g++.dg/modules/dashinclude-1_b.C index 6e6a33407a4..f257a1d658e 100644 --- a/gcc/testsuite/g++.dg/modules/dashinclude-1_b.C +++ b/gcc/testsuite/g++.dg/modules/dashinclude-1_b.C @@ -6,4 +6,6 @@ int main () return f(); } +#error foo // { dg-error "foo" } + // { dg-final { scan-lang-dump {Translating include to import} module } } diff --git a/libcpp/files.cc b/libcpp/files.cc index 1cbce4947ee..a60fe1fb6ea 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -977,8 +977,11 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, that. (We also need an extra newline, so this looks like a regular file, which we do that to to make sure we don't fall off the end in the middle of a line. */ - static uchar newlines[] = "\n\n\n"; - cpp_push_buffer (pfile, newlines, 2, true); + if (type != IT_CMDLINE) + { + static uchar newlines[] = "\n\n\n"; + cpp_push_buffer (pfile, newlines, 2, true); + } size_t len = strlen (buf); buf[len] = '\n'; /* See above */ @@ -986,6 +989,9 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, = cpp_push_buffer (pfile, reinterpret_cast (buf), len, true); buffer->to_free = buffer->buf; + if (type == IT_CMDLINE) + /* Tell _cpp_pop_buffer to change files. */ + buffer->file = file; file->header_unit = +1; _cpp_mark_file_once_only (pfile, file); diff --git a/gcc/testsuite/g++.dg/modules/dashinclude-1_a.H b/gcc/testsuite/g++.dg/modules/dashinclude-1_a.H index c1b40a53924..82ee340798f 100644 --- a/gcc/testsuite/g++.dg/modules/dashinclude-1_a.H +++ b/gcc/testsuite/g++.dg/modules/dashinclude-1_a.H @@ -1,4 +1,3 @@ -// { dg-module-do run } // { dg-additional-options "-fmodule-header" } // { dg-module-cmi {} }