https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105412
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:f25788bfb856a83f7d12d850d62a940536b70688 commit r16-8086-gf25788bfb856a83f7d12d850d62a940536b70688 Author: Jakub Jelinek <[email protected]> Date: Fri Mar 13 21:58:46 2026 +0100 libcpp: Fix up -MP for - input [PR105412] For -MP we used to emit something like below in GCC 9 and earlier: touch a.h; echo '#include "a.h"' | ./cc1 -quiet -E -M -MP - -: /usr/include/stdc-predef.h a.h /usr/include/stdc-predef.h: a.h: but since r10-205 we emit instead just touch a.h; echo '#include "a.h"' | ./cc1 -quiet -E -M -MP - -: /usr/include/stdc-predef.h a.h a.h: i.e. the rule for /usr/include/stdc-predef.h is removed. Similarly with -nostdinc: touch a.h; echo '#include "a.h"' | ./cc1 -quiet -E -nostdinc -M -MP - -: a.h a.h: r10-205 changed that to: touch a.h; echo '#include "a.h"' | ./cc1 -quiet -E -nostdinc -M -MP - -: a.h a.h: The rationale for the change was https://gcc.gnu.org/legacy-ml/gcc-patches/2019-05/msg00323.html where after the mkdeps.cc reimplementation it started ICEing on - input (file->path[0] is "" in that case). The problem is that by leaving out the "" dependency (which we then in some cases indeed ignore) the -MP printing if (CPP_OPTION (pfile, deps.phony_targets)) for (unsigned i = 1; i < d->deps.size (); i++) fprintf (fp, "%s:\n", munge (d->deps[i])); starts at d->deps[1] unconditionally and so ignores the first dependency even when it is not the main file. So, either we could just revert the r10-205 change and ensure we don't ICE on it and keep ignoring it when it should be ignored, or the following patch fixes it by not adding the "" dep, but remembering that in that case we should start iterating from i = 0; and not from i = 1; 2026-03-13 Jakub Jelinek <[email protected]> PR preprocessor/105412 * files.cc (_cpp_stack_file): Call deps_add_dep even on empty file path. * mkdeps.cc (class mkdeps): Add first_phony_dep member. (mkdeps::mkdeps ()): Initialize it to 1. (deps_add_dep): When called first with "" argument, decrease d->first_phony_dep to 0. (make_write): For -MP iterate from d->first_phony_dep rather than 1. Reviewed-by: Joseph Myers <[email protected]>
