libcpp: Fix ICE when parsing __has_include outside a directive.
Preprocessor correctly handles __has_include and __has_embed when not inside a directive, preventing internal compiler errors.
This change fixes an internal compiler error (ICE) in the C preprocessor (libcpp) that occurred when __has_include or __has_embed were used outside of a preprocessor directive. Previously, the parser would incorrectly attempt to read the entire file as a header name, leading to an error and a crash when encountering the closing token. The fix adds an early exit condition in builtin_has_include_1 to prevent calling glue_header_name in invalid contexts, thus avoiding the ICE and correctly handling these builtins.
In Details
The glue_header_name function in macro.cc is intended for parsing header names within preprocessor directives. The builtin_has_include_1 function was calling glue_header_name unconditionally. When __has_include or __has_embed were encountered outside a directive context, glue_header_name would consume the entire input file, treating it as a header name. Subsequent parsing for the closing parenthesis or angle bracket would then hit end-of-file prematurely, leading to an ICE. This commit modifies builtin_has_include_1 to check if it's currently processing a directive before call…
- ICE
- Internal Compiler Error. A crash within the compiler itself, usually indicating a bug in the compiler's logic or code generation.
- Preprocessor
- A program that processes source code before the main compilation phase. It handles directives like #include, #define, and conditional compilation.