[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 Lewis Hyatt changed: What|Removed |Added Target Milestone|--- |14.0 Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #7 from Lewis Hyatt --- Fixed for GCC 14.
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 --- Comment #6 from GCC Commits --- The master branch has been updated by Lewis Hyatt : https://gcc.gnu.org/g:942497ad74272e0ef16020d628e471c5f21474b0 commit r14-9465-g942497ad74272e0ef16020d628e471c5f21474b0 Author: Lewis Hyatt Date: Tue Dec 12 17:46:36 2023 -0500 libcpp: Fix macro expansion for argument of __has_include [PR110558] When the file name for a #include directive is the result of stringifying a macro argument, libcpp needs to take some care to get the whitespace correct; in particular stringify_arg() needs to see a CPP_PADDING token between macro tokens so that it can figure out when to output space between tokens. The CPP_PADDING tokens are not normally generated when handling a preprocessor directive, but for #include-like directives, libcpp sets the state variable pfile->state.directive_wants_padding to TRUE so that the CPP_PADDING tokens will be output, and then everything works fine for computed includes. As the PR points out, things do not work fine for __has_include. Fix that by setting the state variable the same as is done for #include. libcpp/ChangeLog: PR preprocessor/110558 * macro.cc (builtin_has_include): Set pfile->state.directive_wants_padding prior to lexing the file name, in case it comes from macro expansion. gcc/testsuite/ChangeLog: PR preprocessor/110558 * c-c++-common/cpp/has-include-2.c: New test. * c-c++-common/cpp/has-include-2.h: New test.
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 Lewis Hyatt changed: What|Removed |Added Keywords||patch URL||https://gcc.gnu.org/piperma ||il/gcc-patches/2023-Decembe ||r/640386.html --- Comment #5 from Lewis Hyatt --- Patch submitted for review: https://gcc.gnu.org/pipermail/gcc-patches/2023-December/640386.html
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 Lewis Hyatt changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed||2023-12-11 CC||lhyatt at gcc dot gnu.org --- Comment #4 from Lewis Hyatt --- __has_include was added I think in GCC 5, and re-implemented in GCC 10, but this issue with padding in the macro expansion was never handled correctly it seems. I am testing the below which will fix it, will submit it soon with a testcase. Not sure if it would be eligible for backport or not, but it would apply cleanly to all active branches also. diff --git a/libcpp/macro.cc b/libcpp/macro.cc index 6f24a9d6f3a..15140c60023 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -398,6 +398,8 @@ builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next) NODE_NAME (op)); pfile->state.angled_headers = true; + const auto sav_padding = pfile->state.directive_wants_padding; + pfile->state.directive_wants_padding = true; const cpp_token *token = cpp_get_token_no_padding (pfile); bool paren = token->type == CPP_OPEN_PAREN; if (paren) @@ -406,6 +408,7 @@ builtin_has_include (cpp_reader *pfile, cpp_hashnode *op, bool has_next) cpp_error (pfile, CPP_DL_ERROR, "missing '(' before \"%s\" operand", NODE_NAME (op)); pfile->state.angled_headers = false; + pfile->state.directive_wants_padding = sav_padding; bool bracket = token->type != CPP_STRING; char *fname = NULL;
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 --- Comment #3 from Florian Weimer --- It tries to read "my. header.h" for some reason, even though the MAKE_INCLUDE_PATH macro produces "my.header.h" in other contexts (not just in #include directives). I doubt this is related to bug 80753.
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 --- Comment #2 from provisorisch at online dot de --- Not quite, but you will run into bug 80753 if the header file does not exist: The second #include will not cause an error in that case. The first #include however will cause an error as expected - presumably only because the first __has_include ends up with a different file name.
[Bug preprocessor/110558] __has_include argument expansion results in unexpected filename
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110558 Andrew Pinski changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=80753 --- Comment #1 from Andrew Pinski --- I think this is a dup of bug 80753 .