From patchwork Tue Feb 16 20:26:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1441108 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=8.43.85.97; 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=d5E+MHbP; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (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 4DgCDK5kr4z9rx8 for ; Wed, 17 Feb 2021 07:26:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30CC23988805; Tue, 16 Feb 2021 20:26:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 60636383F879 for ; Tue, 16 Feb 2021 20:26:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 60636383F879 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-qt1-x834.google.com with SMTP id e15so7988595qte.9 for ; Tue, 16 Feb 2021 12:26:16 -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=P8O+Gx5qyDsDStfG/YAV1Ld8Wz6+EjUiOJvRYtCQsoE=; b=d5E+MHbPH34bGtDw0cMx9ARaeWKL4FoEGWocpSkIaf0bISsSaVLymi4aq3fvy1bt9B Zmhoen1wGDPrUIVGO7SYxUDWHVj27O1Cbj8wthXHkvwFdHo9kozq/QewoVRK4NFu/at5 9EZKoKs0dGX4Bf4pHCeUY2NmPD/n+fVljzx0+HKev1nGeg6ahMk4fQ+/nhzG0Up/PLO7 P6ODLpHttXwM7Wa8qMKQ9+NbNxyYZkO2y4+MzESNxkYNzJsRhV4rCfpjmnCuCg4f+tpG e5wNx3bI56jegq+X6iC+jBxnpVxz3vNtl681N/MaA8Nz7p2k9h9CncCrGiEpEEYeXS8I 9nzQ== 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=P8O+Gx5qyDsDStfG/YAV1Ld8Wz6+EjUiOJvRYtCQsoE=; b=WUzp19Up47SrN8ISlWamsH8Pb6AM9adzdxIPtg6q3Mbmg38S9py+hvvNWGfYjONgjL Cdmj2qIoZY4hgOEjGWJNNyPwS3wFK+v1+6+vxWpcbC8/rEPzI6QUmK3uZfZgheg3J8R2 wUlEt0yzLbT/lDJwd85bxoTr1y3Ja03H09RMqXguFdGn1nVIESvxaIcJ+IqXquc/tzW2 YMeC7veBzKpdFY3ldI8kY8qMZNcSvQaGibdMGqqCU/hzEWHCc+1zwn3wLhU/Td01UWSR nxdly5Pt5obnIEwAMS0KRQGR4++ucQK3XaZogW2DQMcBaDzi4rxvHBCAEH9U44MTqfnz Ev5w== X-Gm-Message-State: AOAM532XxZfBPvm35hBVlNAljmfarxqwnZXCXz7B8oFi3VdsI3qnXeDD zUdiieA3TWjP42dhvrLdYho= X-Google-Smtp-Source: ABdhPJwB6dKlXwOWIU8uHHBzLveSqnFP6OedR6gZE2HvbhPjMhH+5l9mco6vuqruMq9cbYkTZiFlbQ== X-Received: by 2002:a05:622a:183:: with SMTP id s3mr20844293qtw.223.1613507175925; Tue, 16 Feb 2021 12:26:15 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:a074:e186:6b89:877d? ([2620:10d:c091:480::1:6fa]) by smtp.googlemail.com with ESMTPSA id d14sm14179174qtc.25.2021.02.16.12.26.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Feb 2021 12:26:14 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: directives-only preprocessing and include translation [PR 99050] Message-ID: <17dabded-a9ec-514b-5eea-bf09b47e1f16@acm.org> Date: Tue, 16 Feb 2021 15:26:13 -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" We make sure files end in \n by placing one at the limit of the buffer (just past the end of what is read). We need to do the same for buffers generated via include-translation. Fortunately they have space. libcpp/ * files.c (_cpp_stack_file): Make buffers end in unread \n. gcc/testsuite/ * g++.dg/modules/pr99050_a.H: New. * g++.dg/modules/pr99050_b.C: New. diff --git c/gcc/testsuite/g++.dg/modules/pr99050_a.H w/gcc/testsuite/g++.dg/modules/pr99050_a.H new file mode 100644 index 00000000000..137e37f567f --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99050_a.H @@ -0,0 +1,4 @@ +// PR c++/99050 ICE with directives only +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } +void f (); diff --git c/gcc/testsuite/g++.dg/modules/pr99050_b.C w/gcc/testsuite/g++.dg/modules/pr99050_b.C new file mode 100644 index 00000000000..439e216eb16 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr99050_b.C @@ -0,0 +1,7 @@ +// { dg-do preprocess } +// { dg-additional-options {-fdirectives-only -fmodules-ts} } +#include "pr99050_a.H" + +int main () {} + +// { dg-final { scan-file pr99050_b.i {import "[^\n]*99050_a.H" \[\[__translated\]\];\n} } } diff --git c/libcpp/files.c w/libcpp/files.c index 5ea3f8e1bf3..3a35f7c9743 100644 --- c/libcpp/files.c +++ w/libcpp/files.c @@ -918,13 +918,17 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, because we don't usually need that location (we're popping an include file). However in this case we do want to do the increment. So push a writable buffer of two newlines to acheive - that. */ - static uchar newlines[] = "\n\n"; + 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); + size_t len = strlen (buf); + buf[len] = '\n'; /* See above */ cpp_buffer *buffer = cpp_push_buffer (pfile, reinterpret_cast (buf), - strlen (buf), true); + len, true); buffer->to_free = buffer->buf; file->header_unit = +1;