From patchwork Sat Jan 14 18:46:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 43787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp404809wrn; Sat, 14 Jan 2023 10:47:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXswdCWDOzse76q5p26JwcuJkEOb3e9mnGK2tR7SUWAYIXK5kbhb4p3QNWafR56xfaBbaPzS X-Received: by 2002:a17:907:a68a:b0:7c1:4d35:a143 with SMTP id vv10-20020a170907a68a00b007c14d35a143mr8244476ejc.3.1673722056068; Sat, 14 Jan 2023 10:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673722056; cv=none; d=google.com; s=arc-20160816; b=oeSQYA4HwApJ3RzXTXUGl2JCCZ/oPSsvzpkyfMR9ugRxm7ZWNfYZqoRb4q92bFBLo5 x2TQ+KCIaRiofqYyUA+ZWRAmkJhBlCjqZFZkXX4Lwx6OqN7lBHbajwzLvFChtxoVtzaF 8U82WtKfhxXaQ7Babky2h6PWrFEVc8094ks0Bkbh5DPUCMYXQRWih8R38USkfc0pIx14 5mBRNbZgY6ct0uZxq3EeVVAmJnJOWWBhlGJbXyGEwC00Kjk8Tbsg7xMzDV64T5v7I+/B RCOXsPSkI7bfKz3MZ/wLlmAhDqOwJy4GcGaI6Rz6fxw2dciFT6TQbW5Zfd1k3SLsEZnm Q/dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vyPAeaC3eoXGPSsGMy4eWEvK2CtPJKXqf22zauaH4/E=; b=D5CPS1IDvZVSAEGPyNXS+HXsLNI5KbY4OABlaUUglLlZa77WTRGGFhBBK2zRdxfTyQ Ft3A3MOW0DSDLJmANdF7HAwK3tlG+o79bv5HUYjj2Hl1jAP+z927QqIER8POxpOPa4QB TDxAxQIfxGUZFsHhpCLiMOf/QU8qiDheK1N93mpC+N6ORWUbKfMjvD/IAn1D2jvUK5RS DK0Pi6DH+whIIl0UXrOWN07eAqc8XJM/7PUlyq4RouaSCy8o8kfQx9NJnNviEvI3Jt+j CJr4ow+sw67nn2nbAYUn8lC2PHH0IeliB3jUSITuch4kvKUiMDFHFqJ2JruylI3iuWbE s1hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lH3XpmiH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l6-20020a170906794600b007c0a4c149bfsi1499860ejo.403.2023.01.14.10.47.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 10:47:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lH3XpmiH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13ACD3858CDA for ; Sat, 14 Jan 2023 18:47:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13ACD3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673722055; bh=vyPAeaC3eoXGPSsGMy4eWEvK2CtPJKXqf22zauaH4/E=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lH3XpmiH+6AozI1g4jHXR7EN/XI+bt7NeqV/QkHlCVJ3Iq5cvgzMlpsdBcXIJLRCa kQVKDRIdSVt4n117neK2C6YSmJPf+CiJrxvG1GHWlvasktOZ90ON07I+FCN52GFZFL +y0IkSFBxSl45gnkpV/1CCVsKA5NArQotiVfOTrI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id C209A3858D1E for ; Sat, 14 Jan 2023 18:46:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C209A3858D1E Received: by mail-qt1-x829.google.com with SMTP id h21so21555614qta.12 for ; Sat, 14 Jan 2023 10:46:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vyPAeaC3eoXGPSsGMy4eWEvK2CtPJKXqf22zauaH4/E=; b=jGkp93G3HY9X1yTNkuDcNrVd02De53BHQm70X0Jced8CLUbIXDES9KlhklxztXpgI0 nJUSkqdSqyV4s1E0sEj7hS6G0Boa1Vlh70uMFC0ftPsb6uWkRSec/jtxhjYcKl21GZWT ZA+MZxNdxHone2APfKaSUHkIFGgrXHCW/rU6JjtRXF05/tZs3ozI31k/1erHQwlgv/U4 5+9twfAq4NqKcrRzgKLJcSYHHW389BcAuI20/ultDZHBv9XTU7ykHA53iYHmA5sqxjvu y5s1iGWDf4vLletSHYz90BlETu0LEyHQVTy/O+kBgxh10HXPDnDBkG+x+8UMhn6V8s1C ezfw== X-Gm-Message-State: AFqh2ko2rtJBRypP7ciXC8IoSTSXM37yOApAe0ZKE79FPGcL+qQ3IjXY wTR43bFTiAqqmUWlOEeNF8YLc/CQinY= X-Received: by 2002:ac8:5a85:0:b0:3ab:b6cd:3758 with SMTP id c5-20020ac85a85000000b003abb6cd3758mr91393759qtc.54.1673722001016; Sat, 14 Jan 2023 10:46:41 -0800 (PST) Received: from localhost.localdomain (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id bi1-20020a05620a318100b006fb0e638f12sm14971692qkb.4.2023.01.14.10.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 10:46:40 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH] libcpp: Fix ICE on directive inside _Pragma() operator [PR67046] Date: Sat, 14 Jan 2023 13:46:24 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3038.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lewis Hyatt via Gcc-patches From: Lewis Hyatt Reply-To: Lewis Hyatt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755024778715591292?= X-GMAIL-MSGID: =?utf-8?q?1755024778715591292?= get__Pragma_string() in directives.cc is responsible for lexing the parens and the string argument from a _Pragma("...") operator. This function does not handle the case when the closing paren is not on the same line as the string; in that case, libcpp will by default reuse the token buffer it previously used for the string, so that the string token returned by get__Pragma_string() may be corrupted, as shown in the testcase. Fix using the existing keep_tokens mechanism that temporarily disables the reuse of token buffers. libcpp/ChangeLog: PR preprocessor/67046 * directives.cc (_cpp_do__Pragma): Increment pfile->keep_tokens to ensure the returned string token is valid. gcc/testsuite/ChangeLog: PR preprocessor/67046 * c-c++-common/cpp/pr67046.c: New test. --- Notes: Hello- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67046 This fixes an old ICE in libcpp that can happen when lexing the tokens from a _Pragma operator. Bootstrapped+tested on x86-64 Linux with no regressions. Please let me know if it's OK? Thanks... -Lewis gcc/testsuite/c-c++-common/cpp/pr67046.c | 10 ++++++++++ libcpp/directives.cc | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/cpp/pr67046.c diff --git a/gcc/testsuite/c-c++-common/cpp/pr67046.c b/gcc/testsuite/c-c++-common/cpp/pr67046.c new file mode 100644 index 00000000000..f37f20c624e --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr67046.c @@ -0,0 +1,10 @@ +/* { dg-do preprocess } */ + +_Pragma( +"message(\"msg\")" +) + +_Pragma( +"message(\"msg\")" +# +) diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 9dc4363c65a..ffd262bce7d 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -1996,7 +1996,12 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in, int _cpp_do__Pragma (cpp_reader *pfile, location_t expansion_loc) { + /* Make sure we don't invalidate the string token, if the closing parenthesis + ended up on a different line. */ + ++pfile->keep_tokens; const cpp_token *string = get__Pragma_string (pfile); + --pfile->keep_tokens; + pfile->directive_result.type = CPP_PADDING; if (string)