Skip to content

Commit f8abdec

Browse files
authored
Merge pull request #6618 from akyrtzi/pr/5.9/cas-cherry-pick
[5.9] Cherry-pick missing cas-related commits from `stable/20221013`
2 parents 4211cff + a8b1c4f commit f8abdec

File tree

82 files changed

+5008
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+5008
-1019
lines changed

clang/include/clang-c/CXString.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "clang-c/ExternC.h"
1818
#include "clang-c/Platform.h"
19+
#include <stddef.h>
1920

2021
LLVM_CLANG_C_EXTERN_C_BEGIN
2122

@@ -44,6 +45,14 @@ typedef struct {
4445
unsigned Count;
4546
} CXStringSet;
4647

48+
/**
49+
* An array of C strings.
50+
*/
51+
typedef struct {
52+
const char **Strings;
53+
size_t Count;
54+
} CXCStringArray;
55+
4756
/**
4857
* Retrieve the character data associated with the given string.
4958
*/

clang/include/clang-c/Dependencies.h

Lines changed: 262 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,8 @@ typedef size_t CXModuleLookupOutputCallback(void *Context,
310310
char *Output, size_t MaxLen);
311311

312312
/**
313-
* See \c clang_experimental_DependencyScannerWorker_getFileDependencies_v5.
314-
* Returns diagnostics in an unstructured CXString instead of CXDiagnosticSet.
315-
*/
316-
CINDEX_LINKAGE enum CXErrorCode
317-
clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
318-
CXDependencyScannerWorker Worker, int argc, const char *const *argv,
319-
const char *ModuleName, const char *WorkingDirectory, void *MDCContext,
320-
CXModuleDiscoveredCallback *MDC, void *MLOContext,
321-
CXModuleLookupOutputCallback *MLO, unsigned Options,
322-
CXFileDependenciesList **Out, CXString *error);
323-
324-
/**
313+
* Deprecated, use \c clang_experimental_DependencyScannerWorker_getDepGraph.
314+
*
325315
* Calculates the list of file dependencies for a particular compiler
326316
* invocation.
327317
*
@@ -351,19 +341,275 @@ clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
351341
* \param [out] Out A non-NULL pointer to store the resulting dependencies. The
352342
* output must be freed by calling
353343
* \c clang_experimental_FileDependenciesList_dispose.
354-
* \param [out] OutDiags The diagnostics emitted during scanning. These must be
355-
* always freed by calling \c clang_disposeDiagnosticSet.
344+
* \param [out] error the error string to pass back to client (if any).
356345
*
357346
* \returns \c CXError_Success on success; otherwise a non-zero \c CXErrorCode
358347
* indicating the kind of error.
359348
*/
360349
CINDEX_LINKAGE enum CXErrorCode
361-
clang_experimental_DependencyScannerWorker_getFileDependencies_v5(
350+
clang_experimental_DependencyScannerWorker_getFileDependencies_v4(
362351
CXDependencyScannerWorker Worker, int argc, const char *const *argv,
363352
const char *ModuleName, const char *WorkingDirectory, void *MDCContext,
364353
CXModuleDiscoveredCallback *MDC, void *MLOContext,
365354
CXModuleLookupOutputCallback *MLO, unsigned Options,
366-
CXFileDependenciesList **Out, CXDiagnosticSet *OutDiags);
355+
CXFileDependenciesList **Out, CXString *error);
356+
357+
/**
358+
* Output of \c clang_experimental_DependencyScannerWorker_getDepGraph.
359+
*/
360+
typedef struct CXOpaqueDepGraph *CXDepGraph;
361+
362+
/**
363+
* An individual module dependency that is part of an overall compilation
364+
* \c CXDepGraph.
365+
*/
366+
typedef struct CXOpaqueDepGraphModule *CXDepGraphModule;
367+
368+
/**
369+
* An individual command-line invocation that is part of an overall compilation
370+
* \c CXDepGraph.
371+
*/
372+
typedef struct CXOpaqueDepGraphTUCommand *CXDepGraphTUCommand;
373+
374+
/**
375+
* Settings to use for the
376+
* \c clang_experimental_DependencyScannerWorker_getDepGraph action.
377+
*/
378+
typedef struct CXOpaqueDependencyScannerWorkerScanSettings
379+
*CXDependencyScannerWorkerScanSettings;
380+
381+
/**
382+
* Creates a set of settings for
383+
* \c clang_experimental_DependencyScannerWorker_getDepGraph action.
384+
* Must be disposed with
385+
* \c clang_experimental_DependencyScannerWorkerScanSettings_dispose.
386+
* Memory for settings is not copied. Any provided pointers must be valid until
387+
* the call to \c clang_experimental_DependencyScannerWorker_getDepGraph.
388+
*
389+
* \param argc the number of compiler invocation arguments (including argv[0]).
390+
* \param argv the compiler driver invocation arguments (including argv[0]).
391+
* \param ModuleName If non-null, the dependencies of the named module are
392+
* returned. Otherwise, the dependencies of the whole
393+
* translation unit are returned.
394+
* \param WorkingDirectory the directory in which the invocation runs.
395+
* \param MLOContext the context that will be passed to \c MLO each time it is
396+
* called.
397+
* \param MLO a callback that is called to determine the paths of output files
398+
* for each module dependency. This may receive the same module on
399+
* different workers. This should be NULL if
400+
* \c clang_experimental_DependencyScannerService_create_v1 was
401+
* called with \c CXDependencyMode_Flat. This callback will be called
402+
* on the same thread that called \c
403+
* clang_experimental_DependencyScannerWorker_getDepGraph.
404+
*/
405+
CINDEX_LINKAGE CXDependencyScannerWorkerScanSettings
406+
clang_experimental_DependencyScannerWorkerScanSettings_create(
407+
int argc, const char *const *argv, const char *ModuleName,
408+
const char *WorkingDirectory, void *MLOContext,
409+
CXModuleLookupOutputCallback *MLO);
410+
411+
/**
412+
* Dispose of a \c CXDependencyScannerWorkerScanSettings object.
413+
*/
414+
CINDEX_LINKAGE void
415+
clang_experimental_DependencyScannerWorkerScanSettings_dispose(
416+
CXDependencyScannerWorkerScanSettings);
417+
418+
/**
419+
* Produces the dependency graph for a particular compiler invocation.
420+
*
421+
* \param Settings object created via
422+
* \c clang_experimental_DependencyScannerWorkerScanSettings_create.
423+
* \param [out] Out A non-NULL pointer to store the resulting dependencies. The
424+
* output must be freed by calling
425+
* \c clang_experimental_DepGraph_dispose.
426+
*
427+
* \returns \c CXError_Success on success; otherwise a non-zero \c CXErrorCode
428+
* indicating the kind of error. When returning \c CXError_Failure there will
429+
* be a \c CXDepGraph object on \p Out that can be used to get diagnostics via
430+
* \c clang_experimental_DepGraph_getDiagnostics.
431+
*/
432+
CINDEX_LINKAGE enum CXErrorCode
433+
clang_experimental_DependencyScannerWorker_getDepGraph(
434+
CXDependencyScannerWorker, CXDependencyScannerWorkerScanSettings Settings,
435+
CXDepGraph *Out);
436+
437+
/**
438+
* Dispose of a \c CXDepGraph object.
439+
*/
440+
CINDEX_LINKAGE void clang_experimental_DepGraph_dispose(CXDepGraph);
441+
442+
/**
443+
* \returns the number of \c CXDepGraphModule objects in the graph.
444+
*/
445+
CINDEX_LINKAGE size_t clang_experimental_DepGraph_getNumModules(CXDepGraph);
446+
447+
/**
448+
* \returns the \c CXDepGraphModule object at the given \p Index.
449+
*
450+
* The \c CXDepGraphModule object is only valid to use while \c CXDepGraph is
451+
* valid. Must be disposed with \c clang_experimental_DepGraphModule_dispose.
452+
*/
453+
CINDEX_LINKAGE CXDepGraphModule
454+
clang_experimental_DepGraph_getModule(CXDepGraph, size_t Index);
455+
456+
CINDEX_LINKAGE void clang_experimental_DepGraphModule_dispose(CXDepGraphModule);
457+
458+
/**
459+
* \returns the name of the module. This may include `:` for C++20 module
460+
* partitions, or a header-name for C++20 header units.
461+
*
462+
* The string is only valid to use while the \c CXDepGraphModule object is
463+
* valid.
464+
*/
465+
CINDEX_LINKAGE
466+
const char *clang_experimental_DepGraphModule_getName(CXDepGraphModule);
467+
468+
/**
469+
* \returns the context hash of a module represents the set of compiler options
470+
* that may make one version of a module incompatible from another. This
471+
* includes things like language mode, predefined macros, header search paths,
472+
* etc...
473+
*
474+
* Modules with the same name but a different \c ContextHash should be treated
475+
* as separate modules for the purpose of a build.
476+
*
477+
* The string is only valid to use while the \c CXDepGraphModule object is
478+
* valid.
479+
*/
480+
CINDEX_LINKAGE
481+
const char *clang_experimental_DepGraphModule_getContextHash(CXDepGraphModule);
482+
483+
/**
484+
* \returns the path to the modulemap file which defines this module. If there's
485+
* no modulemap (e.g. for a C++ module) returns \c NULL.
486+
*
487+
* This can be used to explicitly build this module. This file will
488+
* additionally appear in \c FileDeps as a dependency.
489+
*
490+
* The string is only valid to use while the \c CXDepGraphModule object is
491+
* valid.
492+
*/
493+
CINDEX_LINKAGE const char *
494+
clang_experimental_DepGraphModule_getModuleMapPath(CXDepGraphModule);
495+
496+
/**
497+
* \returns the list of files which this module directly depends on.
498+
*
499+
* If any of these change then the module needs to be rebuilt.
500+
*
501+
* The strings are only valid to use while the \c CXDepGraphModule object is
502+
* valid.
503+
*/
504+
CINDEX_LINKAGE CXCStringArray
505+
clang_experimental_DepGraphModule_getFileDeps(CXDepGraphModule);
506+
507+
/**
508+
* \returns the list of modules which this module direct depends on.
509+
*
510+
* This does include the context hash. The format is
511+
* `<module-name>:<context-hash>`
512+
*
513+
* The strings are only valid to use while the \c CXDepGraphModule object is
514+
* valid.
515+
*/
516+
CINDEX_LINKAGE CXCStringArray
517+
clang_experimental_DepGraphModule_getModuleDeps(CXDepGraphModule);
518+
519+
/**
520+
* \returns the canonical command line to build this module.
521+
*
522+
* The strings are only valid to use while the \c CXDepGraphModule object is
523+
* valid.
524+
*/
525+
CINDEX_LINKAGE CXCStringArray
526+
clang_experimental_DepGraphModule_getBuildArguments(CXDepGraphModule);
527+
528+
/**
529+
* \returns the \c ActionCache key for this module, if any.
530+
*/
531+
CINDEX_LINKAGE
532+
const char *clang_experimental_DepGraphModule_getCacheKey(CXDepGraphModule);
533+
534+
/**
535+
* \returns the number \c CXDepGraphTUCommand objects in the graph.
536+
*/
537+
CINDEX_LINKAGE size_t clang_experimental_DepGraph_getNumTUCommands(CXDepGraph);
538+
539+
/**
540+
* \returns the \c CXDepGraphTUCommand object at the given \p Index.
541+
*
542+
* The \c CXDepGraphTUCommand object is only valid to use while \c CXDepGraph is
543+
* valid. Must be disposed with \c clang_experimental_DepGraphTUCommand_dispose.
544+
*/
545+
CINDEX_LINKAGE CXDepGraphTUCommand
546+
clang_experimental_DepGraph_getTUCommand(CXDepGraph, size_t Index);
547+
548+
/**
549+
* Dispose of a \c CXDepGraphTUCommand object.
550+
*/
551+
CINDEX_LINKAGE void
552+
clang_experimental_DepGraphTUCommand_dispose(CXDepGraphTUCommand);
553+
554+
/**
555+
* \returns the executable name for the command.
556+
*
557+
* The string is only valid to use while the \c CXDepGraphTUCommand object is
558+
* valid.
559+
*/
560+
CINDEX_LINKAGE const char *
561+
clang_experimental_DepGraphTUCommand_getExecutable(CXDepGraphTUCommand);
562+
563+
/**
564+
* \returns the canonical command line to build this translation unit.
565+
*
566+
* The strings are only valid to use while the \c CXDepGraphTUCommand object is
567+
* valid.
568+
*/
569+
CINDEX_LINKAGE CXCStringArray
570+
clang_experimental_DepGraphTUCommand_getBuildArguments(CXDepGraphTUCommand);
571+
572+
/**
573+
* \returns the \c ActionCache key for this translation unit, if any.
574+
*/
575+
CINDEX_LINKAGE const char *
576+
clang_experimental_DepGraphTUCommand_getCacheKey(CXDepGraphTUCommand);
577+
578+
/**
579+
* \returns the list of files which this translation unit directly depends on.
580+
*
581+
* The strings are only valid to use while the \c CXDepGraph object is valid.
582+
*/
583+
CINDEX_LINKAGE
584+
CXCStringArray clang_experimental_DepGraph_getTUFileDeps(CXDepGraph);
585+
586+
/**
587+
* \returns the list of modules which this translation unit direct depends on.
588+
*
589+
* This does include the context hash. The format is
590+
* `<module-name>:<context-hash>`
591+
*
592+
* The strings are only valid to use while the \c CXDepGraph object is valid.
593+
*/
594+
CINDEX_LINKAGE
595+
CXCStringArray clang_experimental_DepGraph_getTUModuleDeps(CXDepGraph);
596+
597+
/**
598+
* \returns the context hash of the C++20 module this translation unit exports.
599+
*
600+
* If the translation unit is not a module then this is empty.
601+
*
602+
* The string is only valid to use while the \c CXDepGraph object is valid.
603+
*/
604+
CINDEX_LINKAGE
605+
const char *clang_experimental_DepGraph_getTUContextHash(CXDepGraph);
606+
607+
/**
608+
* \returns The diagnostics emitted during scanning. These must be always freed
609+
* by calling \c clang_disposeDiagnosticSet.
610+
*/
611+
CINDEX_LINKAGE
612+
CXDiagnosticSet clang_experimental_DepGraph_getDiagnostics(CXDepGraph);
367613

368614
/**
369615
* @}

clang/include/clang/AST/ASTContext.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
477477
/// For module code-gen cases, this is the top-level module we are building.
478478
Module *TopLevelModule = nullptr;
479479

480+
/// The include tree that is being built, if any.
481+
/// See \c FrontendOptions::CASIncludeTreeID.
482+
std::optional<std::string> CASIncludeTreeID;
483+
484+
/// The cas-fs tree that is being built, if any.
485+
/// See \c FileSystemOptions::CASFileSystemRootID.
486+
std::optional<std::string> CASFileSystemRootID;
487+
480488
static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
481489
static constexpr unsigned GeneralTypesLog2InitSize = 9;
482490
static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
@@ -1086,6 +1094,20 @@ class ASTContext : public RefCountedBase<ASTContext> {
10861094
/// Get module under construction, nullptr if this is not a C++20 module.
10871095
Module *getModuleForCodeGen() const { return TopLevelModule; }
10881096

1097+
std::optional<std::string> getCASIncludeTreeID() const {
1098+
return CASIncludeTreeID;
1099+
}
1100+
void setCASIncludeTreeID(std::string ID) {
1101+
CASIncludeTreeID = std::move(ID);
1102+
}
1103+
1104+
std::optional<std::string> getCASFileSystemRootID() const {
1105+
return CASFileSystemRootID;
1106+
}
1107+
void setCASFileSystemRootID(std::string ID) {
1108+
CASFileSystemRootID = std::move(ID);
1109+
}
1110+
10891111
TranslationUnitDecl *getTranslationUnitDecl() const {
10901112
return TUDecl->getMostRecentDecl();
10911113
}

clang/include/clang/Basic/DiagnosticCASKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def err_cas_missing_root_id : Error<
3636
"CAS missing expected root-id '%0'">, DefaultFatal;
3737
def err_cas_cannot_parse_root_id_for_module : Error<
3838
"CAS cannot parse root-id '%0' for module '%1'">, DefaultFatal;
39+
def err_cas_cannot_parse_include_tree_id : Error<
40+
"CAS cannot parse include-tree-id '%0'">, DefaultFatal;
41+
def err_cas_missing_include_tree_id : Error<
42+
"CAS missing expected include-tree '%0'">, DefaultFatal;
3943

4044
def warn_clang_cache_disabled_caching: Warning<
4145
"caching disabled because %0">,

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def err_missing_module_name : Error<
229229
DefaultFatal;
230230
def err_missing_module : Error<
231231
"no module named '%0' declared in module map file '%1'">, DefaultFatal;
232+
def err_missing_module_include_tree : Error<
233+
"no module named '%0' declared in include-tree module map '%1'">, DefaultFatal;
232234
def err_no_submodule : Error<"no submodule named %0 in module '%1'">;
233235
def err_no_submodule_suggest : Error<
234236
"no submodule named %0 in module '%1'; did you mean '%2'?">;

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ def warn_defined_in_function_type_macro : Extension<
918918
"macro expansion producing 'defined' has undefined behavior">,
919919
InGroup<ExpansionToDefined>;
920920

921+
def err_pp_missing_module_include_tree : Error<
922+
"no module named '%0' declared in include-tree module map">, DefaultFatal;
923+
921924
let CategoryName = "Nullability Issue" in {
922925

923926
def err_pp_assume_nonnull_syntax : Error<"expected 'begin' or 'end'">;

0 commit comments

Comments
 (0)