public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/108108] New: "gcc -MM" fails to list all dependencies
@ 2022-12-14 18:01 terra at gnome dot org
  2022-12-14 18:05 ` [Bug preprocessor/108108] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: terra at gnome dot org @ 2022-12-14 18:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108108

            Bug ID: 108108
           Summary: "gcc -MM" fails to list all dependencies
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: terra at gnome dot org
  Target Milestone: ---

This is a spin-off from bug 52566


#!/bin/sh

rm -f a.h b.h c.c c.o Makefile
(echo '#pragma once'; echo '// Killroy was here') > a.h
cp -p a.h b.h
# or even "ln a.h b.h"
(echo '#include "a.h"'; echo '#include "b.h"') > c.c
gcc -MM c.c > Makefile
echo "------The Makefile:"
cat Makefile

echo "------Compiling first time:"
make CC=gcc c.o 

rm b.h
echo '#error "this file was changed"' >b.h
echo "------Compiling second time:"
make CC=gcc c.o 


The output I get is

------The Makefile:
c.o: c.c a.h
------Compiling first time:
gcc    -c -o c.o c.c
------Compiling second time:
make: 'c.o' is up to date.


Notice that the second compilation does nothing.  That's quite wrong.  Make has
not been told that c.0 depends on b.h

As seen in bug 52566, this comes down to "#pragma once" deciding that a.h and
b.h are the same file.  One could certainly take that point of view for the
purposes of a single compilation.  I wouldn't, but fine.

However, "gcc -MM" involves the future.  It is not reasonable to assume that
a.h and b.h remain the same file forever.  I think it is reasonable to expect
that any quoted #include string will show up as a dependency with no
de-duplication.


Tested on gcc 7.5.0 (opensuse) and 12.1.0 (self-built).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/108108] "gcc -MM" fails to list all dependencies
  2022-12-14 18:01 [Bug other/108108] New: "gcc -MM" fails to list all dependencies terra at gnome dot org
@ 2022-12-14 18:05 ` pinskia at gcc dot gnu.org
  2022-12-14 18:11 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-14 18:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108108

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|other                       |preprocessor

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>This is a spin-off from bug 52566

I don't think this is different issue from that bug.
The preprocessor decided it was the same file.

This is why '#pragma once' should not be used.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/108108] "gcc -MM" fails to list all dependencies
  2022-12-14 18:01 [Bug other/108108] New: "gcc -MM" fails to list all dependencies terra at gnome dot org
  2022-12-14 18:05 ` [Bug preprocessor/108108] " pinskia at gcc dot gnu.org
@ 2022-12-14 18:11 ` pinskia at gcc dot gnu.org
  2022-12-14 18:11 ` pinskia at gcc dot gnu.org
  2022-12-14 18:40 ` terra at gnome dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-14 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108108

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/cpp/Pragmas.html#Pragmas
"that file will never be read again, no matter what."

https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Preprocessor-Options.html#index-M
"The preprocessor outputs one make rule containing the object file name for
that source file, a colon, and the names of all the included files, including
those coming from -include or -imacros command-line options."

Since it was not read again, the file is not considered included ...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/108108] "gcc -MM" fails to list all dependencies
  2022-12-14 18:01 [Bug other/108108] New: "gcc -MM" fails to list all dependencies terra at gnome dot org
  2022-12-14 18:05 ` [Bug preprocessor/108108] " pinskia at gcc dot gnu.org
  2022-12-14 18:11 ` pinskia at gcc dot gnu.org
@ 2022-12-14 18:11 ` pinskia at gcc dot gnu.org
  2022-12-14 18:40 ` terra at gnome dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-14 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108108

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really #pragma once should just emit a warning just like #import does ...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/108108] "gcc -MM" fails to list all dependencies
  2022-12-14 18:01 [Bug other/108108] New: "gcc -MM" fails to list all dependencies terra at gnome dot org
                   ` (2 preceding siblings ...)
  2022-12-14 18:11 ` pinskia at gcc dot gnu.org
@ 2022-12-14 18:40 ` terra at gnome dot org
  3 siblings, 0 replies; 5+ messages in thread
From: terra at gnome dot org @ 2022-12-14 18:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108108

--- Comment #4 from M Welinder <terra at gnome dot org> ---
> Since it was not read again, the file is not considered included ...

It must have been read -- how else could gcc decide it was the same?

# strace -f gcc -MM c.c 2>&1 >Makefile  | grep 'open.*\.h' | grep -v /
[pid 30494] openat(AT_FDCWD, "a.h", O_RDONLY|O_NOCTTY) = 3
[pid 30494] openat(AT_FDCWD, "b.h", O_RDONLY|O_NOCTTY) = 3

If it was necessary to open that file, then it's a dependency.


> Really #pragma once should just emit a warning just like #import does ...

I hear you, :-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-14 18:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14 18:01 [Bug other/108108] New: "gcc -MM" fails to list all dependencies terra at gnome dot org
2022-12-14 18:05 ` [Bug preprocessor/108108] " pinskia at gcc dot gnu.org
2022-12-14 18:11 ` pinskia at gcc dot gnu.org
2022-12-14 18:11 ` pinskia at gcc dot gnu.org
2022-12-14 18:40 ` terra at gnome dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).