Skip to content

[5.9] Cherry-pick missing cas-related commits from stable/20221013 #6618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
75da6cf
[clang][cas] Factor IncludeTreeBuilder out of IncludeTreeActionConsumer
benlangmuir Mar 15, 2023
e34a755
[clang][cas] Remove PPCallbacks from DependencyActionController
benlangmuir Mar 15, 2023
a450905
[clang][cas] Scaffolding for modules with include-tree
benlangmuir Mar 15, 2023
737d65e
[clang][cas] Move IncludeFile after IncludeTree in the header NFC
benlangmuir Mar 22, 2023
cb78dfa
[clang][cas] Move IncludeFile[List] to IncludeTree::File[List] NFC
benlangmuir Mar 22, 2023
c3fb291
[clang][cas] Basic building and importing modules with include-tree
benlangmuir Mar 15, 2023
dd7e074
[clang][cas] include-tree support for submodule visibility
benlangmuir Mar 16, 2023
c3eb502
[clang][cas] Handle include-tree for a file considered part of the mo…
benlangmuir Mar 16, 2023
7f474cb
[clang][cas] Add a test for include-tree with explicit imports
benlangmuir Mar 16, 2023
56691d9
[clang][cas] Move include-tree and cas-fs IDs out of Module into ASTC…
benlangmuir Mar 23, 2023
6c5e143
[clang][cas] IncludeTree filesystem merges from imported PCH/modules
benlangmuir Mar 23, 2023
5d75294
[clang][cas] Create explicit IncludeTree::ModuleMap
benlangmuir Mar 22, 2023
1658593
[clang][cas] Add tests for include-tree module map
benlangmuir Mar 23, 2023
6d400c9
[clang][cas] Correctly split out modules that are only imported for v…
benlangmuir Mar 23, 2023
0f206d4
[clang][cas] Fix include-tree with pch importing public/private modules
benlangmuir Mar 23, 2023
531d49b
[clang][cas] Make missing include-tree id an error
benlangmuir Mar 24, 2023
8c8da77
[clang][cas] Allow non-existent fmodule-name
benlangmuir Mar 26, 2023
d52f5d4
[clang][cas] Switch to chained representation of IncludeTree::FileList
benlangmuir Mar 27, 2023
fe61f9d
[clang][cas] Add simple prefix-mapping test for include-tree modules
benlangmuir Mar 26, 2023
0d7dd5e
[clang][cas] Skip duplicates in forEachFile
benlangmuir Mar 27, 2023
91b39ea
[clang][cas] Update tests for stable/20221013 branch
benlangmuir Mar 28, 2023
7a73648
[clang][cas] Fall back to textual include for missing inferred submod…
benlangmuir Mar 28, 2023
5fa22a8
[clang][cas] Extend fix for private modules to module builds
benlangmuir Mar 31, 2023
20d4eb7
[clang][deps] Remove -coverage-data-file and -coverage-notes-file fro…
benlangmuir Mar 30, 2023
379b7b4
[clang][cas] Strip -coverage-data-file and -coverage-notes-file from PCH
benlangmuir Mar 30, 2023
a707b12
[clang][cas] Move -fdepscan-prefix-map-* options to clang driver
benlangmuir Mar 29, 2023
3c0fb9f
[libclang][cas] Update for prefix mapping API change
benlangmuir Apr 4, 2023
a8fedd5
[clang][cas] Add a depscan-prefix-map feature flag
benlangmuir Apr 4, 2023
4f89fbe
[clang][cas] Prefix map -fdepfile-entry
benlangmuir Mar 30, 2023
5cff5c0
[clang][modules] Handle explicit modules when checking for .Private -…
benlangmuir Apr 3, 2023
3409d7d
[libclang] Add APIs to report dependency scanning info as opaque objects
akyrtzi Mar 21, 2023
0e9192b
[libclang/depscan] Fix use-after-free issue when using diagnostics of…
akyrtzi Mar 31, 2023
6a5c8b7
[clang/cas/dep-scan] Include the translation unit cache key in the sc…
akyrtzi Mar 21, 2023
fa6ed10
[libclang][cas] Expose the module and TU cache keys from the libclang…
akyrtzi Mar 22, 2023
f560e4a
[libclang][cas] Avoid using `CachingOnDiskFileSystem` when include-tr…
akyrtzi Apr 3, 2023
fd562de
[clang][cas] Switch to include-tree by default
benlangmuir Apr 3, 2023
55fdf8a
[libclang][cas] Fix local path that showed up in test
benlangmuir Apr 4, 2023
a8b1c4f
Fix doxygen comment
cachemeifyoucan Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clang/include/clang-c/CXString.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "clang-c/ExternC.h"
#include "clang-c/Platform.h"
#include <stddef.h>

LLVM_CLANG_C_EXTERN_C_BEGIN

Expand Down Expand Up @@ -44,6 +45,14 @@ typedef struct {
unsigned Count;
} CXStringSet;

/**
* An array of C strings.
*/
typedef struct {
const char **Strings;
size_t Count;
} CXCStringArray;

/**
* Retrieve the character data associated with the given string.
*/
Expand Down
278 changes: 262 additions & 16 deletions clang/include/clang-c/Dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,8 @@ typedef size_t CXModuleLookupOutputCallback(void *Context,
char *Output, size_t MaxLen);

/**
* See \c clang_experimental_DependencyScannerWorker_getFileDependencies_v5.
* Returns diagnostics in an unstructured CXString instead of CXDiagnosticSet.
*/
CINDEX_LINKAGE enum CXErrorCode
clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
CXDependencyScannerWorker Worker, int argc, const char *const *argv,
const char *ModuleName, const char *WorkingDirectory, void *MDCContext,
CXModuleDiscoveredCallback *MDC, void *MLOContext,
CXModuleLookupOutputCallback *MLO, unsigned Options,
CXFileDependenciesList **Out, CXString *error);

/**
* Deprecated, use \c clang_experimental_DependencyScannerWorker_getDepGraph.
*
* Calculates the list of file dependencies for a particular compiler
* invocation.
*
Expand Down Expand Up @@ -351,19 +341,275 @@ clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
* \param [out] Out A non-NULL pointer to store the resulting dependencies. The
* output must be freed by calling
* \c clang_experimental_FileDependenciesList_dispose.
* \param [out] OutDiags The diagnostics emitted during scanning. These must be
* always freed by calling \c clang_disposeDiagnosticSet.
* \param [out] error the error string to pass back to client (if any).
*
* \returns \c CXError_Success on success; otherwise a non-zero \c CXErrorCode
* indicating the kind of error.
*/
CINDEX_LINKAGE enum CXErrorCode
clang_experimental_DependencyScannerWorker_getFileDependencies_v5(
clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
CXDependencyScannerWorker Worker, int argc, const char *const *argv,
const char *ModuleName, const char *WorkingDirectory, void *MDCContext,
CXModuleDiscoveredCallback *MDC, void *MLOContext,
CXModuleLookupOutputCallback *MLO, unsigned Options,
CXFileDependenciesList **Out, CXDiagnosticSet *OutDiags);
CXFileDependenciesList **Out, CXString *error);

/**
* Output of \c clang_experimental_DependencyScannerWorker_getDepGraph.
*/
typedef struct CXOpaqueDepGraph *CXDepGraph;

/**
* An individual module dependency that is part of an overall compilation
* \c CXDepGraph.
*/
typedef struct CXOpaqueDepGraphModule *CXDepGraphModule;

/**
* An individual command-line invocation that is part of an overall compilation
* \c CXDepGraph.
*/
typedef struct CXOpaqueDepGraphTUCommand *CXDepGraphTUCommand;

/**
* Settings to use for the
* \c clang_experimental_DependencyScannerWorker_getDepGraph action.
*/
typedef struct CXOpaqueDependencyScannerWorkerScanSettings
*CXDependencyScannerWorkerScanSettings;

/**
* Creates a set of settings for
* \c clang_experimental_DependencyScannerWorker_getDepGraph action.
* Must be disposed with
* \c clang_experimental_DependencyScannerWorkerScanSettings_dispose.
* Memory for settings is not copied. Any provided pointers must be valid until
* the call to \c clang_experimental_DependencyScannerWorker_getDepGraph.
*
* \param argc the number of compiler invocation arguments (including argv[0]).
* \param argv the compiler driver invocation arguments (including argv[0]).
* \param ModuleName If non-null, the dependencies of the named module are
* returned. Otherwise, the dependencies of the whole
* translation unit are returned.
* \param WorkingDirectory the directory in which the invocation runs.
* \param MLOContext the context that will be passed to \c MLO each time it is
* called.
* \param MLO a callback that is called to determine the paths of output files
* for each module dependency. This may receive the same module on
* different workers. This should be NULL if
* \c clang_experimental_DependencyScannerService_create_v1 was
* called with \c CXDependencyMode_Flat. This callback will be called
* on the same thread that called \c
* clang_experimental_DependencyScannerWorker_getDepGraph.
*/
CINDEX_LINKAGE CXDependencyScannerWorkerScanSettings
clang_experimental_DependencyScannerWorkerScanSettings_create(
int argc, const char *const *argv, const char *ModuleName,
const char *WorkingDirectory, void *MLOContext,
CXModuleLookupOutputCallback *MLO);

/**
* Dispose of a \c CXDependencyScannerWorkerScanSettings object.
*/
CINDEX_LINKAGE void
clang_experimental_DependencyScannerWorkerScanSettings_dispose(
CXDependencyScannerWorkerScanSettings);

/**
* Produces the dependency graph for a particular compiler invocation.
*
* \param Settings object created via
* \c clang_experimental_DependencyScannerWorkerScanSettings_create.
* \param [out] Out A non-NULL pointer to store the resulting dependencies. The
* output must be freed by calling
* \c clang_experimental_DepGraph_dispose.
*
* \returns \c CXError_Success on success; otherwise a non-zero \c CXErrorCode
* indicating the kind of error. When returning \c CXError_Failure there will
* be a \c CXDepGraph object on \p Out that can be used to get diagnostics via
* \c clang_experimental_DepGraph_getDiagnostics.
*/
CINDEX_LINKAGE enum CXErrorCode
clang_experimental_DependencyScannerWorker_getDepGraph(
CXDependencyScannerWorker, CXDependencyScannerWorkerScanSettings Settings,
CXDepGraph *Out);

/**
* Dispose of a \c CXDepGraph object.
*/
CINDEX_LINKAGE void clang_experimental_DepGraph_dispose(CXDepGraph);

/**
* \returns the number of \c CXDepGraphModule objects in the graph.
*/
CINDEX_LINKAGE size_t clang_experimental_DepGraph_getNumModules(CXDepGraph);

/**
* \returns the \c CXDepGraphModule object at the given \p Index.
*
* The \c CXDepGraphModule object is only valid to use while \c CXDepGraph is
* valid. Must be disposed with \c clang_experimental_DepGraphModule_dispose.
*/
CINDEX_LINKAGE CXDepGraphModule
clang_experimental_DepGraph_getModule(CXDepGraph, size_t Index);

CINDEX_LINKAGE void clang_experimental_DepGraphModule_dispose(CXDepGraphModule);

/**
* \returns the name of the module. This may include `:` for C++20 module
* partitions, or a header-name for C++20 header units.
*
* The string is only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraphModule_getName(CXDepGraphModule);

/**
* \returns the context hash of a module represents the set of compiler options
* that may make one version of a module incompatible from another. This
* includes things like language mode, predefined macros, header search paths,
* etc...
*
* Modules with the same name but a different \c ContextHash should be treated
* as separate modules for the purpose of a build.
*
* The string is only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraphModule_getContextHash(CXDepGraphModule);

/**
* \returns the path to the modulemap file which defines this module. If there's
* no modulemap (e.g. for a C++ module) returns \c NULL.
*
* This can be used to explicitly build this module. This file will
* additionally appear in \c FileDeps as a dependency.
*
* The string is only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE const char *
clang_experimental_DepGraphModule_getModuleMapPath(CXDepGraphModule);

/**
* \returns the list of files which this module directly depends on.
*
* If any of these change then the module needs to be rebuilt.
*
* The strings are only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE CXCStringArray
clang_experimental_DepGraphModule_getFileDeps(CXDepGraphModule);

/**
* \returns the list of modules which this module direct depends on.
*
* This does include the context hash. The format is
* `<module-name>:<context-hash>`
*
* The strings are only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE CXCStringArray
clang_experimental_DepGraphModule_getModuleDeps(CXDepGraphModule);

/**
* \returns the canonical command line to build this module.
*
* The strings are only valid to use while the \c CXDepGraphModule object is
* valid.
*/
CINDEX_LINKAGE CXCStringArray
clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule);

/**
* \returns the \c ActionCache key for this module, if any.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule);

/**
* \returns the number \c CXDepGraphTUCommand objects in the graph.
*/
CINDEX_LINKAGE size_t clang_experimental_DepGraph_getNumTUCommands(CXDepGraph);

/**
* \returns the \c CXDepGraphTUCommand object at the given \p Index.
*
* The \c CXDepGraphTUCommand object is only valid to use while \c CXDepGraph is
* valid. Must be disposed with \c clang_experimental_DepGraphTUCommand_dispose.
*/
CINDEX_LINKAGE CXDepGraphTUCommand
clang_experimental_DepGraph_getTUCommand(CXDepGraph, size_t Index);

/**
* Dispose of a \c CXDepGraphTUCommand object.
*/
CINDEX_LINKAGE void
clang_experimental_DepGraphTUCommand_dispose(CXDepGraphTUCommand);

/**
* \returns the executable name for the command.
*
* The string is only valid to use while the \c CXDepGraphTUCommand object is
* valid.
*/
CINDEX_LINKAGE const char *
clang_experimental_DepGraphTUCommand_getExecutable(CXDepGraphTUCommand);

/**
* \returns the canonical command line to build this translation unit.
*
* The strings are only valid to use while the \c CXDepGraphTUCommand object is
* valid.
*/
CINDEX_LINKAGE CXCStringArray
clang_experimental_DepGraphTUCommand_getBuildArguments(CXDepGraphTUCommand);

/**
* \returns the \c ActionCache key for this translation unit, if any.
*/
CINDEX_LINKAGE const char *
clang_experimental_DepGraphTUCommand_getCacheKey(CXDepGraphTUCommand);

/**
* \returns the list of files which this translation unit directly depends on.
*
* The strings are only valid to use while the \c CXDepGraph object is valid.
*/
CINDEX_LINKAGE
CXCStringArray clang_experimental_DepGraph_getTUFileDeps(CXDepGraph);

/**
* \returns the list of modules which this translation unit direct depends on.
*
* This does include the context hash. The format is
* `<module-name>:<context-hash>`
*
* The strings are only valid to use while the \c CXDepGraph object is valid.
*/
CINDEX_LINKAGE
CXCStringArray clang_experimental_DepGraph_getTUModuleDeps(CXDepGraph);

/**
* \returns the context hash of the C++20 module this translation unit exports.
*
* If the translation unit is not a module then this is empty.
*
* The string is only valid to use while the \c CXDepGraph object is valid.
*/
CINDEX_LINKAGE
const char *clang_experimental_DepGraph_getTUContextHash(CXDepGraph);

/**
* \returns The diagnostics emitted during scanning. These must be always freed
* by calling \c clang_disposeDiagnosticSet.
*/
CINDEX_LINKAGE
CXDiagnosticSet clang_experimental_DepGraph_getDiagnostics(CXDepGraph);

/**
* @}
Expand Down
22 changes: 22 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// For module code-gen cases, this is the top-level module we are building.
Module *TopLevelModule = nullptr;

/// The include tree that is being built, if any.
/// See \c FrontendOptions::CASIncludeTreeID.
std::optional<std::string> CASIncludeTreeID;

/// The cas-fs tree that is being built, if any.
/// See \c FileSystemOptions::CASFileSystemRootID.
std::optional<std::string> CASFileSystemRootID;

static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
static constexpr unsigned GeneralTypesLog2InitSize = 9;
static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
Expand Down Expand Up @@ -1086,6 +1094,20 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// Get module under construction, nullptr if this is not a C++20 module.
Module *getModuleForCodeGen() const { return TopLevelModule; }

std::optional<std::string> getCASIncludeTreeID() const {
return CASIncludeTreeID;
}
void setCASIncludeTreeID(std::string ID) {
CASIncludeTreeID = std::move(ID);
}

std::optional<std::string> getCASFileSystemRootID() const {
return CASFileSystemRootID;
}
void setCASFileSystemRootID(std::string ID) {
CASFileSystemRootID = std::move(ID);
}

TranslationUnitDecl *getTranslationUnitDecl() const {
return TUDecl->getMostRecentDecl();
}
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticCASKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def err_cas_missing_root_id : Error<
"CAS missing expected root-id '%0'">, DefaultFatal;
def err_cas_cannot_parse_root_id_for_module : Error<
"CAS cannot parse root-id '%0' for module '%1'">, DefaultFatal;
def err_cas_cannot_parse_include_tree_id : Error<
"CAS cannot parse include-tree-id '%0'">, DefaultFatal;
def err_cas_missing_include_tree_id : Error<
"CAS missing expected include-tree '%0'">, DefaultFatal;

def warn_clang_cache_disabled_caching: Warning<
"caching disabled because %0">,
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def err_missing_module_name : Error<
DefaultFatal;
def err_missing_module : Error<
"no module named '%0' declared in module map file '%1'">, DefaultFatal;
def err_missing_module_include_tree : Error<
"no module named '%0' declared in include-tree module map '%1'">, DefaultFatal;
def err_no_submodule : Error<"no submodule named %0 in module '%1'">;
def err_no_submodule_suggest : Error<
"no submodule named %0 in module '%1'; did you mean '%2'?">;
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ def warn_defined_in_function_type_macro : Extension<
"macro expansion producing 'defined' has undefined behavior">,
InGroup<ExpansionToDefined>;

def err_pp_missing_module_include_tree : Error<
"no module named '%0' declared in include-tree module map">, DefaultFatal;

let CategoryName = "Nullability Issue" in {

def err_pp_assume_nonnull_syntax : Error<"expected 'begin' or 'end'">;
Expand Down
Loading