From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by sourceware.org (Postfix) with ESMTPS id 3BA2B3858C98 for ; Wed, 28 Feb 2024 00:03:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BA2B3858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3BA2B3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709078605; cv=none; b=q9BkxjfnOfhsAm+LAXem763bQtVhzy049qR2yS+HMqHiZM1MKi+2vqu/2twuQyI3dwh6MHtdmYPWUc2awWxZC3cVdx4d18wBj6HA9vii9JhVB0O8vJ/JioKce+em03sA+mj4NgTA8rcsEes6CcRSG/nY0eJB/FzseF3BnApps7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709078605; c=relaxed/simple; bh=aso5iVfG5XwkgV1grE1ngXQ1M5kz/UyKzB1/b3cH/qc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=Jx0QPGaD4FKhcoNt8o46JwbnAQHEEtU39LbpP/R3KLwZuPTNnEf9Np9Wpw0LvGDtPSAyuf/ZSy5BQ0oRV6IGv6rneT9nnllF75uFSxPVtrj+jDbOKU2EzlI9YSgqv81Ury1A/x2QBB6xggFcKOA9p8NCNTTEswbiC53YiGANKBo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-dcbf82cdf05so5027023276.2 for ; Tue, 27 Feb 2024 16:03:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709078602; x=1709683402; darn=gcc.gnu.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XFS2Npd87hwS3WG8CHPjquAyAbo8gPFDYJbj/OEtijs=; b=nXgb5eX+xU59WgmaKZZgEUMmRfDOBLG8KBsPDLc6hVpqx3FGNoU0JgvNteEvetNi4n 1vT/gvP/4ahkzuudqSt9xY3TZ4V7TIgvmhMgMBBfL90uhHtkov9VlN1DJvAfGNN6CLl9 UvRJQYugnnJY1JjMIigtdcsZTV7r44jkegwLbdk+fryvOLrF6atQT+mVshzcMrAfNQjy szl1TD97KNKtod0wQ/POmrLEnpjgU53gIaS4FBrViuMG5Dc1191xSpN00hVrDvwvKx2j IhAvmGe/s2aokj45AnAseMBlRuaooC9nbR9zzhMPl9PoqjRQ5UAXxokGH8ouX9b3cF5/ MTGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709078602; x=1709683402; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XFS2Npd87hwS3WG8CHPjquAyAbo8gPFDYJbj/OEtijs=; b=GVVb/PluLVTiHjqkDYnxAmBzsisJ9tXFfkdbJHbcHpm5I5GV+MFWj0MYMgRP0t/4cP X36KNrZhbkxdBWPKw2iAFXd3UxO3S/hSO3YxUPATWaW7v825XUAORfdzvUc20O4Y4ENu Eq6d6DWRpCuamQ6ytckTSFtmGrm6IUZc4MaPonog0Dlyp85bkeU1AcG5yRQC9JXSiV2Z Smu7qwAO/r9Y8Ya/q77tV6BnFzbOaDFUurggOyKwYLKtZK943Vfb/8XK1csXuW+O1cFk rArqIA6v1WlCpdqCW4WjB0bOlH4zydJLXZY1WPiIhWOJ1Xh8bh26uIh2ZgjF+V8iGc0n /kBw== X-Gm-Message-State: AOJu0YyTbFx8JjDkuqR4tsIMeYXHEi9lZS2+BR56pftyJZTXKYAILV1p YEpC/qH9zWOkqQy5s1CaAaoz8Wv7qeC5Ztp1yKFjIFFJBrhebk7xLZGQ2QvaPP5YdB3NDCWJ+Z0 4KTsENZZQCC9p6u1MVQ64E6W0tFeMEgXF X-Google-Smtp-Source: AGHT+IHs06AkLaobFzkgr/3tDFz0stTBViGz92xUiAoOEKIZKk8t52KtUiNO5PuhVV1Iz2yAE85L66T8KZfXp6l/wYo= X-Received: by 2002:a25:8682:0:b0:dcc:6d85:586a with SMTP id z2-20020a258682000000b00dcc6d85586amr977633ybk.49.1709078602484; Tue, 27 Feb 2024 16:03:22 -0800 (PST) MIME-Version: 1.0 References: <20231221123750.2303405-1-lhyatt@gmail.com> In-Reply-To: From: Lewis Hyatt Date: Tue, 27 Feb 2024 19:03:10 -0500 Message-ID: Subject: Re: ping: [PATCH] libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755] To: gcc-patches List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3035.6 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,T_SCC_BODY_TEXT_LINE 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- https://gcc.gnu.org/pipermail/gcc-patches/2023-December/641247.html There was a request on the PR (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80755#c5) for me to ping this again, so I am complying :). Might anyone have a minute to take a look please? Thanks... -Lewis On Thu, Jan 11, 2024 at 7:34=E2=80=AFAM Lewis Hyatt wrot= e: > > Can I please ping this one? Thanks... > https://gcc.gnu.org/pipermail/gcc-patches/2023-December/641247.html > > -Lewis > > On Thu, Dec 21, 2023 at 7:37=E2=80=AFAM Lewis Hyatt wr= ote: > > > > Hello- > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80755 > > > > Here is a short fix for the ICE in libcpp noted in the PR. Bootstrap + > > regtest all languages on x86-64 Linux. Is it OK please? Thanks! > > > > -Lewis > > > > -- >8 -- > > > > In libcpp/files.cc, the function _cpp_has_header(), which implements > > __has_include and __has_include_next, does not check for a NULL return = value > > from search_path_head(), leading to an ICE tripping an assert when > > _cpp_find_file() tries to use it. Fix it by checking for that case and > > silently returning false instead. > > > > As suggested by the PR author, it is easiest to make a testcase by usin= g > > the -idirafter option. To enable that, also modify the dg-additional-op= tions > > testsuite procedure to make the global $srcdir available, since -idiraf= ter > > requires the full path. > > > > libcpp/ChangeLog: > > > > PR preprocessor/80755 > > * files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument > > defaulting to false. > > (_cpp_has_header): Silently return false if the search path has= been > > exhausted, rather than issuing a diagnostic and then hitting an > > assert. > > > > gcc/testsuite/ChangeLog: > > > > * lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable= in a > > dg-additional-options directive. > > * c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h:= New test. > > * c-c++-common/cpp/has-include-next-2.c: New test. > > --- > > libcpp/files.cc | 12 ++++++++---- > > .../cpp/has-include-next-2-dir/has-include-next-2.h | 3 +++ > > gcc/testsuite/c-c++-common/cpp/has-include-next-2.c | 4 ++++ > > gcc/testsuite/lib/gcc-defs.exp | 1 + > > 4 files changed, 16 insertions(+), 4 deletions(-) > > create mode 100644 gcc/testsuite/c-c++-common/cpp/has-include-next-2-d= ir/has-include-next-2.h > > create mode 100644 gcc/testsuite/c-c++-common/cpp/has-include-next-2.c > > > > diff --git a/libcpp/files.cc b/libcpp/files.cc > > index 27301d79fa4..aaab4b13a6a 100644 > > --- a/libcpp/files.cc > > +++ b/libcpp/files.cc > > @@ -181,7 +181,8 @@ static bool read_file_guts (cpp_reader *pfile, _cpp= _file *file, > > static bool read_file (cpp_reader *pfile, _cpp_file *file, > > location_t loc); > > static struct cpp_dir *search_path_head (cpp_reader *, const char *fna= me, > > - int angle_brackets, enum include_type)= ; > > + int angle_brackets, enum inclu= de_type, > > + bool suppress_diagnostic =3D f= alse); > > static const char *dir_name_of_file (_cpp_file *file); > > static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int, > > location_t); > > @@ -1041,7 +1042,7 @@ _cpp_mark_file_once_only (cpp_reader *pfile, _cpp= _file *file) > > nothing left in the path, returns NULL. */ > > static struct cpp_dir * > > search_path_head (cpp_reader *pfile, const char *fname, int angle_brac= kets, > > - enum include_type type) > > + enum include_type type, bool suppress_diagnostic) > > { > > cpp_dir *dir; > > _cpp_file *file; > > @@ -1070,7 +1071,7 @@ search_path_head (cpp_reader *pfile, const char *= fname, int angle_brackets, > > return make_cpp_dir (pfile, dir_name_of_file (file), > > pfile->buffer ? pfile->buffer->sysp : 0); > > > > - if (dir =3D=3D NULL) > > + if (dir =3D=3D NULL && !suppress_diagnostic) > > cpp_error (pfile, CPP_DL_ERROR, > > "no include path in which to search for %s", fname); > > > > @@ -2164,7 +2165,10 @@ bool > > _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brack= ets, > > enum include_type type) > > { > > - cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_bracket= s, type); > > + cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_bracket= s, type, > > + /* suppress_diagnostic =3D */ = true); > > + if (!start_dir) > > + return false; > > _cpp_file *file =3D _cpp_find_file (pfile, fname, start_dir, angle_b= rackets, > > _cpp_FFK_HAS_INCLUDE, 0); > > return file->err_no !=3D ENOENT; > > diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-= include-next-2.h b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/ha= s-include-next-2.h > > new file mode 100644 > > index 00000000000..1e4be6ce7a3 > > --- /dev/null > > +++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-include= -next-2.h > > @@ -0,0 +1,3 @@ > > +#if __has_include_next() > > +/* This formerly led to an ICE when the current directory was the last= one in the path. */ > > +#endif > > diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c b/gcc/= testsuite/c-c++-common/cpp/has-include-next-2.c > > new file mode 100644 > > index 00000000000..4928d3e992c > > --- /dev/null > > +++ b/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c > > @@ -0,0 +1,4 @@ > > +/* PR preprocessor/80755 */ > > +/* { dg-do preprocess } */ > > +/* { dg-additional-options "-idirafter $srcdir/c-c++-common/cpp/has-in= clude-next-2-dir" } */ > > +#include > > diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-def= s.exp > > index fc569c18ad5..091520ff69e 100644 > > --- a/gcc/testsuite/lib/gcc-defs.exp > > +++ b/gcc/testsuite/lib/gcc-defs.exp > > @@ -280,6 +280,7 @@ if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)]= \ > > > > proc dg-additional-options { args } { > > upvar dg-extra-tool-flags extra-tool-flags > > + global srcdir > > > > if { [llength $args] > 3 } { > > error "[lindex $args 0]: too many arguments"