https://github.com/chandlerc created https://github.com/llvm/llvm-project/pull/216946
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 >From 7881a3a56c4de6a87b44ac83d4b5bfd0565d92c5 Mon Sep 17 00:00:00 2001 From: Chandler Carruth <[email protected]> Date: Mon, 17 Aug 2026 10:19:00 -0700 Subject: [PATCH] [clang] Trim large(-ish) includes from common headers 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 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 1 + .../utils/FormatStringConverter.cpp | 1 + clang-tools-extra/clangd/FindSymbols.cpp | 1 + clang-tools-extra/clangd/ParsedAST.cpp | 1 + clang-tools-extra/clangd/ParsedAST.h | 1 + clang-tools-extra/clangd/Preamble.h | 1 + .../clangd/unittests/ASTTests.cpp | 1 + .../clangd/unittests/ExpectedTypeTest.cpp | 1 + .../clangd/unittests/FindTargetTests.cpp | 1 + .../clangd/unittests/InsertionPointTests.cpp | 1 + .../include-cleaner/lib/FindHeaders.cpp | 1 + .../include-cleaner/lib/HTMLReport.cpp | 1 + .../include-cleaner/lib/IncludeSpeller.cpp | 1 + .../include-cleaner/unittests/RecordTest.cpp | 1 + clang/include/clang/AST/ExprObjC.h | 1 - clang/include/clang/AST/GlobalDecl.h | 60 +++++++++++-------- .../LifetimeSafety/LifetimeAnnotations.h | 7 ++- clang/include/clang/Basic/FileManager.h | 29 +++++---- clang/include/clang/Basic/TargetInfo.h | 15 +---- clang/include/clang/Driver/Driver.h | 1 + clang/include/clang/Frontend/ASTUnit.h | 1 + .../include/clang/Frontend/CompilerInstance.h | 5 +- .../clang/Frontend/CompilerInvocation.h | 2 +- clang/include/clang/Frontend/FrontendAction.h | 21 ++----- clang/include/clang/Sema/Sema.h | 1 - clang/lib/AST/CMakeLists.txt | 1 + clang/lib/AST/Decl.cpp | 1 + clang/lib/AST/GlobalDecl.cpp | 46 ++++++++++++++ .../lib/Analysis/FlowSensitive/HTMLLogger.cpp | 1 + clang/lib/Basic/FileManager.cpp | 14 +++++ clang/lib/Basic/SourceManager.cpp | 1 + clang/lib/Basic/TargetInfo.cpp | 15 +++++ clang/lib/Basic/Targets/RISCV.h | 1 + clang/lib/Basic/Targets/X86.h | 1 + clang/lib/CIR/CodeGen/CIRGenerator.cpp | 1 + clang/lib/CIR/FrontendAction/CIRGenAction.cpp | 1 + clang/lib/CodeGen/CGOpenMPRuntime.cpp | 1 + clang/lib/CodeGen/CGPointerAuth.cpp | 1 + clang/lib/CodeGen/CodeGenFunction.h | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 1 + clang/lib/CrossTU/CrossTranslationUnit.cpp | 1 + clang/lib/Format/Format.cpp | 2 + clang/lib/Frontend/CompilerInstance.cpp | 5 ++ clang/lib/Frontend/FrontendAction.cpp | 19 ++++++ clang/lib/Frontend/FrontendActions.cpp | 1 + .../InterfaceStubFunctionsConsumer.cpp | 1 + .../Frontend/Rewrite/InclusionRewriter.cpp | 1 + clang/lib/Frontend/TextDiagnostic.cpp | 1 + .../ExecuteCompilerInvocation.cpp | 1 + clang/lib/Index/IndexingAction.cpp | 1 + clang/lib/InstallAPI/DirectoryScanner.cpp | 1 + clang/lib/InstallAPI/Frontend.cpp | 1 + clang/lib/InstallAPI/HeaderFile.cpp | 1 + clang/lib/Interpreter/IncrementalAction.h | 1 + clang/lib/Lex/PPLexerChange.cpp | 1 + .../SourceTransformationFrontendAction.cpp | 1 + .../TUSummaryExtractorFrontendAction.cpp | 1 + clang/lib/Sema/SemaCodeComplete.cpp | 2 + clang/lib/Sema/SemaExpr.cpp | 1 + clang/lib/Serialization/ASTReader.cpp | 2 + clang/lib/Serialization/ASTWriter.cpp | 2 + .../StaticAnalyzer/Core/PlistDiagnostics.cpp | 1 + .../StaticAnalyzer/Core/SarifDiagnostics.cpp | 2 + .../StaticAnalyzer/Frontend/ModelInjector.cpp | 1 + clang/lib/Testing/TestAST.cpp | 1 + clang/lib/Tooling/Syntax/Tokens.cpp | 1 + clang/tools/clang-format/ClangFormat.cpp | 1 + clang/tools/clang-installapi/Options.cpp | 1 + .../Analysis/MacroExpansionContextTest.cpp | 1 + .../CrossTU/CrossTranslationUnitTest.cpp | 1 + .../Frontend/CompilerInstanceTest.cpp | 2 + .../Frontend/CompilerInvocationTest.cpp | 1 + clang/unittests/Lex/HeaderSearchTest.cpp | 1 + .../Lex/NoTrivialPPDirectiveTracerTest.cpp | 1 + clang/unittests/Lex/PPCallbacksTest.cpp | 1 + .../Lex/PPDependencyDirectivesTest.cpp | 1 + clang/unittests/Tooling/ASTSelectionTest.cpp | 1 + clang/unittests/Tooling/RewriterTestContext.h | 1 + .../unittests/Tooling/Syntax/TreeTestBase.cpp | 1 + clang/unittests/Tooling/Syntax/TreeTestBase.h | 1 + 80 files changed, 237 insertions(+), 75 deletions(-) create mode 100644 clang/lib/AST/GlobalDecl.cpp 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 { /// /// This is guaranteed to only be called following a successful call to /// BeginSourceFileAction (and BeginSourceFile). - virtual void EndSourceFileAction() { - if (CurrentInput.isPreprocessed()) - // Reset the preprocessor macro expansion to the default. - getCompilerInstance().getPreprocessor().SetEnableMacroExpansion(); - } + virtual void EndSourceFileAction(); /// Callback at the end of processing a single input, to determine /// if the output files should be erased or not. @@ -192,12 +184,7 @@ class FrontendAction { virtual bool usesPreprocessorOnly() const = 0; /// For AST-based actions, the kind of translation unit we're handling. - virtual TranslationUnitKind getTranslationUnitKind() { - // The ASTContext, if exists, knows the exact TUKind of the frondend. - if (Instance && Instance->hasASTContext()) - return Instance->getASTContext().TUKind; - return TU_Complete; - } + virtual TranslationUnitKind getTranslationUnitKind(); /// Does this action support use with PCH? virtual bool hasPCHSupport() const { return true; } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 3cb0dcbbba83a..0a85cccfba2ec 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -66,7 +66,6 @@ #include "clang/Sema/Scope.h" #include "clang/Sema/SemaBase.h" #include "clang/Sema/SemaConcept.h" -#include "clang/Sema/SemaRISCV.h" #include "clang/Sema/TypoCorrection.h" #include "clang/Sema/Weak.h" #include "llvm/ADT/APInt.h" diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt index e3f74d73f21da..9c3c118b22fed 100644 --- a/clang/lib/AST/CMakeLists.txt +++ b/clang/lib/AST/CMakeLists.txt @@ -66,6 +66,7 @@ add_clang_library(clangAST ExternalASTMerger.cpp ExternalASTSource.cpp FormatString.cpp + GlobalDecl.cpp InferAlloc.cpp InheritViz.cpp ByteCode/BitcastBuffer.cpp diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 55f34e27ae535..da7ed96093752 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -62,6 +62,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Triple.h" +#include "llvm/Support/Path.h" #include <algorithm> #include <cassert> #include <cstddef> diff --git a/clang/lib/AST/GlobalDecl.cpp b/clang/lib/AST/GlobalDecl.cpp new file mode 100644 index 0000000000000..72f2848c17a0d --- /dev/null +++ b/clang/lib/AST/GlobalDecl.cpp @@ -0,0 +1,46 @@ +//===--- GlobalDecl.cpp - Global declaration holder -------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Out-of-line members of GlobalDecl. GlobalDecl is a small key type that is +// included very widely, so everything here is kept out of the header to spare +// its users the OpenMP and OpenACC declaration hierarchies, the generated +// attribute classes, and the template declaration hierarchy. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/GlobalDecl.h" +#include "clang/AST/Attr.h" +#include "clang/AST/DeclOpenACC.h" +#include "clang/AST/DeclOpenMP.h" +#include "clang/AST/DeclTemplate.h" + +using namespace clang; + +GlobalDecl::GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); } +GlobalDecl::GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); } +GlobalDecl::GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); } +GlobalDecl::GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); } + +bool GlobalDecl::hasCUDAGlobalAttr(const Decl *D) { + return D->hasAttr<CUDAGlobalAttr>(); +} + +bool GlobalDecl::isKernelReference(const Decl *D) { + if (const auto *FD = dyn_cast<FunctionDecl>(D)) + return FD->isReferenceableKernel(); + if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) + return FTD->getTemplatedDecl()->hasAttr<CUDAGlobalAttr>(); + return false; +} + +KernelReferenceKind +GlobalDecl::getDefaultKernelReference(const FunctionDecl *D) { + return (D->hasAttr<DeviceKernelAttr>() || D->getLangOpts().CUDAIsDevice) + ? KernelReferenceKind::Kernel + : KernelReferenceKind::Stub; +} diff --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp index a1469d690a3a8..cf7f289f0a111 100644 --- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp +++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp @@ -66,6 +66,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/Path.h" #include "llvm/Support/Program.h" #include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 8fb3ba0a27aad..fe80ffbebd2bf 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/IOSandbox.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include <cassert> #include <climits> @@ -63,6 +64,9 @@ static void normalizeCacheKey(StringRef &Path, // Common logic. //===----------------------------------------------------------------------===// +FileManager::FileManager(const FileSystemOptions &FSO) + : FileManager(FSO, nullptr) {} + FileManager::FileManager(const FileSystemOptions &FSO, IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64), @@ -73,6 +77,16 @@ FileManager::FileManager(const FileSystemOptions &FSO, this->FS = llvm::vfs::getRealFileSystem(); } +void FileManager::setVirtualFileSystem( + IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) { + this->FS = std::move(FS); +} + +IntrusiveRefCntPtr<llvm::vfs::FileSystem> +FileManager::getVirtualFileSystemPtr() const { + return FS; +} + FileManager::~FileManager() = default; llvm::ErrorOr<DirectoryEntryRef> diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 5540aade05ef5..136426d302f61 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/AutoConvert.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 1bb0026d8422e..0a6255b6e05d5 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/TargetParser/TargetParser.h" #include "llvm/TargetParser/Triple.h" @@ -203,6 +204,20 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) { // Out of line virtual dtor for TargetInfo. TargetInfo::~TargetInfo() {} +size_t TargetInfo::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; +} + void TargetInfo::resetDataLayout(StringRef DL) { DataLayoutString = DL.str(); } void TargetInfo::resetDataLayout() { diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index 73287c5d2d58d..edaac3e74f9d3 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -15,6 +15,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/RISCVISAInfo.h" #include "llvm/TargetParser/Triple.h" diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 9ed7035ccc230..658730ae88186 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -17,6 +17,7 @@ #include "clang/Basic/BitmaskEnum.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/Triple.h" #include "llvm/TargetParser/X86TargetParser.h" diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp index 312766d66ba7e..8cbee4ea39a4b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp @@ -18,6 +18,7 @@ #include "mlir/IR/MLIRContext.h" #include "clang/AST/DeclGroup.h" +#include "clang/AST/DeclOpenACC.h" #include "clang/CIR/CIRDataLayoutSpec.h" #include "clang/CIR/CIRGenerator.h" #include "clang/CIR/InitAllDialects.h" diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp index 78702a64da795..30f499e597cb6 100644 --- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp +++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO/Internalize.h" +#include "clang/AST/ASTContext.h" using namespace cir; using namespace clang; diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 409c222da87fc..5267d65e85ad8 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -40,6 +40,7 @@ #include "llvm/IR/Value.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/VirtualFileSystem.h" #include <cassert> #include <cstdint> #include <numeric> diff --git a/clang/lib/CodeGen/CGPointerAuth.cpp b/clang/lib/CodeGen/CGPointerAuth.cpp index 6889899107266..438d08b53a742 100644 --- a/clang/lib/CodeGen/CGPointerAuth.cpp +++ b/clang/lib/CodeGen/CGPointerAuth.cpp @@ -14,6 +14,7 @@ #include "CGCXXABI.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "clang/AST/Attr.h" #include "clang/CodeGen/CodeGenABITypes.h" #include "clang/CodeGen/ConstantInitBuilder.h" #include "llvm/Analysis/ValueTracking.h" diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index b4449948af19d..eeec32d1e0bdb 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -44,6 +44,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Transforms/Utils/SanitizerStats.h" #include <optional> +#include "clang/AST/Attr.h" namespace llvm { class BasicBlock; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e17bd72c2f052..9b9bb33522b10 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -81,6 +81,7 @@ #include "llvm/Transforms/Utils/BuildLibCalls.h" #include "llvm/Transforms/Utils/KCFIHash.h" #include "llvm/Transforms/Utils/ModuleUtils.h" +#include "llvm/Support/VirtualFileSystem.h" #include <optional> #include <set> diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 2239d54d591bf..4ef7a1fc4bf7a 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -20,6 +20,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/UnifiedSymbolResolution/USRGeneration.h" #include "llvm/ADT/Statistic.h" #include "llvm/Option/ArgList.h" diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2b6e65efbf026..fa308086da5b5 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -25,6 +25,8 @@ #include "clang/Tooling/Inclusions/HeaderIncludes.h" #include "llvm/ADT/Sequence.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/VirtualFileSystem.h" #include <functional> #include <limits> diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 66662a786e6fc..9126ad4c09dfe 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -188,6 +188,11 @@ void CompilerInstance::setPreprocessor(std::shared_ptr<Preprocessor> Value) { PP = std::move(Value); } +IntrusiveRefCntPtr<ASTContext> CompilerInstance::getASTContextPtr() const { + assert(Context && "Compiler instance has no AST context!"); + return Context; +} + void CompilerInstance::setASTContext( llvm::IntrusiveRefCntPtr<ASTContext> Value) { Context = std::move(Value); diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index c18c702d46cc7..e467ffc6ecf83 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -370,6 +370,25 @@ FrontendAction::FrontendAction() : Instance(nullptr) {} FrontendAction::~FrontendAction() {} +TranslationUnitKind FrontendAction::getTranslationUnitKind() { + // The ASTContext, if exists, knows the exact TUKind of the frondend. + if (Instance && Instance->hasASTContext()) + return Instance->getASTContext().TUKind; + return TU_Complete; +} + +bool FrontendAction::BeginSourceFileAction(CompilerInstance &CI) { + if (CurrentInput.isPreprocessed()) + CI.getPreprocessor().SetMacroExpansionOnlyInDirectives(); + return true; +} + +void FrontendAction::EndSourceFileAction() { + if (CurrentInput.isPreprocessed()) + // Reset the preprocessor macro expansion to the default. + getCompilerInstance().getPreprocessor().SetEnableMacroExpansion(); +} + void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr<ASTUnit> AST) { this->CurrentInput = CurrentInput; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4ef94c1991ee2..e7b05740b8376 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/Module.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/ASTConsumers.h" +#include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/Utils.h" diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp index 7142383fc64b3..73ab710af84fc 100644 --- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp +++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp @@ -11,6 +11,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" +#include "clang/Sema/Sema.h" #include "llvm/BinaryFormat/ELF.h" using namespace clang; diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index dd2eb6721eae2..3854cbb73e249 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -18,6 +18,7 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Path.h" #include <optional> using namespace clang; diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 5221ed4de02ff..fe54b8c083317 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Locale.h" #include <algorithm> #include <optional> +#include "llvm/Support/Path.h" using namespace clang; diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 560aef43086cb..e872f0823f23e 100644 --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -27,6 +27,7 @@ #include "clang/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.h" #include "clang/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.h" #include "clang/ScalableStaticAnalysis/SSAFForceLinker.h" // IWYU pragma: keep +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/StaticAnalyzer/Frontend/AnalyzerHelpFlags.h" #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/Option/OptTable.h" diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp index 1d98179111e78..1cdb4e14779dc 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -9,6 +9,7 @@ #include "clang/Index/IndexingAction.h" #include "IndexingContext.h" #include "clang/AST/DeclGroup.h" +#include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Index/IndexDataConsumer.h" diff --git a/clang/lib/InstallAPI/DirectoryScanner.cpp b/clang/lib/InstallAPI/DirectoryScanner.cpp index f8f708fda4ca4..80fe3938ef21e 100644 --- a/clang/lib/InstallAPI/DirectoryScanner.cpp +++ b/clang/lib/InstallAPI/DirectoryScanner.cpp @@ -9,6 +9,7 @@ #include "clang/InstallAPI/DirectoryScanner.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace llvm; using namespace llvm::MachO; diff --git a/clang/lib/InstallAPI/Frontend.cpp b/clang/lib/InstallAPI/Frontend.cpp index cce0b19b50619..b2335e659d677 100644 --- a/clang/lib/InstallAPI/Frontend.cpp +++ b/clang/lib/InstallAPI/Frontend.cpp @@ -9,6 +9,7 @@ #include "clang/InstallAPI/Frontend.h" #include "clang/AST/Availability.h" #include "clang/InstallAPI/FrontendRecords.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/StringRef.h" using namespace llvm; diff --git a/clang/lib/InstallAPI/HeaderFile.cpp b/clang/lib/InstallAPI/HeaderFile.cpp index d736a0af0dd47..63fad847abe7d 100644 --- a/clang/lib/InstallAPI/HeaderFile.cpp +++ b/clang/lib/InstallAPI/HeaderFile.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/InstallAPI/HeaderFile.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/TextAPI/Utils.h" using namespace llvm; diff --git a/clang/lib/Interpreter/IncrementalAction.h b/clang/lib/Interpreter/IncrementalAction.h index 725cdd0c27cf4..2893ff7b5baa6 100644 --- a/clang/lib/Interpreter/IncrementalAction.h +++ b/clang/lib/Interpreter/IncrementalAction.h @@ -13,6 +13,7 @@ #include "clang/Frontend/MultiplexConsumer.h" namespace llvm { +class LLVMContext; class Module; } diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index b44bf2cd3c253..552902e70f094 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/Path.h" +#include "llvm/Support/VirtualFileSystem.h" #include <optional> using namespace clang; diff --git a/clang/lib/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.cpp b/clang/lib/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.cpp index b7886af72479d..3592f131e8217 100644 --- a/clang/lib/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.cpp +++ b/clang/lib/ScalableStaticAnalysis/Frontend/SourceTransformationFrontendAction.cpp @@ -29,6 +29,7 @@ #include <string> #include <utility> #include <vector> +#include "clang/AST/ASTContext.h" using namespace clang; using namespace ssaf; diff --git a/clang/lib/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.cpp b/clang/lib/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.cpp index bb4caef8f99ab..dc72fa20ee02b 100644 --- a/clang/lib/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.cpp +++ b/clang/lib/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.cpp @@ -8,6 +8,7 @@ #include "clang/ScalableStaticAnalysis/Frontend/TUSummaryExtractorFrontendAction.h" #include "clang/AST/ASTConsumer.h" +#include "clang/AST/ASTContext.h" #include "clang/Basic/DiagnosticFrontend.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/MultiplexConsumer.h" diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 3b3c9a476421d..1821ecf41a005 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -54,7 +54,9 @@ #include "llvm/ADT/Twine.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" #include <list> diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0908841dca8bf..4364fdb5de85a 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -65,6 +65,7 @@ #include "clang/Sema/Template.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/TimeProfiler.h" diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index c4c4b22f85093..e3e3d29f3273e 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -81,6 +81,7 @@ #include "clang/Sema/Sema.h" #include "clang/Sema/SemaCUDA.h" #include "clang/Sema/SemaObjC.h" +#include "clang/Sema/SemaRISCV.h" #include "clang/Sema/Weak.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ASTDeserializationListener.h" @@ -141,6 +142,7 @@ #include <tuple> #include <utility> #include <vector> +#include "llvm/Support/VirtualFileSystem.h" using namespace clang; using namespace clang::serialization; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index f34b2ff182bc8..4db2bfb900ac9 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -70,6 +70,7 @@ #include "clang/Sema/Sema.h" #include "clang/Sema/SemaCUDA.h" #include "clang/Sema/SemaObjC.h" +#include "clang/Sema/SemaRISCV.h" #include "clang/Sema/Weak.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ASTReader.h" @@ -118,6 +119,7 @@ #include <tuple> #include <utility> #include <vector> +#include "llvm/Support/VirtualFileSystem.h" using namespace clang; using namespace clang::serialization; diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index 3e3fff900cde8..ee6b613e579f1 100644 --- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -25,6 +25,7 @@ #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Support/FileSystem.h" #include <memory> #include <optional> diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp index 1d5139c067c7b..8d85d5543e47d 100644 --- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp @@ -25,6 +25,8 @@ #include "llvm/ADT/StringMap.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include <memory> using namespace llvm; diff --git a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp index 531c642bf4f31..ee59e6a7be939 100644 --- a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp @@ -17,6 +17,7 @@ #include "clang/Frontend/FrontendAction.h" #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/FileSystem.h" diff --git a/clang/lib/Testing/TestAST.cpp b/clang/lib/Testing/TestAST.cpp index f99f649f52e9c..af5eedf9beddb 100644 --- a/clang/lib/Testing/TestAST.cpp +++ b/clang/lib/Testing/TestAST.cpp @@ -18,6 +18,7 @@ #include "gtest/gtest.h" #include <string> +#include "clang/Lex/Preprocessor.h" namespace clang { namespace { diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp index 6b75c17cab67e..0550dddf8d8ea 100644 --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -28,6 +28,7 @@ #include <string> #include <utility> #include <vector> +#include "llvm/Support/Path.h" using namespace clang; using namespace clang::syntax; diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index de513d942df1a..3703ea6488df5 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/Process.h" +#include "llvm/Support/VirtualFileSystem.h" #include <fstream> using namespace llvm; diff --git a/clang/tools/clang-installapi/Options.cpp b/clang/tools/clang-installapi/Options.cpp index f484d6f33ad8f..f0ad4501a4593 100644 --- a/clang/tools/clang-installapi/Options.cpp +++ b/clang/tools/clang-installapi/Options.cpp @@ -16,6 +16,7 @@ #include "llvm/BinaryFormat/Magic.h" #include "llvm/Support/JSON.h" #include "llvm/Support/Program.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/TargetParser/Host.h" #include "llvm/TextAPI/DylibReader.h" #include "llvm/TextAPI/TextAPIError.h" diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp index 25a76edbfdc49..d180f3be3dc0a 100644 --- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp +++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp @@ -23,6 +23,7 @@ #include "clang/Parse/Parser.h" #include "llvm/ADT/SmallString.h" #include "gtest/gtest.h" +#include "llvm/Support/VirtualFileSystem.h" // static bool HACK_EnableDebugInUnitTest = (::llvm::DebugFlag = true); diff --git a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp index 96d0c1954505c..8457c1b16ad1c 100644 --- a/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp +++ b/clang/unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -17,6 +17,7 @@ #include "llvm/Support/ToolOutputFile.h" #include "gtest/gtest.h" #include <cassert> +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" namespace clang { namespace cross_tu { diff --git a/clang/unittests/Frontend/CompilerInstanceTest.cpp b/clang/unittests/Frontend/CompilerInstanceTest.cpp index 41908e9c0f254..f4d47bdfbc676 100644 --- a/clang/unittests/Frontend/CompilerInstanceTest.cpp +++ b/clang/unittests/Frontend/CompilerInstanceTest.cpp @@ -20,6 +20,8 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/VirtualFileSystem.h" #include "gtest/gtest.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PPCallbacks.h" using namespace llvm; using namespace clang; diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index be537ae88bdf9..ac881c3a3217c 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -15,6 +15,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/TargetParser/Host.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp index 0213bfeb8e221..845115cdfa906 100644 --- a/clang/unittests/Lex/HeaderSearchTest.cpp +++ b/clang/unittests/Lex/HeaderSearchTest.cpp @@ -20,6 +20,7 @@ #include "gtest/gtest.h" #include <memory> #include <string> +#include "llvm/Support/VirtualFileSystem.h" namespace clang { namespace { diff --git a/clang/unittests/Lex/NoTrivialPPDirectiveTracerTest.cpp b/clang/unittests/Lex/NoTrivialPPDirectiveTracerTest.cpp index d79c1428e55bb..0833ac59dfc06 100644 --- a/clang/unittests/Lex/NoTrivialPPDirectiveTracerTest.cpp +++ b/clang/unittests/Lex/NoTrivialPPDirectiveTracerTest.cpp @@ -21,6 +21,7 @@ #include "gtest/gtest.h" #include <cstddef> #include <initializer_list> +#include "llvm/Support/VirtualFileSystem.h" using namespace clang; diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index 9533fbc776e6e..4f2c158f6a8ab 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" #include "gtest/gtest.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace clang; diff --git a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp index 3b369ffc60d27..6a62b36241768 100644 --- a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp +++ b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp @@ -22,6 +22,7 @@ #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include <optional> +#include "llvm/Support/VirtualFileSystem.h" using namespace clang; diff --git a/clang/unittests/Tooling/ASTSelectionTest.cpp b/clang/unittests/Tooling/ASTSelectionTest.cpp index 0f60749725cde..de4b1979f1ebd 100644 --- a/clang/unittests/Tooling/ASTSelectionTest.cpp +++ b/clang/unittests/Tooling/ASTSelectionTest.cpp @@ -10,6 +10,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Tooling/Refactoring/ASTSelection.h" #include <optional> +#include "clang/AST/ExprObjC.h" using namespace clang; using namespace tooling; diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h index 020ef60aa16ae..46bd3dcbb510a 100644 --- a/clang/unittests/Tooling/RewriterTestContext.h +++ b/clang/unittests/Tooling/RewriterTestContext.h @@ -21,6 +21,7 @@ #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" namespace clang { diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp index dad75854240ef..2453b1f03d802 100644 --- a/clang/unittests/Tooling/Syntax/TreeTestBase.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTestBase.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/Error.h" #include "llvm/Testing/Annotations/Annotations.h" #include "gtest/gtest.h" +#include "clang/AST/ASTContext.h" using namespace clang; using namespace clang::syntax; diff --git a/clang/unittests/Tooling/Syntax/TreeTestBase.h b/clang/unittests/Tooling/Syntax/TreeTestBase.h index e85d76c9efed7..780778030fb6d 100644 --- a/clang/unittests/Tooling/Syntax/TreeTestBase.h +++ b/clang/unittests/Tooling/Syntax/TreeTestBase.h @@ -25,6 +25,7 @@ #include "llvm/Testing/Annotations/Annotations.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "llvm/Support/VirtualFileSystem.h" namespace clang { namespace syntax { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
