From patchwork Mon Oct 19 15:00:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1384372 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; 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=Fwxn1ylP; 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 4CFKgw5gckz9sSC for ; Tue, 20 Oct 2020 02:00:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84953388A437; Mon, 19 Oct 2020 15:00:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by sourceware.org (Postfix) with ESMTPS id B753A3857C4F for ; Mon, 19 Oct 2020 15:00:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B753A3857C4F 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-qv1-xf29.google.com with SMTP id g13so10449qvu.1 for ; Mon, 19 Oct 2020 08:00:38 -0700 (PDT) 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=y4VCdPdbizpajKPBVJ1cJsS+oU0IdB8RfeL/pdMs2cs=; b=Fwxn1ylPjbxYTmvjuqTgZeH91O1jJ4+5tfH2VaDyv4HYlzoALQBOlPBt2X/DUqJuYy kft9iTvAYuG+6rsNrn7KZvoMKKs2/GYZC46sV94oWEx2c1fxySfOqaWUd2B71OwcMw1h rsEVmYHhuH1ldPS5Y7QCnitNC3ByA+rYMFQ54G8JYSXQiVyb3z6bNpc2C7qTYmvuEno/ e9DAAjfATWwkPRvZZ6icqhUUHf9X3QbAMG8cEHOyFiViFhpaw8IwIZuEPFngEn0PAOCj FuAVoFjK5llWPVSvwFvbWc9HoiYbotCDC7K5VQta8wS1+iYvVUH1M60CZP82SP1u7GgH wQmg== 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=y4VCdPdbizpajKPBVJ1cJsS+oU0IdB8RfeL/pdMs2cs=; b=K9wOr6PNz2qd6Hil4qvM44MxlZzhlC/NWIvxPA2vp09obE74ecnXtDmv/6oZFHXwlt YRceQxCzWh2u9Yp5cVLGJOx+qtQWpveOl+4P1zqeUfZG63mA3xy1XJpUdzjmA+/2ytO5 CRohi23IRgW5V/ScgQDBcVhDe7j5LcGVyyx/ynfV62Crcz8n3gABGg+B1pkc0+1smul1 /fPEOTkwZyabCMQxB2AnjzU7DsB2zrdJTPt+OCwbCSI+CpLqIUAvNp4q/n4/atCGCsiJ eJDOK3W7vuFYhZ54esbW3dQgfylL2fJoMXzHWTUV5QDRvnLnE3m8m2xD0ak2/f9Kg6JC apjA== X-Gm-Message-State: AOAM530qUXXTE2WJLgUfHUO2Jsc7kIEmBP9bhrL8X773UTDfL7Oluy/3 /B+jOwhSN3fDxmrZgWpdTwI= X-Google-Smtp-Source: ABdhPJzKQ38OwUBBe4+gVWgkdARUeNtoEvShqvWiD3dPXViF4ZK0GxF1D2stX7znR3Tnzup55nRuuw== X-Received: by 2002:a0c:a166:: with SMTP id d93mr147505qva.22.1603119637741; Mon, 19 Oct 2020 08:00:37 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:14b:cbd4:3b8:1eae? ([2620:10d:c091:480::1:99ae]) by smtp.googlemail.com with ESMTPSA id b33sm61265qtk.38.2020.10.19.08.00.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Oct 2020 08:00:35 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: preprocessor: Fix non-fn fn-like macro at EOF [PR97471] Message-ID: <22291356-353e-fe73-600c-ac985df58df2@acm.org> Date: Mon, 19 Oct 2020 11:00:34 -0400 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.1 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 inject EOF tokens between macro argument lists, but had confused/stale logic in the non-fn invocation. Renamed the magic 'eof' token, as it's now only used for macro argument termination. Always rewind the non-OPEN_PAREN token. libcpp/ * internal.h (struct cpp_reader): Rename 'eof' field to 'endarg'. * init.c (cpp_create_reader): Adjust. * macro.c (collect_args): Use endarg for separator. Always rewind in the not-fn case. gcc/testsuite/ * c-c++-common/cpp/pr97471.c: New. pushing to trunk, nathan diff --git c/gcc/testsuite/c-c++-common/cpp/pr97471.c w/gcc/testsuite/c-c++-common/cpp/pr97471.c new file mode 100644 index 00000000000..f1e512ea331 --- /dev/null +++ w/gcc/testsuite/c-c++-common/cpp/pr97471.c @@ -0,0 +1,10 @@ +/* PR preprocessor/97471 */ +/* { dg-do compile } */ + +/* ICE with non-fn use of fn-like macro at EOF */ + +#define a() b + +/* { dg-error "expected" "" { target c } .+2 } */ +/* { dg-error "does not name" "" { target c++ } .+1 } */ +a diff --git c/libcpp/init.c w/libcpp/init.c index 84c0a9efa74..454a183134a 100644 --- c/libcpp/init.c +++ w/libcpp/init.c @@ -248,8 +248,10 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table, /* Set up static tokens. */ pfile->avoid_paste.type = CPP_PADDING; pfile->avoid_paste.val.source = NULL; - pfile->eof.type = CPP_EOF; - pfile->eof.flags = 0; + pfile->avoid_paste.src_loc = 0; + pfile->endarg.type = CPP_EOF; + pfile->endarg.flags = 0; + pfile->endarg.src_loc = 0; /* Create a token buffer for the lexer. */ _cpp_init_tokenrun (&pfile->base_run, 250); diff --git c/libcpp/internal.h w/libcpp/internal.h index b728df74562..b1a2a996ef6 100644 --- c/libcpp/internal.h +++ w/libcpp/internal.h @@ -517,9 +517,9 @@ struct cpp_reader set to -1 to disable it or to a non-negative value to enable it. */ time_t source_date_epoch; - /* EOF token, and a token forcing paste avoidance. */ + /* A token forcing paste avoidance, and one demarking macro arguments. */ cpp_token avoid_paste; - cpp_token eof; + cpp_token endarg; /* Opaque handle to the dependencies of mkdeps.c. */ class mkdeps *deps; diff --git c/libcpp/macro.c w/libcpp/macro.c index 2c7d7322e09..9cb3b10a9a0 100644 --- c/libcpp/macro.c +++ w/libcpp/macro.c @@ -1241,7 +1241,8 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node, ntokens--; arg->count = ntokens; - set_arg_token (arg, &pfile->eof, pfile->eof.src_loc, + /* Append an EOF to mark end-of-argument. */ + set_arg_token (arg, &pfile->endarg, token->src_loc, ntokens, MACRO_ARG_TOKEN_NORMAL, CPP_OPTION (pfile, track_macro_expansion)); @@ -1328,17 +1329,12 @@ funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, return collect_args (pfile, node, pragma_buff, num_args); } - /* CPP_EOF can be the end of macro arguments, or the end of the - file. We mustn't back up over the latter. Ugh. */ - if (token->type != CPP_EOF || token == &pfile->eof) - { - /* Back up. We may have skipped padding, in which case backing - up more than one token when expanding macros is in general - too difficult. We re-insert it in its own context. */ - _cpp_backup_tokens (pfile, 1); - if (padding) - _cpp_push_token_context (pfile, NULL, padding, 1); - } + /* Back up. We may have skipped padding, in which case backing + up more than one token when expanding macros is in general + too difficult. We re-insert it in its own context. */ + _cpp_backup_tokens (pfile, 1); + if (padding) + _cpp_push_token_context (pfile, NULL, padding, 1); return NULL; }