[Frontend] Don't output skipped includes from predefines
authorShoaib Meenai <smeenai@fb.com>
Fri, 16 Jun 2023 22:32:34 +0000 (15:32 -0700)
committerShoaib Meenai <smeenai@fb.com>
Wed, 21 Jun 2023 22:48:27 +0000 (15:48 -0700)
commit67a11290df64fec44e671a1bdc3a225ed8a02962
tree18636a0dc8259a8693369077c82cda1ec4cfb4bb
parent2bcbcbefcd0f7432f99cc07bb47d1e1ecb579a3f
[Frontend] Don't output skipped includes from predefines

`-H` displays a tree of included header files, but that tree is supposed
to omit two categories of header files:
1. Any header files pulled in via `-include`, which the code refers to
   as the "predefines".
2. Any header files whose inclusion was skipped because they'd already
   been included (assuming header guards or `#pragma once`).

`-fshow-skipped-includes` was intended to make `-H` display the second
category of files. It wasn't checking for the first category, however,
so you could end up with only the middle of the `-include` hierarchy
displayed, e.g. the added test would previously output:

```
... /data/users/smeenai/llvm-project/clang/test/Frontend/Inputs/test2.h
. /data/users/smeenai/llvm-project/clang/test/Frontend/Inputs/test.h
```

This diff adds a check to prevent that and correctly omit headers from
`-include` even when `-fshow-skipped-includes` is passed. While I'm
here, add tests for the interaction between `-fshow-skipped-includes`
and `-sys-header-deps` as well.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D153175
clang/lib/Frontend/HeaderIncludeGen.cpp
clang/test/Frontend/print-header-includes.c