From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 674163834C21; Fri, 9 Dec 2022 15:06:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 674163834C21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670598364; bh=uGT224z4Rzmm7lp2N0X2uj/obP+lttumpyqEQdH9BpQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FfDTBoC+nKE12qfH8R9FrYsGNryYxNyLr6vFadtgphNPVf1ZE74z4tcQgNytS1COc vkMNwcgplMdXZOcB9GUG/LUfjkMORa0ocbstdRWTisV5DjOuV6Gqa2MBH4ClSoFYKl UGBgraT+hABAIwrMRbfnK2JzPOFbYydIS3/y9POo= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug preprocessor/104471] ICE with -nostdinc: NULL directory in find_file Date: Fri, 09 Dec 2022 15:06:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: preprocessor X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104471 --- Comment #2 from Andrew Pinski --- This patch should fix the issue (I might get to it in a few weeks though): diff --git a/libcpp/files.cc b/libcpp/files.cc index a18b1caf48d..eb90fa4f65a 100644 --- a/libcpp/files.cc +++ b/libcpp/files.cc @@ -177,7 +177,7 @@ 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 *fname, - int angle_brackets, enum include_type); + int angle_brackets, enum include_type, boo= l =3D true); static const char *dir_name_of_file (_cpp_file *file); static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int, location_t); @@ -1026,7 +1026,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_brackets, - enum include_type type) + enum include_type type, bool canerror) { cpp_dir *dir; _cpp_file *file; @@ -1055,7 +1055,7 @@ search_path_head (cpp_reader *pfile, const char *fnam= e, 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 (canerror && dir =3D=3D NULL) cpp_error (pfile, CPP_DL_ERROR, "no include path in which to search for %s", fname); @@ -2144,7 +2144,9 @@ bool _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets, enum include_type type) { - cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_brackets, t= ype); + cpp_dir *start_dir =3D search_path_head (pfile, fname, angle_brackets, t= ype, false); + if (!start_dir) + return false; _cpp_file *file =3D _cpp_find_file (pfile, fname, start_dir, angle_brack= ets, _cpp_FFK_HAS_INCLUDE, 0); return file->err_no !=3D ENOENT;=