llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Chandler Carruth (chandlerc)

<details>
<summary>Changes</summary>

Several widely included Clang headers pull in whole subsystems to name types 
they only use through pointers, references, or declarations. Because these 
headers sit underneath SourceManager.h, Sema.h, and CompilerInstance.h, nearly 
every translation unit in Clang pays for them, as well as many down-stream 
users of Clang.

Translation units across Clang and clang-tools-extra that were relying on any 
of the removed transitive includes now include what they use.

Out-of-tree code that was relying on any of these transitive includes needs the 
same treatment. The failure is an incomplete type or an undeclared identifier 
at the point of use, and the fix is to include the header that declares it; 
llvm/Support/VirtualFileSystem.h and AST/Attr.h account for most of it, since 
Basic/FileManager.h and AST/GlobalDecl.h are reached from so much of Clang.

Measured on a random 90 translation unit sample of clang's 1006 library 
translation units, compiling each directly: 280.0s drops to 267.2s of compiler 
CPU time, a 4.6% reduction. In isolation, Basic/SourceManager.h drops from 
1.11s to 0.85s and Lex/Preprocessor.h from 1.56s to 1.33s.

Assisted-by: Claude Code

---

Patch is 51.72 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/216946.diff


80 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+1) 
- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp (+1) 
- (modified) clang-tools-extra/clangd/FindSymbols.cpp (+1) 
- (modified) clang-tools-extra/clangd/ParsedAST.cpp (+1) 
- (modified) clang-tools-extra/clangd/ParsedAST.h (+1) 
- (modified) clang-tools-extra/clangd/Preamble.h (+1) 
- (modified) clang-tools-extra/clangd/unittests/ASTTests.cpp (+1) 
- (modified) clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp (+1) 
- (modified) clang-tools-extra/clangd/unittests/FindTargetTests.cpp (+1) 
- (modified) clang-tools-extra/clangd/unittests/InsertionPointTests.cpp (+1) 
- (modified) clang-tools-extra/include-cleaner/lib/FindHeaders.cpp (+1) 
- (modified) clang-tools-extra/include-cleaner/lib/HTMLReport.cpp (+1) 
- (modified) clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp (+1) 
- (modified) clang-tools-extra/include-cleaner/unittests/RecordTest.cpp (+1) 
- (modified) clang/include/clang/AST/ExprObjC.h (-1) 
- (modified) clang/include/clang/AST/GlobalDecl.h (+34-26) 
- (modified) 
clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h 
(+6-1) 
- (modified) clang/include/clang/Basic/FileManager.h (+19-10) 
- (modified) clang/include/clang/Basic/TargetInfo.h (+1-14) 
- (modified) clang/include/clang/Driver/Driver.h (+1) 
- (modified) clang/include/clang/Frontend/ASTUnit.h (+1) 
- (modified) clang/include/clang/Frontend/CompilerInstance.h (+1-4) 
- (modified) clang/include/clang/Frontend/CompilerInvocation.h (+1-1) 
- (modified) clang/include/clang/Frontend/FrontendAction.h (+4-17) 
- (modified) clang/include/clang/Sema/Sema.h (-1) 
- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/AST/Decl.cpp (+1) 
- (added) clang/lib/AST/GlobalDecl.cpp (+46) 
- (modified) clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp (+1) 
- (modified) clang/lib/Basic/FileManager.cpp (+14) 
- (modified) clang/lib/Basic/SourceManager.cpp (+1) 
- (modified) clang/lib/Basic/TargetInfo.cpp (+15) 
- (modified) clang/lib/Basic/Targets/RISCV.h (+1) 
- (modified) clang/lib/Basic/Targets/X86.h (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+1) 
- (modified) clang/lib/CIR/FrontendAction/CIRGenAction.cpp (+1) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1) 
- (modified) clang/lib/CodeGen/CGPointerAuth.cpp (+1) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) 
- (modified) clang/lib/CrossTU/CrossTranslationUnit.cpp (+1) 
- (modified) clang/lib/Format/Format.cpp (+2) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+5) 
- (modified) clang/lib/Frontend/FrontendAction.cpp (+19) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+1) 
- (modified) clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp (+1) 
- (modified) clang/lib/Frontend/Rewrite/InclusionRewriter.cpp (+1) 
- (modified) clang/lib/Frontend/TextDiagnostic.cpp (+1) 
- (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+1) 
- (modified) clang/lib/Index/IndexingAction.cpp (+1) 
- (modified) clang/lib/InstallAPI/DirectoryScanner.cpp (+1) 
- (modified) clang/lib/InstallAPI/Frontend.cpp (+1) 
- (modified) clang/lib/InstallAPI/HeaderFile.cpp (+1) 
- (modified) clang/lib/Interpreter/IncrementalAction.h (+1) 
- (modified) clang/lib/Lex/PPLexerChange.cpp (+1) 
- (modified) 
clang/lib/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.cpp
 (+1) 
- (modified) 
clang/lib/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.cpp 
(+1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+2) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2) 
- (modified) clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (+1) 
- (modified) clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (+2) 
- (modified) clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp (+1) 
- (modified) clang/lib/Testing/TestAST.cpp (+1) 
- (modified) clang/lib/Tooling/Syntax/Tokens.cpp (+1) 
- (modified) clang/tools/clang-format/ClangFormat.cpp (+1) 
- (modified) clang/tools/clang-installapi/Options.cpp (+1) 
- (modified) clang/unittests/Analysis/MacroExpansionContextTest.cpp (+1) 
- (modified) clang/unittests/CrossTU/CrossTranslationUnitTest.cpp (+1) 
- (modified) clang/unittests/Frontend/CompilerInstanceTest.cpp (+2) 
- (modified) clang/unittests/Frontend/CompilerInvocationTest.cpp (+1) 
- (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+1) 
- (modified) clang/unittests/Lex/NoTrivialPPDirectiveTracerTest.cpp (+1) 
- (modified) clang/unittests/Lex/PPCallbacksTest.cpp (+1) 
- (modified) clang/unittests/Lex/PPDependencyDirectivesTest.cpp (+1) 
- (modified) clang/unittests/Tooling/ASTSelectionTest.cpp (+1) 
- (modified) clang/unittests/Tooling/RewriterTestContext.h (+1) 
- (modified) clang/unittests/Tooling/Syntax/TreeTestBase.cpp (+1) 
- (modified) clang/unittests/Tooling/Syntax/TreeTestBase.h (+1) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 8135826ef660d..d065bb2c4bcfc 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -42,6 +42,7 @@
 
 #if CLANG_TIDY_ENABLE_STATIC_ANALYZER
 #include "clang/Analysis/PathDiagnostic.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
 #endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
 
diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 98709e924a7a1..a710c6ab728c2 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -23,6 +23,7 @@
 #include "clang/Tooling/FixIt.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::ast_matchers;
 using namespace clang::analyze_printf;
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index eeb6a56023b11..7e3067cf41464 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/StringRef.h"
 #include <limits>
 #include <optional>
+#include "clang/AST/Attr.h"
 
 #define DEBUG_TYPE "FindSymbols"
 
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index df56420cd7f24..164ab02abfba7 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -80,6 +80,7 @@
 #if CLANGD_TIDY_CHECKS
 #define CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS
 #include "../clang-tidy/ClangTidyForceLinker.h"
+#include "clang/Lex/PreprocessingRecord.h"
 #endif
 
 namespace clang {
diff --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 6640ccccf5815..03b1ad836a34c 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -36,6 +36,7 @@
 #include <optional>
 #include <string>
 #include <vector>
+#include "clang/AST/DeclCXX.h"
 
 namespace clang {
 class HeuristicResolver;
diff --git a/clang-tools-extra/clangd/Preamble.h 
b/clang-tools-extra/clangd/Preamble.h
index 8a5edf1fee1af..44f20901caad3 100644
--- a/clang-tools-extra/clangd/Preamble.h
+++ b/clang-tools-extra/clangd/Preamble.h
@@ -47,6 +47,7 @@
 #include <string>
 #include <utility>
 #include <vector>
+#include "clang/AST/ASTContext.h"
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ASTTests.cpp
index 91ae727d8c944..323a89a25e495 100644
--- a/clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -25,6 +25,7 @@
 #include <cstddef>
 #include <string>
 #include <vector>
+#include "clang/AST/DeclTemplate.h"
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp 
b/clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp
index afefa245f03e7..9ba18688066e6 100644
--- a/clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp
+++ b/clang-tools-extra/clangd/unittests/ExpectedTypeTest.cpp
@@ -15,6 +15,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include <optional>
+#include "clang/Sema/CodeCompleteConsumer.h"
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index d8c903cfcafeb..89c39b010922b 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -19,6 +19,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include <initializer_list>
+#include "clang/AST/DeclObjC.h"
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp 
b/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
index 3d5365a099f0a..d0b60e7434513 100644
--- a/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InsertionPointTests.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include "clang/AST/DeclObjC.h"
 
 namespace clang {
 namespace clangd {
diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index b96d9a70728c2..1b00f7cf6a474 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -30,6 +30,7 @@
 #include <queue>
 #include <set>
 #include <utility>
+#include "llvm/Support/Path.h"
 
 namespace clang::include_cleaner {
 namespace {
diff --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index 5b24008c1b08d..c056752fba95f 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -26,6 +26,7 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include <numeric>
+#include "llvm/Support/Path.h"
 
 namespace clang::include_cleaner {
 namespace {
diff --git a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp 
b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
index d0549825d4c40..0b4a92b485248 100644
--- a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
+++ b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Support/Registry.h"
 #include <memory>
 #include <string>
+#include "llvm/Support/VirtualFileSystem.h"
 
 LLVM_INSTANTIATE_REGISTRY(clang::include_cleaner::IncludeSpellingStrategy)
 
diff --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index cbf7bae23b365..c7abb4f23d838 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -36,6 +36,7 @@
 #include <memory>
 #include <optional>
 #include <utility>
+#include "clang/Lex/Preprocessor.h"
 
 namespace clang::include_cleaner {
 namespace {
diff --git a/clang/include/clang/AST/ExprObjC.h 
b/clang/include/clang/AST/ExprObjC.h
index 7f7b556f14329..b424530c8447c 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -13,7 +13,6 @@
 #ifndef LLVM_CLANG_AST_EXPROBJC_H
 #define LLVM_CLANG_AST_EXPROBJC_H
 
-#include "clang/AST/Attr.h"
 #include "clang/AST/ComputeDependence.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
diff --git a/clang/include/clang/AST/GlobalDecl.h 
b/clang/include/clang/AST/GlobalDecl.h
index 0f9ff9496ff88..c6a7c6431a762 100644
--- a/clang/include/clang/AST/GlobalDecl.h
+++ b/clang/include/clang/AST/GlobalDecl.h
@@ -14,14 +14,11 @@
 #ifndef LLVM_CLANG_AST_GLOBALDECL_H
 #define LLVM_CLANG_AST_GLOBALDECL_H
 
-#include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/DeclOpenACC.h"
-#include "clang/AST/DeclOpenMP.h"
-#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/ABI.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/Support/Casting.h"
@@ -30,6 +27,12 @@
 
 namespace clang {
 
+class FunctionTemplateDecl;
+class OMPDeclareMapperDecl;
+class OMPDeclareReductionDecl;
+class OpenACCDeclareDecl;
+class OpenACCRoutineDecl;
+
 enum class DynamicInitKind : unsigned {
   NoStub = 0,
   Initializer,
@@ -58,10 +61,23 @@ class GlobalDecl {
   llvm::PointerIntPair<const Decl *, 3> Value;
   unsigned MultiVersionIndex = 0;
 
+  /// Whether \p D carries the CUDA `__global__` attribute.
+  ///
+  /// Defined out of line so that this header does not have to include the
+  /// generated attribute class definitions for assertions alone.
+  CLANG_ABI static bool hasCUDAGlobalAttr(const Decl *D);
+
+  /// Whether \p D is a kernel that is referred to through an explicit
+  /// KernelReferenceKind, either directly or as a function template.
+  ///
+  /// Defined out of line so that this header does not have to include the
+  /// template declaration hierarchy for assertions alone.
+  CLANG_ABI static bool isKernelReference(const Decl *D);
+
   void Init(const Decl *D) {
     assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
     assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
-    assert(!D->hasAttr<CUDAGlobalAttr>() && "Use other ctor with GPU 
kernels!");
+    assert(!hasCUDAGlobalAttr(D) && "Use other ctor with GPU kernels!");
 
     Value.setPointer(D);
   }
@@ -85,10 +101,12 @@ class GlobalDecl {
   GlobalDecl(const BlockDecl *D) { Init(D); }
   GlobalDecl(const CapturedDecl *D) { Init(D); }
   GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
-  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
-  GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
-  GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); }
-  GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); }
+  // Defined out of line so that this header does not have to pull in the
+  // OpenMP and OpenACC declaration hierarchies for these rare cases.
+  GlobalDecl(const OMPDeclareReductionDecl *D);
+  GlobalDecl(const OMPDeclareMapperDecl *D);
+  GlobalDecl(const OpenACCRoutineDecl *D);
+  GlobalDecl(const OpenACCDeclareDecl *D);
   GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
   GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
   GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
@@ -123,9 +141,7 @@ class GlobalDecl {
   }
 
   unsigned getMultiVersionIndex() const {
-    assert(isa<FunctionDecl>(
-               getDecl()) &&
-               !cast<FunctionDecl>(getDecl())->hasAttr<CUDAGlobalAttr>() &&
+    assert(isa<FunctionDecl>(getDecl()) && !hasCUDAGlobalAttr(getDecl()) &&
            !isa<CXXConstructorDecl>(getDecl()) &&
            !isa<CXXDestructorDecl>(getDecl()) &&
            "Decl is not a plain FunctionDecl!");
@@ -133,13 +149,7 @@ class GlobalDecl {
   }
 
   KernelReferenceKind getKernelReferenceKind() const {
-    assert(((isa<FunctionDecl>(getDecl()) &&
-             cast<FunctionDecl>(getDecl())->isReferenceableKernel()) ||
-            (isa<FunctionTemplateDecl>(getDecl()) &&
-             cast<FunctionTemplateDecl>(getDecl())
-                 ->getTemplatedDecl()
-                 ->hasAttr<CUDAGlobalAttr>())) &&
-           "Decl is not a GPU kernel!");
+    assert(isKernelReference(getDecl()) && "Decl is not a GPU kernel!");
 
     return static_cast<KernelReferenceKind>(Value.getInt());
   }
@@ -163,11 +173,10 @@ class GlobalDecl {
     return GD;
   }
 
-  static KernelReferenceKind getDefaultKernelReference(const FunctionDecl *D) {
-    return (D->hasAttr<DeviceKernelAttr>() || D->getLangOpts().CUDAIsDevice)
-               ? KernelReferenceKind::Kernel
-               : KernelReferenceKind::Stub;
-  }
+  /// Defined out of line so that this header does not have to include the
+  /// generated attribute class definitions.
+  CLANG_ABI static KernelReferenceKind
+  getDefaultKernelReference(const FunctionDecl *D);
 
   GlobalDecl getWithDecl(const Decl *D) {
     GlobalDecl Result(*this);
@@ -190,8 +199,7 @@ class GlobalDecl {
   }
 
   GlobalDecl getWithMultiVersionIndex(unsigned Index) {
-    assert(isa<FunctionDecl>(getDecl()) &&
-           !cast<FunctionDecl>(getDecl())->hasAttr<CUDAGlobalAttr>() &&
+    assert(isa<FunctionDecl>(getDecl()) && !hasCUDAGlobalAttr(getDecl()) &&
            !isa<CXXConstructorDecl>(getDecl()) &&
            !isa<CXXDestructorDecl>(getDecl()) &&
            "Decl is not a plain FunctionDecl!");
diff --git 
a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h 
b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h
index 6f1259fa867dc..d0d0d4a103918 100644
--- a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h
@@ -10,13 +10,18 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMEANNOTATIONS_H
 #define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMEANNOTATIONS_H
 
-#include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
 #include <optional>
 
+namespace clang {
+// Only ever named through a pointer here, so the generated attribute
+// class definitions are not needed.
+class LifetimeBoundAttr;
+} // namespace clang
+
 namespace clang ::lifetimes {
 
 // This function is needed because Decl::isInStdNamespace will return false for
diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index f328969b1033a..daded34eb7e01 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -25,9 +25,10 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include <ctime>
 #include <map>
 #include <memory>
@@ -36,7 +37,15 @@
 
 namespace llvm {
 
-class MemoryBuffer;
+namespace vfs {
+// Only named through pointers, references and IntrusiveRefCntPtr below.
+// Including VirtualFileSystem.h here would put <chrono>, and with it libc++'s
+// <sstream>/<locale>/<format> machinery, into every translation unit that
+// touches SourceManager.
+class File;
+class FileSystem;
+class Status;
+} // end namespace vfs
 
 } // end namespace llvm
 
@@ -151,7 +160,11 @@ class FileManager : public RefCountedBase<FileManager> {
   /// \param FS if non-null, the VFS to use.  Otherwise uses
   /// llvm::vfs::getRealFileSystem().
   FileManager(const FileSystemOptions &FileSystemOpts,
-              IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
+              IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
+  /// Construct a file manager over the real file system. Kept separate from
+  /// the constructor above rather than defaulting its argument so that callers
+  /// do not need llvm::vfs::FileSystem to be complete.
+  explicit FileManager(const FileSystemOptions &FileSystemOpts);
   ~FileManager();
 
   /// Returns the number of unique real file entries cached by the file 
manager.
@@ -231,17 +244,13 @@ class FileManager : public RefCountedBase<FileManager> {
 
   llvm::vfs::FileSystem &getVirtualFileSystem() const { return *FS; }
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-  getVirtualFileSystemPtr() const {
-    return FS;
-  }
+  getVirtualFileSystemPtr() const;
 
   /// Enable or disable tracking of VFS usage. Used to not track full header
   /// search and implicit modulemap lookup.
   void trackVFSUsage(bool Active);
 
-  void setVirtualFileSystem(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
-    this->FS = std::move(FS);
-  }
+  void setVirtualFileSystem(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
 
   /// Retrieve a file entry for a "virtual" file that acts as
   /// if there were a file with the given name on disk.
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 6311b6b567a5e..5a541aaf797fe 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -35,7 +35,6 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringTable.h"
 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
-#include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/VersionTuple.h"
@@ -699,19 +698,7 @@ class TargetInfo : public TransferrableTargetInfo,
 
   // Different targets may support a different maximum width for the _BitInt
   // type, depending on what operations are supported.
-  virtual size_t getMaxBitIntWidth() const {
-    // Consider -fexperimental-max-bitint-width= first.
-    if (MaxBitIntWidth)
-      return std::min<size_t>(*MaxBitIntWidth, 
llvm::IntegerType::MAX_INT_BITS);
-
-    // FIXME: this value should be llvm::IntegerType::MAX_INT_BITS, which is
-    // maximum bit width that LLVM claims its IR can support. However, most
-    // backends currently have a bug where they only support float to int
-    // conversion (and vice versa) on types that are <= 128 bits and crash
-    // otherwise. We're setting the max supported value to 128 to be
-    // conservative.
-    return 128;
-  }
+  virtual size_t getMaxBitIntWidth() const;
 
   /// Determine whether the target has fast native support for operations
   /// on half types.
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index eece9ac5293f0..0a21a54993e14 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -33,6 +33,7 @@
 #include <set>
 #include <string>
 #include <vector>
+#include "llvm/Support/VirtualFileSystem.h"
 
 namespace llvm {
 class Triple;
diff --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index b187494e449f2..cbff9980e6906 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -47,6 +47,7 @@
 #include <string>
 #include <utility>
 #include <vector>
+#include "llvm/Support/VirtualFileSystem.h"
 
 namespace llvm {
 
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 24488e053c628..21b83dfefa842 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -558,10 +558,7 @@ class CompilerInstance : public ModuleLoader {
     return *Context;
   }
 
-  IntrusiveRefCntPtr<ASTContext> getASTContextPtr() const {
-    assert(Context && "Compiler instance has no AST context!");
-    return Context;
-  }
+  IntrusiveRefCntPtr<ASTContext> getASTContextPtr() const;
 
   void resetAndLeakASTContext() {
     llvm::BuryPointer(Context.get());
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index f71969d515be0..de38029596672 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -20,7 +20,6 @@
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Frontend/MigratorOptions.h"
 #include "clang/Frontend/PreprocessorOutputOptions.h"
-#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/ScopeExit.h"
@@ -48,6 +47,7 @@ class FileSystem;
 
 namespace clang {
 
+class AnalyzerOptions;
 class DiagnosticsEngine;
 class HeaderSearchOptions;
 class PreprocessorOptions;
diff --git a/clang/include/clang/Frontend/FrontendAction.h 
b/clang/include/clang/Frontend/FrontendAction.h
index 08c5fbc78f8ae..6fbe13633c945 100644
--- a/clang/include/clang/Frontend/FrontendAction.h
+++ b/clang/include/clang/Frontend/FrontendAction.h
@@ -20,7 +20,6 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "llvm/ADT/StringRef.h"
@@ -31,6 +30,7 @@
 
 namespace clang {
 class ASTMergeAction;
+class ASTUnit;
 class CompilerInstance;
 
 /// Abstract base class for actions which can be performed by the frontend.
@@ -83,11 +83,7 @@ class FrontendAction {
   ///
   /// \return True on success; on failure ExecutionAction() and
   /// EndSourceFileAction() will not be called.
-  virtual bool BeginSourceFileAction(CompilerInstance &CI) {
-    if (CurrentInput.isPreprocessed())
-      CI.getPreprocessor().SetMacroExpansionOnlyInDirectives();
-    return true;
-  }
+  virtual bool BeginSourceFileAction(CompilerInstance &CI);
 
   /// Callback to run the program action, using the initialized
   /// compiler instance.
@@ -100,11 +96,7 @@ class FrontendAction {
   //...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/216946
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to