This is an archive of the discontinued LLVM Phabricator instance.

Add flag for showing skipped headers in -H / --show-includes output
ClosedPublic

Authored by hans on Apr 14 2021, 7:48 AM.

Details

Summary

Consider the following set of files:

a.cc:
#include "a.h"

a.h:
#ifndef A_H
#define A_H

#include "b.h"
#include "c.h"  // This gets "skipped".

#endif

b.h:
#ifndef B_H
#define B_H

#include "c.h"

#endif

c.h:
#ifndef C_H
#define C_H

void c();

#endif

And the output of the -H option:

$ clang -c -H a.cc
. ./a.h
.. ./b.h
... ./c.h

Note that the include of c.h in a.h is not shown in the output. (GCC does the same.) This is because of the include guard optimization: clang knows c.h is covered by an include guard which is already defined, so when it sees the include in a.h, it skips it. The same would have happened if #pragma once were used instead of include guards.

However, a.h *does* include c.h, and it may be useful to show that in the -H output. This patch adds a flag for doing that.

Diff Detail

Event Timeline

hans created this revision.Apr 14 2021, 7:48 AM
hans requested review of this revision.Apr 14 2021, 7:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2021, 7:48 AM
thakis accepted this revision.Apr 14 2021, 7:55 AM
This revision is now accepted and ready to land.Apr 14 2021, 7:55 AM
This revision was landed with ongoing or failed builds.Apr 14 2021, 8:07 AM
This revision was automatically updated to reflect the committed changes.