From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 6DEF83858C53 for ; Tue, 7 Mar 2023 21:54:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DEF83858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x229.google.com with SMTP id h3so14645566lja.12 for ; Tue, 07 Mar 2023 13:54:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678226046; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ANhf24g350UJwysi4wZW38J/pJ8UuIZoeelBzSv45d0=; b=fxDWafXHecrG62d1sov8fO//Bbm3sJWaVnu3pd96OVjrPyHCPfnfzavoRsVhvqca6V U6KJhD7bi8jNEKYVF7VGHpWou97P/WlVOo2M8bE/ZlwSGngTbcNG0vChhTTxPxGO/WFb gLL2pdQeNa7jtXDKJYLNGEnENMoozKDfFhbGPXgjsjWQRsmrKvx7UFFo30P5D7eoUhEc ZnV2/Kh5eY1m8KUPX7dpw5hK0bwDVzfGFKcOxTKK6ep1sJtec/glo2VEBLsBk7e0Ivfp /StUdX55Dz5Ul2tedsX+ABb4jQM+3Ito5Hqxg8TEcxn5wUPjreM2sJRy3xqYrDSnHP6G YTuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678226046; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ANhf24g350UJwysi4wZW38J/pJ8UuIZoeelBzSv45d0=; b=1zxVuYapP030WJDlSXwRvtKYhdK75QoEOBQHNyw6e7BuA1PAXx3L3+8DWSed9c7m6X sGds6pcG0khDm/xH17NkPgaSDLOWn1eOXyidbBPBwqDBy8Aqcz791vbPAZM6ZgTJ4vcc /uvgxPq884dmp0HmHVsM09hImooRtkbEIFH4bdsQQ0v91UyuyF9IcOq+7nGY4ojcS+MK lMZn5FBLk5soZfaMxyppxepr9r6c8tB/fHisHz0JzadJDgHoOTzoFMq3FdsGX6+JVuOb X3NrPX2bjmwGj0q8hZzlUIXO6NsNQIIxM1CwE9ebbbBcOZaMI/E/7m8ECCUfDHo53uFE 8Epw== X-Gm-Message-State: AO0yUKUphPQaWJ3vmmSXy3B+gh0XKUI/LrbU/zCdHkCMpl6wDRoHQyUU qGtINkvhje1qtB247MaA0/khkHDvrFhR+tqSerqeH8vr X-Google-Smtp-Source: AK7set8LCFoRLB0KoTR/TtdIRHFqRwLIf2DwmwyCNZSxFbPo/+ryo3gCTC/3dyBpeEkWg/d/wwS/jngjH0L6l3Dm+sE= X-Received: by 2002:a05:651c:b93:b0:295:944c:f37e with SMTP id bg19-20020a05651c0b9300b00295944cf37emr4954644ljb.9.1678226046420; Tue, 07 Mar 2023 13:54:06 -0800 (PST) MIME-Version: 1.0 From: Lewis Hyatt Date: Tue, 7 Mar 2023 16:53:55 -0500 Message-ID: Subject: Ping: [PATCH] libcpp: Fix ICE on directive inside _Pragma() operator [PR67046] To: gcc-patches List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3035.5 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 List-Id: Hello- May I please ping this short patch that fixes an old bug? Thanks... -Lewis On Sat, Jan 14, 2023 at 1:46=E2=80=AFPM Lewis Hyatt wrot= e: > > get__Pragma_string() in directives.cc is responsible for lexing the paren= s > and the string argument from a _Pragma("...") operator. This function doe= s > 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 usin= g > 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 t= o > 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=3D67046 > > This fixes an old ICE in libcpp that can happen when lexing the token= s 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 pare= nthesis > + ended up on a different line. */ > + ++pfile->keep_tokens; > const cpp_token *string =3D get__Pragma_string (pfile); > + --pfile->keep_tokens; > + > pfile->directive_result.type =3D CPP_PADDING; > > if (string)