[all-commits] [llvm/llvm-project] d7bba0: [include-cleaner] Improve header spelling in the p...

Sam McCall via All-commits all-commits at lists.llvm.org
Wed Jan 11 05:44:42 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d7bba07526a7298c9331de031dec15daecff3503
      https://github.com/llvm/llvm-project/commit/d7bba07526a7298c9331de031dec15daecff3503
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2023-01-11 (Wed, 11 Jan 2023)

  Changed paths:
    M clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
    M clang-tools-extra/include-cleaner/lib/Record.cpp

  Log Message:
  -----------
  [include-cleaner] Improve header spelling in the presence of links

HeaderSearch uses FileEntry::getName() to determine the best spelling of a
header. FileEntry::getName() is now the name of the *last* retrieved ref.
This means that when FileManager::getFile() hits an existing inode through a new
path, it changes the spelling of that header.

In the absence of explicit logic to track the preferred name(s) of header files,
we should avoid gratuitously calling getFile() with paths different than how
the header was originally included, such as the result of realpath().

The originally-specified path should be fine here:
 - if the same filemanager is being used for record/analysis, we'll hit the
   filename cache
 - if a different filemanager is being used e.g. preamble scenario, we should
   get the same result unless either the working directory has changed (which it
   shouldn't, else many other things will fail) or the file has gone/changed
   inode (in which case the old method doesn't work either)

Needless to say this is fragile, but talking to @kadircet offline, it's good
enough for our purposes for now.

Differential Revision: https://reviews.llvm.org/D141478




More information about the All-commits mailing list