From patchwork Mon Dec 14 15:23:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1416005 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; dmarc=none (p=none dis=none) header.from=acm.org 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=t2jQBIPS; 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 4CvlXw2tSzz9sSf for ; Tue, 15 Dec 2020 02:23:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 723483854834; Mon, 14 Dec 2020 15:23:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id 4FCC53857C61 for ; Mon, 14 Dec 2020 15:23:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4FCC53857C61 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-x836.google.com with SMTP id b9so12064177qtr.2 for ; Mon, 14 Dec 2020 07:23:53 -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=6G9wB7KaIgCfgWqtyR8/RvAYIzZfwPIN96X8DhxDYzE=; b=t2jQBIPSivEzhzxHUXQ4inEx8yi71CyBB7dPPIVGa6VB5L8Uw7KWxT5VWBQ98qcrkx Jb1pwBXH0P7BMZZfTkdDbdQ7MnFkHvl6rfUhHT77dq1pTgzc/g+VmaAynnR13I3CkKz+ msulySxbb9y531JH3g6yapzzYU1To85sBZaJsqwATA9ElNOExW4QITtS17gNWh9UK2Vq 5UjT89dBYweHBLK8c05JuN9xkLpXDI08QOCNCFN4/OX/IlLVF4d2+FqU3FEu5x8kmQY/ aiqNee14a8acbi7X31cBVP6DVX1vIxl4/TCQLAMpEVjCOw7NPJPy7iYfkcMWF+G7Gybf Dn1Q== 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=6G9wB7KaIgCfgWqtyR8/RvAYIzZfwPIN96X8DhxDYzE=; b=Jg6AjhSpC1XY8x/ilk1/Tp7kM/Id11ymUXyGFsO54MuzcyRNPSd0USWV2DBIGt8wvw QZmj+SbAgHA+XuuzcAdCgp22ApU+/t+nyPwgwGHrCvCs/9SpM9O7ke7DiYnF9mrSVN0d NS6j3YFCSSmyO1+/uDiakHbREaYXOMj1MxdGbkNTw20nBEjGIZGgeFrDUHh8AN4/82dk eTp+rqeCGUkHFmGqDUGpAmS8iGWGpkWq1QoFNfNxkjVKqS/36qT7ZF+WS2J54Q2uTyiN bHS0fXRSd3v5/p4oXONwen90iAVEg9xHRWY22t5jjj+8/jgaqThjrmPE1SwBH3SGClgf bfkA== X-Gm-Message-State: AOAM533YsSseUozPfXNJ92fW8cFyATwCwk23RMqzbrU0jy7n/Ab70+gh E58qxqkHuwsiMKmFyJ+jNVw= X-Google-Smtp-Source: ABdhPJw5uxPpLwRPZpXr/OwUffJokRqDdzv96asR5rmUM3+7z1P+JQ8Y8UpgqAbgSxvN3sdKHC0A3A== X-Received: by 2002:ac8:478d:: with SMTP id k13mr30518051qtq.279.1607959432518; Mon, 14 Dec 2020 07:23:52 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:dd49:df09:c3cb:75b0? ([2620:10d:c091:480::1:1493]) by smtp.googlemail.com with ESMTPSA id q20sm14874969qkj.49.2020.12.14.07.23.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Dec 2020 07:23:51 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: preprocessor: Deferred macro support Message-ID: <0d67748d-5ab5-ad22-de3a-b2a147a828c5@acm.org> Date: Mon, 14 Dec 2020 10:23:50 -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=-10.9 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" For deferred macros we also need a new field on the macro itself, so that the module machinery can determine the macro was imported. Also the documentation for the hashnode's deferred field was incomplete. libcpp/ * include/cpplib.h (struct cpp_macro): Add imported_p field. (struct cpp_hashnode): Tweak deferred field documentation. * macro.c (_cpp_new_macro): Clear new field. (cpp_get_deferred_macro, get_deferred_or_lazy_macro): Assert more. pushing to trunk diff --git i/libcpp/include/cpplib.h w/libcpp/include/cpplib.h index 692aee58d19..50d28dc9d5a 100644 --- i/libcpp/include/cpplib.h +++ w/libcpp/include/cpplib.h @@ -826,7 +826,10 @@ struct GTY(()) cpp_macro { tokens. */ unsigned int extra_tokens : 1; - /* 1 bits spare (32-bit). 33 on 64-bit target. */ + /* Imported C++20 macro (from a header unit). */ + unsigned int imported_p : 1; + + /* 0 bits spare (32-bit). 32 on 64-bit target. */ union cpp_exp_u { @@ -921,9 +924,11 @@ struct GTY(()) cpp_hashnode { /* 5 bits spare. */ - /* On a 64-bit system there would be 32-bits of padding to the value + /* The deferred cookie is applicable to NT_USER_MACRO or NT_VOID. + The latter for when a macro had a prevailing undef. + On a 64-bit system there would be 32-bits of padding to the value field. So placing the deferred index here is not costly. */ - unsigned deferred; /* Deferred index, (unless zero). */ + unsigned deferred; /* Deferred cookie */ union _cpp_hashnode_value GTY ((desc ("%1.type"))) value; }; diff --git i/libcpp/macro.c w/libcpp/macro.c index 05755859cd6..cdb182112bc 100644 --- i/libcpp/macro.c +++ w/libcpp/macro.c @@ -3708,6 +3708,7 @@ _cpp_new_macro (cpp_reader *pfile, cpp_macro_kind kind, void *placement) macro->used = !CPP_OPTION (pfile, warn_unused_macros); macro->count = 0; macro->fun_like = 0; + macro->imported_p = false; macro->extra_tokens = 0; /* To suppress some diagnostics. */ macro->syshdr = pfile->buffer && pfile->buffer->sysp != 0; @@ -3791,6 +3792,8 @@ cpp_macro * cpp_get_deferred_macro (cpp_reader *pfile, cpp_hashnode *node, location_t loc) { + gcc_checking_assert (node->type == NT_USER_MACRO); + node->value.macro = pfile->cb.user_deferred_macro (pfile, loc, node); if (!node->value.macro) @@ -3807,11 +3810,9 @@ get_deferred_or_lazy_macro (cpp_reader *pfile, cpp_hashnode *node, if (!macro) { macro = cpp_get_deferred_macro (pfile, node, loc); - if (!macro) - return NULL; + gcc_checking_assert (!macro || !macro->lazy); } - - if (macro->lazy) + else if (macro->lazy) { pfile->cb.user_lazy_macro (pfile, macro, macro->lazy - 1); macro->lazy = 0;