Repository: kythe/kythe
Pull request #5861 (2023-09-21 17:07:14)

chore: various clang-tidy cleanups


Patch:
diff --git a/.clang-tidy b/.clang-tidy
index f833392c9..ba4a4d205 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -109,41 +109,23 @@ WarningsAsErrors: ''
 HeaderFilterRegex: ''
 FormatStyle:     file
 CheckOptions:
-  - key:             llvm-else-after-return.WarnOnConditionVariables
-    value:           'false'
-  - key:             modernize-loop-convert.MinConfidence
-    value:           reasonable
-  - key:             modernize-replace-auto-ptr.IncludeStyle
-    value:           llvm
-  - key:             cert-str34-c.DiagnoseSignedUnsignedCharComparisons
-    value:           'false'
-  - key:             google-readability-namespace-comments.ShortNamespaceLines
-    value:           '10'
-  - key:             cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
-    value:           'false'
-  - key:             cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
-    value:           'true'
-  - key:             cert-dcl16-c.NewSuffixes
-    value:           'L;LL;LU;LLU'
-  - key:             google-readability-braces-around-statements.ShortStatementLines
-    value:           '1'
-  - key:             modernize-pass-by-value.IncludeStyle
-    value:           llvm
-  - key:             google-readability-namespace-comments.SpacesBeforeComments
-    value:           '2'
-  - key:             modernize-loop-convert.MaxCopySize
-    value:           '16'
-  - key:             cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
-    value:           'true'
-  - key:             modernize-use-nullptr.NullMacros
-    value:           'NULL'
-  - key:             llvm-qualified-auto.AddConstToQualified
-    value:           'false'
-  - key:             modernize-loop-convert.NamingStyle
-    value:           CamelCase
-  - key:             llvm-else-after-return.WarnOnUnfixable
-    value:           'false'
-  - key:             google-readability-function-size.StatementThreshold
-    value:           '800'
-  - key:             'bugprone-dangling-handle.HandleClasses'
-    value:           '::std::string_view;::absl::string_view;::absl::Span;::absl::FunctionRef;::llvm::StringRef;::llvm::ArrayRef;::absl::BitGenRef'
+  bugprone-dangling-handle.HandleClasses: '::std::string_view;::absl::string_view;::absl::Span;::absl::FunctionRef;::llvm::StringRef;::llvm::ArrayRef;::absl::BitGenRef'
+  cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
+  cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
+  cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
+  cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors: 'true'
+  cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
+  google-readability-braces-around-statements.ShortStatementLines: '1'
+  google-readability-function-size.StatementThreshold: '800'
+  google-readability-namespace-comments.ShortNamespaceLines: '10'
+  google-readability-namespace-comments.SpacesBeforeComments: '2'
+  llvm-else-after-return.WarnOnConditionVariables: 'false'
+  llvm-else-after-return.WarnOnUnfixable: 'false'
+  llvm-qualified-auto.AddConstToQualified: 'false'
+  misc-include-cleaner.IgnoreHeaders: 'libmemcached-1.0/.*;asm-generic/.*'
+  modernize-loop-convert.MaxCopySize: '16'
+  modernize-loop-convert.MinConfidence: reasonable
+  modernize-loop-convert.NamingStyle: CamelCase
+  modernize-pass-by-value.IncludeStyle: llvm
+  modernize-replace-auto-ptr.IncludeStyle: llvm
+  modernize-use-nullptr.NullMacros: 'NULL'
diff --git a/kythe/cxx/common/BUILD b/kythe/cxx/common/BUILD
index 1cd274133..993b22833 100644
--- a/kythe/cxx/common/BUILD
+++ b/kythe/cxx/common/BUILD
@@ -453,6 +453,9 @@ cc_test(
         "//kythe/testdata/platform:stringset.kzip",
     ],
     deps = [
+        ":index_reader",
+        ":index_writer",
+        ":kzip_encoding",
         ":kzip_reader",
         ":kzip_writer",
         ":libzip/error",
diff --git a/kythe/cxx/common/file_utils.cc b/kythe/cxx/common/file_utils.cc
index 85b47a331..3545c216d 100644
--- a/kythe/cxx/common/file_utils.cc
+++ b/kythe/cxx/common/file_utils.cc
@@ -27,7 +27,8 @@ std::string LoadFileOrDie(const std::string& file) {
   FILE* handle = fopen(file.c_str(), "rb");
   CHECK(handle != nullptr) << "Couldn't open input file " << file;
   CHECK_EQ(fseek(handle, 0, SEEK_END), 0) << "Couldn't seek " << file;
-  long size = ftell(handle);
+  long size = ftell(handle);  // NOLINT(google-runtime-int): ftell is defined to
+                              // return `long`.
   CHECK_GE(size, 0) << "Bad size for " << file;
   CHECK_EQ(fseek(handle, 0, SEEK_SET), 0) << "Couldn't seek " << file;
   std::string content;
diff --git a/kythe/cxx/common/index_reader.cc b/kythe/cxx/common/index_reader.cc
index b7fda08fd..e919519b8 100644
--- a/kythe/cxx/common/index_reader.cc
+++ b/kythe/cxx/common/index_reader.cc
@@ -14,6 +14,6 @@
  * limitations under the License.
  */
 
-#include "kythe/cxx/common/index_reader.h"
+#include "kythe/cxx/common/index_reader.h"  // NOLINT(misc-include-cleaner)
 
 // This file intentionally left blank.
diff --git a/kythe/cxx/common/index_writer.cc b/kythe/cxx/common/index_writer.cc
index 1b0c34228..8d2add97a 100644
--- a/kythe/cxx/common/index_writer.cc
+++ b/kythe/cxx/common/index_writer.cc
@@ -14,6 +14,6 @@
  * limitations under the License.
  */
 
-#include "kythe/cxx/common/index_writer.h"
+#include "kythe/cxx/common/index_writer.h"  // NOLINT(misc-include-cleaner)
 
 // This file intentionally left blank.
diff --git a/kythe/cxx/common/init.cc b/kythe/cxx/common/init.cc
index 33008a573..4fae5cddb 100644
--- a/kythe/cxx/common/init.cc
+++ b/kythe/cxx/common/init.cc
@@ -37,16 +37,18 @@ extern "C" {
 //
 // We are replacing implementation-defined function (defined in glibc)
 // used by the expansion of system defined assert() macro.
-void __assert_fail(const char* assertion, const char* file, unsigned int line,
-                   const char* function) __THROW {
+void __assert_fail(
+    const char* assertion, const char* file, unsigned int line,
+    const char* function) __THROW {  // NOLINT(misc-include-cleaner)
   LOG(FATAL) << "assert.h assertion failed at " << file << ":" << line
              << (function ? " in " : "") << (function ? function : "") << ": "
              << assertion;
 }
 
 // Same as above, but for assert_perror.
-void __assert_perror_fail(int errnum, const char* file, unsigned int line,
-                          const char* function) __THROW {
+void __assert_perror_fail(
+    int errnum, const char* file, unsigned int line,
+    const char* function) __THROW {  // NOLINT(misc-include-cleaner)
   LOG(FATAL) << "assert.h assert_perror failed at " << file << ":" << line
              << " " << (function ? function : "") << ": "
              << std::strerror(errnum) << " [" << errnum << "]";
diff --git a/kythe/cxx/common/path_utils.cc b/kythe/cxx/common/path_utils.cc
index b72696b91..8919ada0b 100644
--- a/kythe/cxx/common/path_utils.cc
+++ b/kythe/cxx/common/path_utils.cc
@@ -16,9 +16,11 @@
 
 #include "kythe/cxx/common/path_utils.h"
 
+#include <stdlib.h>
 #include <unistd.h>
 
 #include <cerrno>
+#include <cstdlib>
 #include <cstring>
 #include <memory>
 #include <optional>
diff --git a/kythe/cxx/doc/BUILD b/kythe/cxx/doc/BUILD
index bb73f3406..d2c3e016e 100644
--- a/kythe/cxx/doc/BUILD
+++ b/kythe/cxx/doc/BUILD
@@ -106,7 +106,6 @@ cc_binary(
     ],
     deps = [
         ":html_renderer",
-        ":markup_handler",
         "//kythe/cxx/common:init",
         "//kythe/cxx/common:kythe_uri",
         "//kythe/cxx/common:lib",
@@ -116,9 +115,7 @@ cc_binary(
         "@com_google_absl//absl/flags:flag",
         "@com_google_absl//absl/flags:parse",
         "@com_google_absl//absl/flags:usage",
-        "@com_google_absl//absl/log",
         "@com_google_absl//absl/log:check",
-        "@com_google_absl//absl/memory",
         "@com_google_absl//absl/strings:str_format",
         "@com_google_protobuf//:protobuf",
         "@com_google_protobuf//src/google/protobuf/io",
diff --git a/kythe/cxx/doc/doc.cc b/kythe/cxx/doc/doc.cc
index e10ec8631..e943e86c6 100644
--- a/kythe/cxx/doc/doc.cc
+++ b/kythe/cxx/doc/doc.cc
@@ -18,8 +18,9 @@
 // extracted from the Kythe graph.
 
 #include <fcntl.h>
-#include <sys/stat.h>
+#include <unistd.h>
 
+#include <cstdio>
 #include <memory>
 #include <string>
 
@@ -27,10 +28,9 @@
 #include "absl/flags/parse.h"
 #include "absl/flags/usage.h"
 #include "absl/log/check.h"
-#include "absl/log/log.h"
-#include "absl/memory/memory.h"
 #include "absl/strings/str_format.h"
 #include "google/protobuf/io/zero_copy_stream_impl.h"
+#include "google/protobuf/stubs/common.h"
 #include "google/protobuf/text_format.h"
 #include "kythe/cxx/common/init.h"
 #include "kythe/cxx/common/kythe_uri.h"
@@ -40,7 +40,9 @@
 #include "kythe/cxx/doc/html_markup_handler.h"
 #include "kythe/cxx/doc/html_renderer.h"
 #include "kythe/cxx/doc/javadoxygen_markup_handler.h"
-#include "kythe/cxx/doc/markup_handler.h"
+#include "kythe/proto/common.pb.h"
+#include "kythe/proto/storage.pb.h"
+#include "kythe/proto/xref.pb.h"
 
 ABSL_FLAG(std::string, xrefs, "http://localhost:8080",
           "Base URI for xrefs service");
diff --git a/kythe/cxx/doc/html_markup_handler.cc b/kythe/cxx/doc/html_markup_handler.cc
index 26d402f1f..b5b357f1c 100644
--- a/kythe/cxx/doc/html_markup_handler.cc
+++ b/kythe/cxx/doc/html_markup_handler.cc
@@ -14,9 +14,13 @@
  * limitations under the License.
  */
 
+#include <cctype>
+#include <cstddef>
+#include <string>
+#include <vector>
+
 #include "absl/log/check.h"
-#include "absl/log/log.h"
-#include "kythe/cxx/doc/javadoxygen_markup_handler.h"
+#include "kythe/cxx/doc/markup_handler.h"
 
 namespace kythe {
 namespace {
diff --git a/kythe/cxx/doc/html_renderer.cc b/kythe/cxx/doc/html_renderer.cc
index a32fa4661..b99c10382 100644
--- a/kythe/cxx/doc/html_renderer.cc
+++ b/kythe/cxx/doc/html_renderer.cc
@@ -16,9 +16,16 @@
 
 #include "kythe/cxx/doc/html_renderer.h"
 
+#include <cstddef>
+#include <map>
 #include <stack>
+#include <string>
+#include <utility>
+#include <vector>
 
 #include "kythe/cxx/doc/markup_handler.h"
+#include "kythe/proto/common.pb.h"
+#include "kythe/proto/xref.pb.h"
 
 namespace kythe {
 namespace {
@@ -717,7 +724,7 @@ std::string RenderDocument(
     if (!initializer.empty()) {
       CssTag init_div(CssTag::Kind::Div, options.initializer_div, &text_out);
       text_out.append("Initializer: ");
-      bool multiline = initializer.find("\n") != decltype(initializer)::npos;
+      bool multiline = initializer.find('\n') != decltype(initializer)::npos;
       CssTag code_div(CssTag::Kind::Pre,
                       multiline ? options.initializer_multiline_pre
                                 : options.initializer_pre,
diff --git a/kythe/cxx/doc/javadoxygen_markup_handler.cc b/kythe/cxx/doc/javadoxygen_markup_handler.cc
index 662e8b4aa..f5f83b614 100644
--- a/kythe/cxx/doc/javadoxygen_markup_handler.cc
+++ b/kythe/cxx/doc/javadoxygen_markup_handler.cc
@@ -16,8 +16,11 @@
 
 #include "kythe/cxx/doc/javadoxygen_markup_handler.h"
 
+#include <cstddef>
+#include <string>
+
 #include "absl/log/check.h"
-#include "absl/log/log.h"
+#include "kythe/cxx/doc/markup_handler.h"
 
 // See
 // <http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html>
diff --git a/kythe/cxx/doc/markup_handler.cc b/kythe/cxx/doc/markup_handler.cc
index c5d6ff6e6..5bc264ada 100644
--- a/kythe/cxx/doc/markup_handler.cc
+++ b/kythe/cxx/doc/markup_handler.cc
@@ -17,7 +17,13 @@
 #include "kythe/cxx/doc/markup_handler.h"
 
 #include <algorithm>
+#include <cstddef>
 #include <stack>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "kythe/proto/xref.pb.h"
 
 namespace kythe {
 
diff --git a/kythe/cxx/extractor/BUILD b/kythe/cxx/extractor/BUILD
index 9405956e2..2f779dc97 100644
--- a/kythe/cxx/extractor/BUILD
+++ b/kythe/cxx/extractor/BUILD
@@ -160,8 +160,12 @@ cc_library(
     name = "objc_bazel_support_library",
     srcs = ["objc_bazel_support.cc"],
     hdrs = ["objc_bazel_support.h"],
+    features = [
+        "-layering_check",  # TODO: protocolbuffers/protobuf#10889
+    ],
     deps = [
         "//third_party/bazel:extra_actions_base_cc_proto",
+        "@com_google_protobuf//:protobuf_lite",
         "@com_googlesource_code_re2//:re2",
         "@llvm-project//llvm:Support",
     ],
@@ -171,11 +175,16 @@ cc_test(
     name = "objc_bazel_support_library_test",
     size = "small",
     srcs = ["objc_bazel_support_test.cc"],
+    features = [
+        "-layering_check",  # TODO: protocolbuffers/protobuf#10889
+    ],
     deps = [
         ":objc_bazel_support_library",
         "//third_party:gtest",
+        "//third_party/bazel:extra_actions_base_cc_proto",
         "@com_google_absl//absl/log",
         "@com_google_absl//absl/log:initialize",
+        "@com_google_protobuf//:protobuf_lite",
     ],
 )
 
diff --git a/kythe/cxx/extractor/CommandLineUtils.cc b/kythe/cxx/extractor/CommandLineUtils.cc
index 85a2fab97..34e1eeb11 100644
--- a/kythe/cxx/extractor/CommandLineUtils.cc
+++ b/kythe/cxx/extractor/CommandLineUtils.cc
@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include <algorithm>
+#include <cassert>
 #include <mutex>
 #include <string>
 #include <string_view>
diff --git a/kythe/cxx/extractor/bazel_artifact_reader.cc b/kythe/cxx/extractor/bazel_artifact_reader.cc
index 51c121bf3..6d105dd39 100644
--- a/kythe/cxx/extractor/bazel_artifact_reader.cc
+++ b/kythe/cxx/extractor/bazel_artifact_reader.cc
@@ -15,12 +15,12 @@
  */
 #include "kythe/cxx/extractor/bazel_artifact_reader.h"
 
-#include <string>
+#include <optional>
+#include <utility>
+#include <vector>
 
-#include "absl/strings/escaping.h"
-#include "absl/strings/str_cat.h"
-#include "absl/strings/str_join.h"
-#include "third_party/bazel/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.pb.h"
+#include "kythe/cxx/extractor/bazel_artifact.h"
+#include "kythe/cxx/extractor/bazel_artifact_selector.h"
 
 namespace kythe {
 
diff --git a/kythe/cxx/extractor/bazel_artifact_selector.cc b/kythe/cxx/extractor/bazel_artifact_selector.cc
index 66187faa7..d588ec902 100644
--- a/kythe/cxx/extractor/bazel_artifact_selector.cc
+++ b/kythe/cxx/extractor/bazel_artifact_selector.cc
@@ -15,11 +15,15 @@
  */
 #include "kythe/cxx/extractor/bazel_artifact_selector.h"
 
+#include <cstddef>
 #include <cstdint>
 #include <functional>
 #include <optional>
+#include <string>
+#include <tuple>
 #include <type_traits>
 #include <utility>
+#include <vector>
 
 #include "absl/base/attributes.h"
 #include "absl/container/flat_hash_map.h"
@@ -33,11 +37,14 @@
 #include "absl/strings/numbers.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/str_join.h"
+#include "absl/strings/string_view.h"
+#include "absl/types/span.h"
 #include "google/protobuf/any.pb.h"
 #include "kythe/cxx/extractor/bazel_artifact.h"
 #include "kythe/proto/bazel_artifact_selector.pb.h"
 #include "kythe/proto/bazel_artifact_selector_v2.pb.h"
 #include "re2/re2.h"
+#include "third_party/bazel/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.pb.h"
 
 namespace kythe {
 namespace {
@@ -86,19 +93,6 @@ T& GetOrConstruct(std::optional<T>& value) {
   return value.has_value() ? *value : value.emplace();
 }
 
-template <typename T>
-struct FromRange {
-  template <typename U>
-  operator U() {
-    return U(range.begin(), range.end());
-  }
-
-  const T& range;
-};
-
-template <typename T>
-FromRange(const T&) -> FromRange<T>;
-
 template <typename T>
 const T& AsConstRef(const T& value) {
   return value;
@@ -428,7 +422,7 @@ bool AspectArtifactSelector::SerializeInto(google::protobuf::Any& state) const {
                                                                     raw)) {
         return false;
       }
-      state.PackFrom(std::move(raw));
+      state.PackFrom(raw);
       return true;
     }
     case AspectArtifactSelectorSerializationFormat::kV1: {
@@ -453,7 +447,7 @@ bool AspectArtifactSelector::SerializeInto(google::protobuf::Any& state) const {
           file_entry->set_uri(file->uri);
         }
       }
-      state.PackFrom(std::move(raw));
+      state.PackFrom(raw);
       return true;
     }
   }
diff --git a/kythe/cxx/extractor/bazel_event_reader.cc b/kythe/cxx/extractor/bazel_event_reader.cc
index 9661509f0..1075612ce 100644
--- a/kythe/cxx/extractor/bazel_event_reader.cc
+++ b/kythe/cxx/extractor/bazel_event_reader.cc
@@ -18,6 +18,8 @@
 #include <utility>
 
 #include "absl/status/status.h"
+#include "google/protobuf/io/coded_stream.h"
+#include "google/protobuf/io/zero_copy_stream.h"
 #include "google/protobuf/util/delimited_message_util.h"
 #include "third_party/bazel/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.pb.h"
 
diff --git a/kythe/cxx/extractor/cxx_details.cc b/kythe/cxx/extractor/cxx_details.cc
index 5700ae485..98fbd523a 100644
--- a/kythe/cxx/extractor/cxx_details.cc
+++ b/kythe/cxx/extractor/cxx_details.cc
@@ -16,7 +16,14 @@
 
 #include "kythe/cxx/extractor/cxx_details.h"
 
+#include <string>
+
 #include "absl/log/log.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "kythe/proto/cxx.pb.h"
 
 namespace kythe {
 
diff --git a/kythe/cxx/extractor/cxx_extractor.cc b/kythe/cxx/extractor/cxx_extractor.cc
index a44a1b6b8..3a3b03762 100644
--- a/kythe/cxx/extractor/cxx_extractor.cc
+++ b/kythe/cxx/extractor/cxx_extractor.cc
@@ -16,43 +16,56 @@
 
 #include "cxx_extractor.h"
 
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
+#include <algorithm>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <map>
 #include <memory>
 #include <optional>
+#include <set>
+#include <stack>
+#include <string>
 #include <string_view>
+#include <system_error>
 #include <tuple>
 #include <type_traits>
 #include <unordered_map>
 #include <utility>
+#include <vector>
 
-#include "absl/container/flat_hash_map.h"
 #include "absl/container/flat_hash_set.h"
 #include "absl/log/check.h"
 #include "absl/log/log.h"
-#include "absl/memory/memory.h"
 #include "absl/status/statusor.h"
 #include "absl/strings/match.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/str_format.h"
 #include "absl/strings/string_view.h"
 #include "absl/strings/strip.h"
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Pragma.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Tooling/Tooling.h"
+#include "google/protobuf/any.pb.h"
 #include "kythe/cxx/common/file_utils.h"
+#include "kythe/cxx/common/index_writer.h"
 #include "kythe/cxx/common/json_proto.h"
 #include "kythe/cxx/common/kzip_writer.h"
 #include "kythe/cxx/common/path_utils.h"
 #include "kythe/cxx/common/sha256_hasher.h"
 #include "kythe/cxx/extractor/CommandLineUtils.h"
+#include "kythe/cxx/extractor/cxx_details.h"
 #include "kythe/cxx/extractor/language.h"
 #include "kythe/cxx/extractor/path_utils.h"
 #include "kythe/cxx/indexer/cxx/stream_adapter.h"
@@ -60,6 +73,10 @@
 #include "kythe/proto/buildinfo.pb.h"
 #include "kythe/proto/cxx.pb.h"
 #include "kythe/proto/filecontext.pb.h"
+#include "kythe/proto/storage.pb.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -372,7 +389,7 @@ struct FileState {
 /// \brief Hooks the Clang preprocessor to detect required include files.
 class ExtractorPPCallbacks : public clang::PPCallbacks {
  public:
-  ExtractorPPCallbacks(ExtractorState state);
+  explicit ExtractorPPCallbacks(ExtractorState state);
 
   /// \brief Common utility to pop a file off the file stack.
   ///
@@ -546,7 +563,7 @@ ExtractorPPCallbacks::ExtractorPPCallbacks(ExtractorState state)
           state.main_source_file_stdin_alternate) {
   class ClaimPragmaHandlerWrapper : public clang::PragmaHandler {
    public:
-    ClaimPragmaHandlerWrapper(ExtractorPPCallbacks* context)
+    explicit ClaimPragmaHandlerWrapper(ExtractorPPCallbacks* context)
         : PragmaHandler("kythe_claim"), context_(context) {}
     void HandlePragma(clang::Preprocessor& preprocessor,
                       clang::PragmaIntroducer introducer,
@@ -563,7 +580,7 @@ ExtractorPPCallbacks::ExtractorPPCallbacks(ExtractorState state)
 
   class MetadataPragmaHandlerWrapper : public clang::PragmaHandler {
    public:
-    MetadataPragmaHandlerWrapper(ExtractorPPCallbacks* context)
+    explicit MetadataPragmaHandlerWrapper(ExtractorPPCallbacks* context)
         : PragmaHandler("kythe_metadata"), context_(context) {}
     void HandlePragma(clang::Preprocessor& preprocessor,
                       clang::PragmaIntroducer introducer,
@@ -1060,7 +1077,7 @@ void KzipWriterSink::OpenIndex(const std::string& unit_hash) {
   std::string path = path_type_ == OutputPathType::SingleFile
                          ? path_
                          : JoinPath(path_, unit_hash + ".kzip");
-  writer_ = IndexWriter(OpenKzipWriterOrDie(path));
+  writer_ = OpenKzipWriterOrDie(path);
 }
 
 void KzipWriterSink::WriteHeader(const kythe::proto::CompilationUnit& header) {
diff --git a/kythe/cxx/extractor/cxx_extractor_bazel_main.cc b/kythe/cxx/extractor/cxx_extractor_bazel_main.cc
index 80aec3f13..1e35cac55 100644
--- a/kythe/cxx/extractor/cxx_extractor_bazel_main.cc
+++ b/kythe/cxx/extractor/cxx_extractor_bazel_main.cc
@@ -19,9 +19,14 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
+#include <algorithm>
+#include <climits>
+#include <cstdio>
 #include <fstream>
 #include <string>
+#include <vector>
 
 #include "absl/flags/flag.h"
 #include "absl/flags/parse.h"
@@ -30,7 +35,6 @@
 #include "absl/strings/str_format.h"
 #include "cxx_extractor.h"
 #include "google/protobuf/io/coded_stream.h"
-#include "google/protobuf/io/zero_copy_stream.h"
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "google/protobuf/stubs/common.h"
 #include "kythe/cxx/common/init.h"
diff --git a/kythe/cxx/extractor/dump_bazel_artifacts.cc b/kythe/cxx/extractor/dump_bazel_artifacts.cc
index f3a77c5b2..e782de216 100644
--- a/kythe/cxx/extractor/dump_bazel_artifacts.cc
+++ b/kythe/cxx/extractor/dump_bazel_artifacts.cc
@@ -13,10 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <cerrno>
+#include <cstring>
 #include <fstream>
 #include <iostream>
 #include <string>
-#include <vector>
 
 #include "absl/flags/flag.h"
 #include "absl/flags/parse.h"
@@ -25,6 +26,7 @@
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "kythe/cxx/common/init.h"
 #include "kythe/cxx/extractor/bazel_artifact_reader.h"
+#include "kythe/cxx/extractor/bazel_event_reader.h"
 
 ABSL_FLAG(std::string, build_event_binary_file, "",
           "Bazel event protocol file to read");
diff --git a/kythe/cxx/extractor/language.cc b/kythe/cxx/extractor/language.cc
index 32b90774e..8064e225b 100644
--- a/kythe/cxx/extractor/language.cc
+++ b/kythe/cxx/extractor/language.cc
@@ -18,8 +18,6 @@
 
 #include <string>
 
-#include "llvm/ADT/StringRef.h"
-
 namespace kythe {
 namespace supported_language {
 
diff --git a/kythe/cxx/extractor/objc_bazel_support.cc b/kythe/cxx/extractor/objc_bazel_support.cc
index 0fc6fcd7d..6b429d0c1 100644
--- a/kythe/cxx/extractor/objc_bazel_support.cc
+++ b/kythe/cxx/extractor/objc_bazel_support.cc
@@ -16,18 +16,26 @@
 
 #include "objc_bazel_support.h"
 
-#include <llvm/ADT/StringRef.h>
+#include <stdio.h>
 
+#include <algorithm>
+#include <cstddef>
+#include <cstdio>
 #include <sstream>
+#include <string>
+#include <vector>
 
+#include "google/protobuf/repeated_ptr_field.h"
+#include "llvm/ADT/StringRef.h"
 #include "re2/re2.h"
+#include "third_party/bazel/src/main/protobuf/extra_actions_base.pb.h"
 
 namespace kythe {
 
 // This is inspiried by Python's commands.mkarg
 // https://hg.python.org/cpython/file/tip/Lib/commands.py#l81
 std::string SanitizeArgument(const std::string& s) {
-  if (s.find("'") == std::string::npos) {
+  if (s.find('\'') == std::string::npos) {
     // There are no single quotes, so we can make the string safe by putting it
     // in single quotes.
     return "'" + s + "'";
@@ -61,7 +69,7 @@ std::string RunScript(const std::string& cmd) {
     return output;
   }
   while (!feof(f)) {
-    if (fgets(buffer, 256, f) != NULL) {
+    if (fgets(buffer, 256, f) != nullptr) {
       output += buffer;
     }
   }
diff --git a/kythe/cxx/extractor/objc_extractor_bazel_main.cc b/kythe/cxx/extractor/objc_extractor_bazel_main.cc
index 8f0fd5912..5c551aaf3 100644
--- a/kythe/cxx/extractor/objc_extractor_bazel_main.cc
+++ b/kythe/cxx/extractor/objc_extractor_bazel_main.cc
@@ -70,6 +70,11 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include <climits>
+#include <cstdio>
+#include <string>
+#include <vector>
+
 #include "absl/flags/flag.h"
 #include "absl/flags/parse.h"
 #include "absl/log/check.h"
@@ -77,7 +82,6 @@
 #include "absl/strings/str_format.h"
 #include "cxx_extractor.h"
 #include "google/protobuf/io/coded_stream.h"
-#include "google/protobuf/io/zero_copy_stream.h"
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "google/protobuf/stubs/common.h"
 #include "kythe/cxx/common/init.h"
diff --git a/kythe/cxx/extractor/path_utils.cc b/kythe/cxx/extractor/path_utils.cc
index 42a76d56c..cf38fec76 100644
--- a/kythe/cxx/extractor/path_utils.cc
+++ b/kythe/cxx/extractor/path_utils.cc
@@ -16,12 +16,16 @@
 
 #include "path_utils.h"
 
+#include <cstdio>
+
 #include "absl/strings/str_format.h"
-#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/HeaderSearch.h"
-#include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/Preprocessor.h"
-#include "clang/Tooling/Tooling.h"
+#include "clang/Lex/Token.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Path.h"
 
 namespace kythe {
diff --git a/kythe/cxx/extractor/proto/proto_extractor.cc b/kythe/cxx/extractor/proto/proto_extractor.cc
index 1edffb3d5..d89b20d19 100644
--- a/kythe/cxx/extractor/proto/proto_extractor.cc
+++ b/kythe/cxx/extractor/proto/proto_extractor.cc
@@ -16,18 +16,25 @@
 
 #include "proto_extractor.h"
 
+#include <cstdlib>
+#include <cstring>
+#include <memory>
+#include <set>
 #include <string>
+#include <utility>
+#include <vector>
 
 #include "absl/log/check.h"
 #include "absl/log/log.h"
-#include "absl/strings/str_cat.h"
+#include "absl/strings/string_view.h"
 #include "google/protobuf/compiler/importer.h"
-#include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "kythe/cxx/common/file_utils.h"
 #include "kythe/cxx/common/file_vname_generator.h"
+#include "kythe/cxx/common/index_writer.h"
 #include "kythe/cxx/common/path_utils.h"
 #include "kythe/cxx/indexer/proto/search_path.h"
 #include "kythe/proto/analysis.pb.h"
+#include "kythe/proto/storage.pb.h"
 
 namespace kythe {
 namespace lang_proto {
diff --git a/kythe/cxx/extractor/proto/proto_extractor_main.cc b/kythe/cxx/extractor/proto/proto_extractor_main.cc
index 16caa27c0..b0a4b7113 100644
--- a/kythe/cxx/extractor/proto/proto_extractor_main.cc
+++ b/kythe/cxx/extractor/proto/proto_extractor_main.cc
@@ -23,13 +23,17 @@
 //   proto_extractor foo.proto bar.proto
 //   proto_extractor foo.proto -- --proto_path dir/with/my/deps
 
+#include <cstdlib>
 #include <string>
+#include <utility>
+#include <vector>
 
 #include "absl/flags/parse.h"
 #include "absl/flags/usage.h"
 #include "absl/log/check.h"
-#include "absl/log/log.h"
 #include "absl/strings/match.h"
+#include "absl/strings/string_view.h"
+#include "kythe/cxx/common/index_writer.h"
 #include "kythe/cxx/common/init.h"
 #include "kythe/cxx/common/kzip_writer.h"
 #include "kythe/cxx/extractor/proto/proto_extractor.h"
diff --git a/kythe/cxx/extractor/textproto/BUILD b/kythe/cxx/extractor/textproto/BUILD
index eba9a0312..9f40defa5 100644
--- a/kythe/cxx/extractor/textproto/BUILD
+++ b/kythe/cxx/extractor/textproto/BUILD
@@ -7,12 +7,14 @@ cc_binary(
     deps = [
         ":textproto_schema",
         "//kythe/cxx/common:file_utils",
+        "//kythe/cxx/common:index_writer",
         "//kythe/cxx/common:init",
         "//kythe/cxx/common:kzip_writer",
         "//kythe/cxx/common:path_utils",
         "//kythe/cxx/extractor/proto:lib",
         "//kythe/cxx/indexer/proto:search_path",
         "//kythe/proto:analysis_cc_proto",
+        "//kythe/proto:storage_cc_proto",
         "@com_google_absl//absl/flags:flag",
         "@com_google_absl//absl/flags:parse",
         "@com_google_absl//absl/flags:usage",
diff --git a/kythe/cxx/extractor/textproto/textproto_extractor.cc b/kythe/cxx/extractor/textproto/textproto_extractor.cc
index fd1928d56..a3d29a99f 100644
--- a/kythe/cxx/extractor/textproto/textproto_extractor.cc
+++ b/kythe/cxx/extractor/textproto/textproto_extractor.cc
@@ -23,18 +23,18 @@
 //   textproto_extractor foo.pbtxt
 //   textproto_extractor foo.pbtxt -- --proto_path dir/with/proto/deps
 
+#include <cstdlib>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "absl/flags/flag.h"
 #include "absl/flags/parse.h"
 #include "absl/flags/usage.h"
 #include "absl/log/check.h"
-#include "absl/log/log.h"
-#include "absl/strings/match.h"
-#include "absl/strings/str_cat.h"
-#include "absl/strings/str_split.h"
+#include "absl/strings/string_view.h"
 #include "kythe/cxx/common/file_utils.h"
+#include "kythe/cxx/common/index_writer.h"
 #include "kythe/cxx/common/init.h"
 #include "kythe/cxx/common/kzip_writer.h"
 #include "kythe/cxx/common/path_utils.h"
@@ -42,6 +42,7 @@
 #include "kythe/cxx/extractor/textproto/textproto_schema.h"
 #include "kythe/cxx/indexer/proto/search_path.h"
 #include "kythe/proto/analysis.pb.h"
+#include "kythe/proto/storage.pb.h"
 
 ABSL_FLAG(std::string, proto_message, "",
           "namespace-qualified message name for the textproto.");
diff --git a/kythe/cxx/extractor/textproto/textproto_schema.cc b/kythe/cxx/extractor/textproto/textproto_schema.cc
index c22430cd1..edc31fee4 100644
--- a/kythe/cxx/extractor/textproto/textproto_schema.cc
+++ b/kythe/cxx/extractor/textproto/textproto_schema.cc
@@ -18,6 +18,7 @@
 
 #include "absl/strings/ascii.h"
 #include "absl/strings/str_split.h"
+#include "absl/strings/string_view.h"
 #include "absl/strings/strip.h"
 
 namespace kythe {


Test patch:
diff --git a/kythe/cxx/common/kzip_writer_test.cc b/kythe/cxx/common/kzip_writer_test.cc
index 1f7c881b5..d80c65781 100644
--- a/kythe/cxx/common/kzip_writer_test.cc
+++ b/kythe/cxx/common/kzip_writer_test.cc
@@ -19,8 +19,10 @@
 #include <zip.h>
 
 #include <cstdlib>
+#include <string>
 #include <unordered_map>
 #include <unordered_set>
+#include <vector>
 
 #include "absl/log/log.h"
 #include "absl/status/status.h"
@@ -31,6 +33,9 @@
 #include "absl/strings/strip.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include "kythe/cxx/common/index_reader.h"
+#include "kythe/cxx/common/index_writer.h"
+#include "kythe/cxx/common/kzip_encoding.h"
 #include "kythe/cxx/common/kzip_reader.h"
 #include "kythe/cxx/common/libzip/error.h"
 #include "kythe/cxx/common/testutil.h"
diff --git a/kythe/cxx/doc/html_renderer_test.cc b/kythe/cxx/doc/html_renderer_test.cc
index e730c3927..2e3eb2266 100644
--- a/kythe/cxx/doc/html_renderer_test.cc
+++ b/kythe/cxx/doc/html_renderer_test.cc
@@ -16,12 +16,18 @@
 
 #include "kythe/cxx/doc/html_renderer.h"
 
+#include <map>
+#include <string>
+
 #include "absl/log/initialize.h"
+#include "google/protobuf/stubs/common.h"
 #include "google/protobuf/text_format.h"
 #include "gtest/gtest.h"
 #include "kythe/cxx/doc/html_markup_handler.h"
 #include "kythe/cxx/doc/javadoxygen_markup_handler.h"
+#include "kythe/cxx/doc/markup_handler.h"
 #include "kythe/proto/common.pb.h"
+#include "kythe/proto/xref.pb.h"
 
 namespace kythe {
 namespace {
diff --git a/kythe/cxx/doc/markup_handler_test.cc b/kythe/cxx/doc/markup_handler_test.cc
index b9ccf7c91..291f063c0 100644
--- a/kythe/cxx/doc/markup_handler_test.cc
+++ b/kythe/cxx/doc/markup_handler_test.cc
@@ -16,14 +16,18 @@
 
 #include "kythe/cxx/doc/markup_handler.h"
 
+#include <cstddef>
+#include <initializer_list>
 #include <stack>
+#include <string>
 
 #include "absl/log/initialize.h"
-#include "absl/log/log.h"
-#include "google/protobuf/text_format.h"
+#include "google/protobuf/stubs/common.h"
 #include "gtest/gtest.h"
 #include "kythe/cxx/doc/html_markup_handler.h"
 #include "kythe/cxx/doc/javadoxygen_markup_handler.h"
+#include "kythe/proto/common.pb.h"
+#include "kythe/proto/xref.pb.h"
 
 namespace kythe {
 namespace {
diff --git a/kythe/cxx/extractor/bazel_artifact_reader_test.cc b/kythe/cxx/extractor/bazel_artifact_reader_test.cc
index 40881b25b..9beedb93c 100644
--- a/kythe/cxx/extractor/bazel_artifact_reader_test.cc
+++ b/kythe/cxx/extractor/bazel_artifact_reader_test.cc
@@ -15,13 +15,16 @@
  */
 #include "kythe/cxx/extractor/bazel_artifact_reader.h"
 
+#include <sstream>
 #include <utility>
+#include <vector>
 
 #include "absl/strings/str_cat.h"
 #include "gmock/gmock.h"
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "google/protobuf/util/delimited_message_util.h"
 #include "gtest/gtest.h"
+#include "kythe/cxx/extractor/bazel_artifact.h"
 #include "kythe/cxx/extractor/bazel_event_reader.h"
 #include "third_party/bazel/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.pb.h"
 
diff --git a/kythe/cxx/extractor/bazel_artifact_selector_test.cc b/kythe/cxx/extractor/bazel_artifact_selector_test.cc
index 86b2b9282..df60be4d2 100644
--- a/kythe/cxx/extractor/bazel_artifact_selector_test.cc
+++ b/kythe/cxx/extractor/bazel_artifact_selector_test.cc
@@ -15,11 +15,15 @@
  */
 #include "kythe/cxx/extractor/bazel_artifact_selector.h"
 
+#include <algorithm>
+#include <functional>
 #include <optional>
 #include <string>
+#include <tuple>
 #include <vector>
 
 #include "absl/container/flat_hash_map.h"
+#include "absl/container/flat_hash_set.h"
 #include "absl/functional/any_invocable.h"
 #include "absl/log/check.h"
 #include "absl/status/status.h"
diff --git a/kythe/cxx/extractor/bazel_event_reader_test.cc b/kythe/cxx/extractor/bazel_event_reader_test.cc
index 102894f5d..8d1b1ed11 100644
--- a/kythe/cxx/extractor/bazel_event_reader_test.cc
+++ b/kythe/cxx/extractor/bazel_event_reader_test.cc
@@ -16,6 +16,8 @@
 #include "kythe/cxx/extractor/bazel_event_reader.h"
 
 #include <sstream>
+#include <string>
+#include <vector>
 
 #include "absl/strings/str_cat.h"
 #include "gmock/gmock.h"
diff --git a/kythe/cxx/extractor/cxx_extractor_test.cc b/kythe/cxx/extractor/cxx_extractor_test.cc
index ad068ac0a..f7c7aa37d 100644
--- a/kythe/cxx/extractor/cxx_extractor_test.cc
+++ b/kythe/cxx/extractor/cxx_extractor_test.cc
@@ -16,18 +16,30 @@
 
 #include "cxx_extractor.h"
 
-#include <map>
+#include <unistd.h>
+
 #include <memory>
+#include <set>
+#include <string>
+#include <system_error>
+#include <unordered_map>
+#include <utility>
+#include <vector>
 
 #include "absl/log/check.h"
 #include "absl/log/initialize.h"
 #include "absl/log/log.h"
-#include "absl/memory/memory.h"
-#include "clang/Frontend/FrontendActions.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "clang/Tooling/Tooling.h"
+#include "google/protobuf/stubs/common.h"
 #include "gtest/gtest.h"
-#include "kythe/cxx/common/path_utils.h"
+#include "kythe/cxx/extractor/cxx_details.h"
+#include "kythe/cxx/extractor/language.h"
 #include "kythe/proto/analysis.pb.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 
@@ -45,7 +57,7 @@ class CxxExtractorTest : public testing::Test {
     directories_to_remove_.insert(std::string(root_.str()));
   }
 
-  ~CxxExtractorTest() {
+  ~CxxExtractorTest() override {
     // Do the best we can to clean up the temporary files we've made.
     std::error_code err;
     for (const auto& file : files_to_remove_) {
@@ -161,7 +173,7 @@ class CxxExtractorTest : public testing::Test {
   /// \brief An `CompilationWriterSink` that forwards all calls to another sink.
   class ForwardingCompilationWriterSink : public kythe::CompilationWriterSink {
    public:
-    ForwardingCompilationWriterSink(
+    explicit ForwardingCompilationWriterSink(
         kythe::CompilationWriterSink* underlying_sink)
         : underlying_sink_(underlying_sink) {}
     void OpenIndex(const std::string& unit_hash) override {
diff --git a/kythe/cxx/extractor/objc_bazel_support_test.cc b/kythe/cxx/extractor/objc_bazel_support_test.cc
index b19b35ec9..b469796d2 100644
--- a/kythe/cxx/extractor/objc_bazel_support_test.cc
+++ b/kythe/cxx/extractor/objc_bazel_support_test.cc
@@ -16,8 +16,13 @@
 
 #include "objc_bazel_support.h"
 
+#include <string>
+#include <vector>
+
 #include "absl/log/initialize.h"
+#include "google/protobuf/stubs/common.h"
 #include "gtest/gtest.h"
+#include "third_party/bazel/src/main/protobuf/extra_actions_base.pb.h"
 
 namespace kythe {
 namespace {
diff --git a/kythe/cxx/extractor/testdata/build_config_test.cc b/kythe/cxx/extractor/testdata/build_config_test.cc
index 358c83f47..7cf7e9c2b 100644
--- a/kythe/cxx/extractor/testdata/build_config_test.cc
+++ b/kythe/cxx/extractor/testdata/build_config_test.cc
@@ -14,7 +14,8 @@
  * limitations under the License.
  */
 
-#include "absl/log/log.h"
+#include <algorithm>
+
 #include "absl/strings/string_view.h"
 #include "gmock/gmock.h"
 #include "google/protobuf/message.h"
diff --git a/kythe/cxx/extractor/testdata/claim_pragma_test.cc b/kythe/cxx/extractor/testdata/claim_pragma_test.cc
index 65be5ed71..726fbe252 100644
--- a/kythe/cxx/extractor/testdata/claim_pragma_test.cc
+++ b/kythe/cxx/extractor/testdata/claim_pragma_test.cc
@@ -1,18 +1,21 @@
-#include <algorithm>
+#include <cstddef>
 #include <memory>
 #include <string>
+#include <unordered_map>
 #include <unordered_set>
 #include <vector>
 
-#include "absl/memory/memory.h"
 #include "absl/log/check.h"
 #include "gmock/gmock.h"
+#include "google/protobuf/descriptor.h"
 #include "google/protobuf/text_format.h"
 #include "google/protobuf/util/field_comparator.h"
 #include "google/protobuf/util/message_differencer.h"
 #include "gtest/gtest.h"
 #include "kythe/cxx/extractor/cxx_extractor.h"
 #include "kythe/cxx/extractor/language.h"
+#include "kythe/proto/analysis.pb.h"
+#include "kythe/proto/filecontext.pb.h"
 
 namespace kythe {
 namespace {
diff --git a/kythe/cxx/extractor/testdata/header_only_module_test.cc b/kythe/cxx/extractor/testdata/header_only_module_test.cc
index e9585975a..c0c8c77fc 100644
--- a/kythe/cxx/extractor/testdata/header_only_module_test.cc
+++ b/kythe/cxx/extractor/testdata/header_only_module_test.cc
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include "absl/algorithm/container.h"
 #include "absl/strings/string_view.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
diff --git a/kythe/cxx/extractor/testdata/modules_test.cc b/kythe/cxx/extractor/testdata/modules_test.cc
index 82b2535d5..63cd6fb14 100644
--- a/kythe/cxx/extractor/testdata/modules_test.cc
+++ b/kythe/cxx/extractor/testdata/modules_test.cc
@@ -16,6 +16,7 @@
 
 #include "absl/algorithm/container.h"
 #include "absl/strings/match.h"
+#include "absl/strings/str_cat.h"
 #include "absl/strings/string_view.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
diff --git a/kythe/cxx/extractor/testdata/root_directory_test.cc b/kythe/cxx/extractor/testdata/root_directory_test.cc
index 705bf510a..20e3fb2eb 100644
--- a/kythe/cxx/extractor/testdata/root_directory_test.cc
+++ b/kythe/cxx/extractor/testdata/root_directory_test.cc
@@ -14,9 +14,12 @@
  * limitations under the License.
  */
 
+#include <algorithm>
 #include <optional>
 #include <string>
+#include <utility>
 
+#include "absl/strings/str_cat.h"
 #include "absl/strings/string_view.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
diff --git a/kythe/cxx/extractor/testlib.cc b/kythe/cxx/extractor/testlib.cc
index b848aa4a4..7c5d0dc91 100644
--- a/kythe/cxx/extractor/testlib.cc
+++ b/kythe/cxx/extractor/testlib.cc
@@ -17,18 +17,23 @@
 #include "kythe/cxx/extractor/testlib.h"
 
 #include <errno.h>
-#include <stdlib.h>
+#include <unistd.h>
 
-#include <iostream>
+#include <cstddef>
+#include <cstring>
+#include <memory>
 #include <optional>
+#include <string>
 #include <utility>
+#include <vector>
 
 #include "absl/container/flat_hash_map.h"
 #include "absl/log/check.h"
 #include "absl/log/log.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/string_view.h"
-#include "gmock/gmock.h"
+#include "absl/utility/utility.h"
+#include "google/protobuf/any.pb.h"
 #include "google/protobuf/message.h"
 #include "google/protobuf/text_format.h"
 #include "gtest/gtest.h"
@@ -37,6 +42,7 @@
 #include "kythe/proto/analysis.pb.h"
 #include "kythe/proto/cxx.pb.h"
 #include "kythe/proto/filecontext.pb.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Program.h"
 #include "tools/cpp/runfiles/runfiles.h"
 
diff --git a/kythe/cxx/indexer/cxx/decl_printer_test.cc b/kythe/cxx/indexer/cxx/decl_printer_test.cc
index e8311a3dd..b285da59a 100644
--- a/kythe/cxx/indexer/cxx/decl_printer_test.cc
+++ b/kythe/cxx/indexer/cxx/decl_printer_test.cc
@@ -27,7 +27,6 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"