[all-commits] [llvm/llvm-project] f29dcb: Add flag for showing skipped headers in -H / --sho...

Hans via All-commits all-commits at lists.llvm.org
Wed Apr 14 08:07:11 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e
      https://github.com/llvm/llvm-project/commit/f29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e
  Author: Hans Wennborg <hans at chromium.org>
  Date:   2021-04-14 (Wed, 14 Apr 2021)

  Changed paths:
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/Frontend/DependencyOutputOptions.h
    M clang/lib/Frontend/HeaderIncludeGen.cpp
    M clang/test/Frontend/Inputs/test.h
    M clang/test/Frontend/Inputs/test2.h
    M clang/test/Frontend/print-header-includes.c

  Log Message:
  -----------
  Add flag for showing skipped headers in -H / --show-includes output

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.

Differential revision: https://reviews.llvm.org/D100480




More information about the All-commits mailing list