From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id 52C3C385E02D for ; Thu, 11 Jan 2024 12:35:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52C3C385E02D 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 52C3C385E02D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704976504; cv=none; b=iyIdUL/gIVQ5MSMhhwWKoYPEMin+9PyDqvJi3cgbda9Qi8O4KaKx23lR94dyOR4is6BDzZh0JCiFz7C/mAKb+RZW+c99UZvimfXt93g7fvlX1CU8rYQ2oxqmbcan678LqOQlNk8XiDro1MrX8p8YRWnbYl14IPZyHQF3zqLqKb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704976504; c=relaxed/simple; bh=KFZTlQ7DhharGIckiDjPGwxYYrohXC1hbx5D/BxZof4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=AalML/48dM5zNiML2ZWt5AW5Uco57PzgRVBX9RibNtPAI8R8PMnD2eMHNx/UX+yXKxqPCb0wk8fPpEPn4OXI3NsTsPNwca4AUZB0tVY2q6ZLDnMA2hw6LLV9NoO4KWoGLQweRlyXxx2pmEdwDrdxniuQRKl6UiE3gTrjyZjX0DI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-dae7cc31151so4086248276.3 for ; Thu, 11 Jan 2024 04:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704976500; x=1705581300; 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=GXp+bXDP93XJesAHud7x2yMyvhqQCG8/Azuke0kj93M=; b=gCL8eLgOuwbXw6OPnB2JGkv0hzmYdHQvoQPZucYIr6PD4JUs+Lwxzd4RORlupYxxZl zRcxCQOAx4mKn404DDgJMaMmPkCX+cUI5BS3GUlt0s/ZDBqceJBP1wjiS2E7OuWYySBk UiD7Znk9BRBH7MA2mDq7ltPIbieWc/QEZNltv4LMGvNdMmdCVOnv9GS7bCzwEDlOX1mc 6Gj5Kgklx1SmKl/1QQqb2HS6LQMH55uJE2D0nETRKYaHUeXCNJ6hkGtouIYFZH7+6aCd lAt8swDvrRNiNR30RIUoBBpqgxe0l/rh10daBaeBRDt9qEgZztSkf5QBHfFiKXJ++kac a88A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704976500; x=1705581300; 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=GXp+bXDP93XJesAHud7x2yMyvhqQCG8/Azuke0kj93M=; b=iozZf5GTrsCtwJ7nC0BcUSBSAzP0EykoJ4UmSajhAe5I9NiIvVHj3vwSBvjuPRbSKT g3Wdn+avuEZUEtFwdpVT6JLo3boEzqnBcnEAwoYD7bjUQBns9+OEKwZ47OQ/nnvGYPxu asrDyC2PVBRX2nqqjRsoT+D4oZLXacVAjMpfGILkB/4CoSdbhyIbfhKI43OoATtZ6YZv d277rAGLjxBR2l5Kkd1fyf2yKDM3r0DYMdl1v2+lXQ3RpsKoGEcVlWTxjURfM1aTLNUp IhSkmHFGsMfbEQNY/OuSMgfs4pcctlGQIpA/0j7Kpc9g6heHcPAxim/06g0u+1m2hvOR mpWQ== X-Gm-Message-State: AOJu0Yzm9ugYnmIoiOZ3eIRBoeIYUgMGY7FqLmSEW6nmnwibXt2JaH09 PY6ZwUVEBoMrC43LuTwwsVvhx0V6Syk01tGoUP0IkO3yYN7Ykw== X-Google-Smtp-Source: AGHT+IEIq0JHPYnl6VeikNHKyJmkU4XxuZBlhnQXxWn/hBgo99fFh1GDsEjvdzOkWgMt8LRTFVCCJLjG9V27ZSfRp5I= X-Received: by 2002:a25:aa64:0:b0:db7:dacf:6ff6 with SMTP id s91-20020a25aa64000000b00db7dacf6ff6mr1088967ybi.126.1704976498975; Thu, 11 Jan 2024 04:34:58 -0800 (PST) MIME-Version: 1.0 References: <20231221123750.2303405-1-lhyatt@gmail.com> In-Reply-To: <20231221123750.2303405-1-lhyatt@gmail.com> From: Lewis Hyatt Date: Thu, 11 Jan 2024 07:34:47 -0500 Message-ID: Subject: 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: 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 wrot= e: > > 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 va= lue > 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 using > the -idirafter option. To enable that, also modify the dg-additional-opti= ons > testsuite procedure to make the global $srcdir available, since -idirafte= r > 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 b= een > exhausted, rather than issuing a diagnostic and then hitting an > assert. > > gcc/testsuite/ChangeLog: > > * lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable i= n a > dg-additional-options directive. > * c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: N= ew 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-dir= /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_f= ile *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 *fname= , > - int angle_brackets, enum include_type); > + int angle_brackets, enum include= _type, > + bool suppress_diagnostic =3D fal= se); > 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_f= ile *file) > nothing left in the path, returns NULL. */ > static struct cpp_dir * > search_path_head (cpp_reader *pfile, const char *fname, int angle_bracke= ts, > - 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 *fn= ame, 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_bracket= s, > enum include_type type) > { > - cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_brackets,= type); > + cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_brackets,= type, > + /* suppress_diagnostic =3D */ tr= ue); > + if (!start_dir) > + return false; > _cpp_file *file =3D _cpp_find_file (pfile, fname, start_dir, angle_bra= ckets, > _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-in= clude-next-2.h b/gcc/testsuite/c-c++-common/cpp/has-include-next-2-dir/has-= 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-n= ext-2.h > @@ -0,0 +1,3 @@ > +#if __has_include_next() > +/* This formerly led to an ICE when the current directory was the last o= ne in the path. */ > +#endif > diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-next-2.c b/gcc/te= stsuite/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-incl= ude-next-2-dir" } */ > +#include > diff --git a/gcc/testsuite/lib/gcc-defs.exp b/gcc/testsuite/lib/gcc-defs.= 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"