Thanks!
I just checked this patch can be applied with "git am" on
the latest trunk. Can someone push it? I don't have that
access level.
Have a great week,
Léo
On 2026-09-20 22:11, Andrea Pinski wrote:
On Mon, Aug 31, 2026 at 7:42 AM Léo Hardt <[email protected]> wrote:
fix(libcpp): Don't ICE parsing __has_include outside directive.
cc: libcpp maintainers.
Fixes an ICE wherein 'glue_header_name' is called outside
parsing a preprocessor directive, causing an entire file to
be read and presumed to be a header name. Then, on the next
read (the closing '>' or ')'), the parser ICEs since the input
has already come to an end.
Affects __has_include and __has_embed when used outside directives.
Minimal reproducible crash has two tokens (both gcc and g++):
__has_include<
Given glue_header_name was written for usage inside preprocessor
parsing, we could either change it or not call it in case of errors.
I opted to bail out early on an error case, since there is no chance
it could influence valid code parsing.
See more on https://gcc.gnu.org/PR121508.
PR preprocessor/121508
PR preprocessor/123339
libcpp/ChangeLog:
* macro.cc (builtin_has_include_1): Bail early if
not on a preprocessor directive.
Ok.
Signed-off-by: Léo Hardt <[email protected]>
---
libcpp/macro.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libcpp/macro.cc b/libcpp/macro.cc
index 736c360336d..064df1d4134 100644
--- a/libcpp/macro.cc
+++ b/libcpp/macro.cc
@@ -392,8 +392,11 @@ builtin_has_include_1 (cpp_reader *pfile, const char
*name, bool *paren,
bool *bracket, location_t *loc)
{
if (!pfile->state.in_directive)
- cpp_error (pfile, CPP_DL_ERROR,
- "%qs used outside of preprocessing directive", name);
+ {
+ cpp_error (pfile, CPP_DL_ERROR,
+ "%qs used outside of preprocessing directive", name);
+ return NULL;
+ }
pfile->state.angled_headers = true;
const auto sav_padding = pfile->state.directive_wants_padding;
--
2.47.3
Received: from [143.54.78.136]
by webmail.inf.ufrgs.br
with HTTP (HTTP/1.1 POST); Mon, 31 Aug 2026 11:41:48 -0300
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8;
format=flowed
Content-Transfer-Encoding: 8bit
Date: Mon, 31 Aug 2026 11:41:48 -0300
From: =?UTF-8?Q?L=C3=A9o_Hardt?= <[email protected]>
To: Gcc patches <[email protected]>
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected]
Subject: [PATCH][PR preprocessor/121508] fix(libcpp): Don't ICE parsing
=?UTF-8?Q?=5F=5Fhas=5Finclude=20outside=20directive=2E?=
Message-ID: <[email protected]>
X-Sender: [email protected]
User-Agent: Roundcube Webmail/0.9.5
fix(libcpp): Don't ICE parsing __has_include outside directive.
cc: libcpp maintainers.
Fixes an ICE wherein 'glue_header_name' is called outside
parsing a preprocessor directive, causing an entire file to
be read and presumed to be a header name. Then, on the next
read (the closing '>' or ')'), the parser ICEs since the input
has already come to an end.
Affects __has_include and __has_embed when used outside directives.
Minimal reproducible crash has two tokens (both gcc and g++):
__has_include<
Given glue_header_name was written for usage inside preprocessor
parsing, we could either change it or not call it in case of errors.
I opted to bail out early on an error case, since there is no chance
it could influence valid code parsing.
See more on https://gcc.gnu.org/PR121508.
PR preprocessor/121508
PR preprocessor/123339
libcpp/ChangeLog:
* macro.cc (builtin_has_include_1): Bail early if
not on a preprocessor directive.
Signed-off-by: Léo Hardt <[email protected]>
---
libcpp/macro.cc | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libcpp/macro.cc b/libcpp/macro.cc
index 736c360336d..064df1d4134 100644
--- a/libcpp/macro.cc
+++ b/libcpp/macro.cc
@@ -392,8 +392,11 @@ builtin_has_include_1 (cpp_reader *pfile, const char
*name, bool *paren,
bool *bracket, location_t *loc)
{
if (!pfile->state.in_directive)
- cpp_error (pfile, CPP_DL_ERROR,
- "%qs used outside of preprocessing directive", name);
+ {
+ cpp_error (pfile, CPP_DL_ERROR,
+ "%qs used outside of preprocessing directive", name);
+ return NULL;
+ }
pfile->state.angled_headers = true;
const auto sav_padding = pfile->state.directive_wants_padding;
--
2.47.3