[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
naveen-seth wrote: This should be ready for review again. The latest version of this code should now also support multi-arch/offloading compilations. For now, I’ve removed the offloading test case because I’m not able to reliably restrict it to environments where we actually generate offloading jobs. (I also can’t provide a multi-arch test at the moment since I don’t have access to a macOS toolchain) https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
@@ -99,5 +100,6 @@ add_clang_library(clangDriver LINK_LIBS clangBasic clangLex + clangDependencyScanning naveen-seth wrote: Addressed in mainly #165277, #163659 (removing the dependency on clangDriver from clangFrontend) and #169962, #171238, #172347 (removing the dependency on clangDriver from clangDependencyScanning). https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth edited https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth updated https://github.com/llvm/llvm-project/pull/152770 >From 6abfac97edb75f99878d6776ab9a0ba1fb421a41 Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig Date: Sun, 1 Feb 2026 15:07:33 +0100 Subject: [PATCH] [clang][modules-driver] Add dependency scan and dependency graph This patch is part of a series to support driver-managed module builds. It adds support for discovery of module dependencies from within the driver and for generation of the module dependency graph. Source inputs provided on the command line can import modules defined in the standard module manifest, which are then scanned on demand. The dependency scan and graph support both Clang modules and C++ named modules, and work correctly with multi-architecture and offloading command lines. The generated dependency graph can be output in Graphviz DOT format as a remark. --- .../clang/Basic/DiagnosticDriverKinds.td | 25 + clang/include/clang/Basic/DiagnosticGroups.td |1 + clang/include/clang/Driver/Driver.h | 18 +- clang/include/clang/Driver/Job.h |3 + clang/include/clang/Driver/ModulesDriver.h| 84 + clang/include/clang/Driver/Types.h|7 + clang/include/clang/Options/Options.td| 11 + clang/lib/Driver/CMakeLists.txt |2 + clang/lib/Driver/Driver.cpp | 73 +- clang/lib/Driver/ModulesDriver.cpp| 1529 + .../modules-driver-dep-graph-offloading.cpp | 137 ++ ...es-driver-dep-graph-with-system-inputs.cpp | 103 ++ .../test/Driver/modules-driver-dep-graph.cpp | 91 + .../modules-driver-dep-scan-diagnostics.cpp | 25 + .../modules-driver-duplicate-named-module.cpp | 19 + ...dules-driver-malformed-module-manifest.cpp | 41 + llvm/include/llvm/ADT/DirectedGraph.h |1 + 17 files changed, 2151 insertions(+), 19 deletions(-) create mode 100644 clang/include/clang/Driver/ModulesDriver.h create mode 100644 clang/lib/Driver/ModulesDriver.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph-offloading.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph-with-system-inputs.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph.cpp create mode 100644 clang/test/Driver/modules-driver-dep-scan-diagnostics.cpp create mode 100644 clang/test/Driver/modules-driver-duplicate-named-module.cpp create mode 100644 clang/test/Driver/modules-driver-malformed-module-manifest.cpp diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 6798801c51142..2497ed1932d82 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -608,6 +608,31 @@ def err_drv_reduced_module_output_overrided : Warning< "please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">, InGroup>; +def remark_performing_driver_managed_module_build : Remark< + "performing driver managed module build">, InGroup; +def remark_modules_manifest_not_found : Remark< + "standard modules manifest file not found; import of standard library " + "modules not supported">, + InGroup; +def remark_using_modules_manifest : Remark< + "using standard modules manifest file '%0'">, + InGroup; +def err_modules_manifest_failed_parse : Error< + "failure while parsing standard modules manifest: '%0'">; +def err_default_modules_cache_not_available : Error< + "unable to determine the default -fmodules-cache-path. Please specify it " + "explicitly using -fmodules-cache-path or the CLANG_MODULE_CACHE_PATH " + "environment variable">; +def err_dependency_scan_failed : Error< + "failed to perform dependency scan">; +def err_modules_driver_named_module_redefinition : Error< + "duplicate definitions of C++20 named module '%0' in '%1' and '%2'">; +def err_building_dependency_graph : Error< + "failed to construct the module dependency graph">; +def remark_printing_module_graph : Remark< + "printing module dependency graph">, + InGroup; + def warn_drv_delayed_template_parsing_after_cxx20 : Warning< "-fdelayed-template-parsing is deprecated after C++20">, InGroup>; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index d36ee57fe7651..4ac155358253e 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -665,6 +665,7 @@ def ModuleConflict : DiagGroup<"module-conflict">; def ModuleFileExtension : DiagGroup<"module-file-extension">; def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">; def ModuleMap : DiagGroup<"module-map">; +def ModulesDriver : DiagGroup<"modules-driver">; def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">; def NewlineEOF : DiagGroup<"newline-eof">; def Nullability : DiagGroup<"nullability">; diff --git a/clang/include/clang/Driver/
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
github-actions[bot] wrote:
# :penguin: Linux x64 Test Results
* 169067 tests passed
* 3024 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang
Clang.Driver/modules-driver-dep-graph-offloading.cpp
```
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 8
split-file
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/modules-driver-dep-graph-offloading.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
# executed command: split-file
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/modules-driver-dep-graph-offloading.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
# note: command had no output on stdout or stderr
# RUN: at line 10
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
-std=c++23 -nostdlib -fmodules-fmodules-driver -Rmodules-driver
-fmodule-map-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/module.modulemap
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/main.cpp
-fmodules-cache-path=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/modules-cache
-fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A-B.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A-C.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/B.cpp
-### 2>&1| sed 's:\?:/:g'|
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck
-DPREFIX=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/modules-driver-dep-graph-offloading.cpp
# executed command:
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
-std=c++23 -nostdlib -fmodules -fmodules-driver -Rmodules-driver
-fmodule-map-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/module.modulemap
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/main.cpp
-fmodules-cache-path=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/modules-cache
-fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A-B.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/A-C.cpp
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/B.cpp
'-###'
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: sed 's:\?:/:g'
# note: command had no output on stdout or stderr
# executed command:
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck
-DPREFIX=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/modules-driver-dep-graph-offloading.cpp
# .---command stderr
# |
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Driver/modules-driver-dep-graph-offloading.cpp:24:16:
error: CHECK-NEXT: expected string not found in input
# | // CHECK-NEXT: "[[PREFIX]]/main.cpp-[[OFFLOADING_ARCH:.*]]" [ fillcolor=3,
label="{ Filename: [[PREFIX]]/main.cpp | Triple: [[OFFLOADING_ARCH]] }"];
# |^
# | :19:396: note: scanning from here
# |
"/home/gha/actions-runner/_work/llvm-project/llvm-project/build/to
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
github-actions[bot] wrote:
# :window: Windows x64 Test Results
* 130360 tests passed
* 2897 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang
Clang.Driver/modules-driver-dep-graph-offloading.cpp
```
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 8
split-file
C:\_work\llvm-project\llvm-project\clang\test\Driver\modules-driver-dep-graph-offloading.cpp
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp
# executed command: split-file
'C:\_work\llvm-project\llvm-project\clang\test\Driver\modules-driver-dep-graph-offloading.cpp'
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp'
# note: command had no output on stdout or stderr
# RUN: at line 10
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -std=c++23 -nostdlib
-fmodules-fmodules-driver -Rmodules-driver
-fmodule-map-file=C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/module.modulemap
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/main.cpp
-fmodules-cache-path=C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/modules-cache
-fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A.cpp
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A-B.cpp
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A-C.cpp
C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/B.cpp
-### 2>&1| sed 's:\?:/:g'|
c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe
-DPREFIX=C:/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
C:\_work\llvm-project\llvm-project\clang\test\Driver\modules-driver-dep-graph-offloading.cpp
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe'
-std=c++23 -nostdlib -fmodules -fmodules-driver -Rmodules-driver
'-fmodule-map-file=C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/module.modulemap'
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/main.cpp'
'-fmodules-cache-path=C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/modules-cache'
-fopenmp=libomp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib -nogpuinc
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A.cpp'
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A-B.cpp'
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/A-C.cpp'
'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Driver\Output\modules-driver-dep-graph-offloading.cpp.tmp/B.cpp'
'-###'
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: sed 's:\?:/:g'
# note: command had no output on stdout or stderr
# executed command:
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe'
-DPREFIX=C:/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp
'C:\_work\llvm-project\llvm-project\clang\test\Driver\modules-driver-dep-graph-offloading.cpp'
# .---command stderr
# |
C:\_work\llvm-project\llvm-project\clang\test\Driver\modules-driver-dep-graph-offloading.cpp:24:16:
error: CHECK-NEXT: expected string not found in input
# | // CHECK-NEXT: "[[PREFIX]]/main.cpp-[[OFFLOADING_ARCH:.*]]" [ fillcolor=3,
label="{ Filename: [[PREFIX]]/main.cpp | Triple: [[OFFLOADING_ARCH]] }"];
# |^
# | :19:348: note: scanning from here
# |
"C:/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/main.cpp-x86_64-pc-windows-msvc"
[ fillcolor=3, label="{ Filename:
C:/_work/llvm-project/llvm-project/build/tools/clang/test/Driver/Output/modules-driver-dep-graph-offloading.cpp.tmp/main.cpp
| Triple: x86_64-pc-windows-msvc }"];
# |
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
@@ -0,0 +1,112 @@
+//===- ModulesDriver.h - Driver managed module builds *- 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
+//
+//===--===//
+///
+/// \file
+/// This file defines functionality to support driver managed builds for
+/// compilations which use Clang modules or standard C++20 named modules.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_DRIVER_MODULESDRIVER_H
+#define LLVM_CLANG_DRIVER_MODULESDRIVER_H
+
+#include "clang/Driver/Types.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace vfs {
+class FileSystem;
+} // namespace vfs
+namespace opt {
+class Arg;
+} // namespace opt
+} // namespace llvm
+
+namespace clang {
+class DiagnosticsEngine;
+namespace driver {
+class Compilation;
+} // namespace driver
+} // namespace clang
+
+namespace clang::driver::modules {
+
+/// A list of inputs and their types for the given arguments.
+/// Identical to Driver::InputTy.
+using InputTy = std::pair;
+
+/// A list of inputs and their types for the given arguments.
+/// Identical to Driver::InputList.
+using InputList = llvm::SmallVector;
+
+/// Checks whether the -fmodules-driver feature should be implicitly enabled.
naveen-seth wrote:
Addressed. (Revert in #172701)
https://github.com/llvm/llvm-project/pull/152770
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth edited https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth edited https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth edited https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth updated https://github.com/llvm/llvm-project/pull/152770 >From cce501c2632794b2cfbfd4841f37701f234f104a Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig Date: Sun, 1 Feb 2026 15:07:33 +0100 Subject: [PATCH] [clang][modules-driver] Add dependency scan and dependency graph This patch is part of a series to support driver-managed module builds. It adds support for discovery of module dependencies from within the driver and for generation of the module dependency graph. Source inputs provided on the command line can import modules defined in the standard module manifest, which are then scanned on demand. The dependency scan and graph support both Clang modules and C++ named modules, and work correctly with multi-architecture and offloading command lines. The generated dependency graph can be output in Graphviz DOT format as a remark. --- .../clang/Basic/DiagnosticDriverKinds.td | 25 + clang/include/clang/Basic/DiagnosticGroups.td |1 + clang/include/clang/Driver/Driver.h | 18 +- clang/include/clang/Driver/Job.h |3 + clang/include/clang/Driver/ModulesDriver.h| 84 + clang/include/clang/Driver/Types.h|7 + clang/include/clang/Options/Options.td| 11 + clang/lib/Driver/CMakeLists.txt |2 + clang/lib/Driver/Driver.cpp | 73 +- clang/lib/Driver/ModulesDriver.cpp| 1529 + .../modules-driver-dep-graph-offloading.cpp | 133 ++ ...es-driver-dep-graph-with-system-inputs.cpp | 103 ++ .../test/Driver/modules-driver-dep-graph.cpp | 91 + .../modules-driver-dep-scan-diagnostics.cpp | 25 + .../modules-driver-duplicate-named-module.cpp | 19 + ...dules-driver-malformed-module-manifest.cpp | 41 + llvm/include/llvm/ADT/DirectedGraph.h |1 + 17 files changed, 2147 insertions(+), 19 deletions(-) create mode 100644 clang/include/clang/Driver/ModulesDriver.h create mode 100644 clang/lib/Driver/ModulesDriver.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph-offloading.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph-with-system-inputs.cpp create mode 100644 clang/test/Driver/modules-driver-dep-graph.cpp create mode 100644 clang/test/Driver/modules-driver-dep-scan-diagnostics.cpp create mode 100644 clang/test/Driver/modules-driver-duplicate-named-module.cpp create mode 100644 clang/test/Driver/modules-driver-malformed-module-manifest.cpp diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 6798801c51142..2497ed1932d82 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -608,6 +608,31 @@ def err_drv_reduced_module_output_overrided : Warning< "please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">, InGroup>; +def remark_performing_driver_managed_module_build : Remark< + "performing driver managed module build">, InGroup; +def remark_modules_manifest_not_found : Remark< + "standard modules manifest file not found; import of standard library " + "modules not supported">, + InGroup; +def remark_using_modules_manifest : Remark< + "using standard modules manifest file '%0'">, + InGroup; +def err_modules_manifest_failed_parse : Error< + "failure while parsing standard modules manifest: '%0'">; +def err_default_modules_cache_not_available : Error< + "unable to determine the default -fmodules-cache-path. Please specify it " + "explicitly using -fmodules-cache-path or the CLANG_MODULE_CACHE_PATH " + "environment variable">; +def err_dependency_scan_failed : Error< + "failed to perform dependency scan">; +def err_modules_driver_named_module_redefinition : Error< + "duplicate definitions of C++20 named module '%0' in '%1' and '%2'">; +def err_building_dependency_graph : Error< + "failed to construct the module dependency graph">; +def remark_printing_module_graph : Remark< + "printing module dependency graph">, + InGroup; + def warn_drv_delayed_template_parsing_after_cxx20 : Warning< "-fdelayed-template-parsing is deprecated after C++20">, InGroup>; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index d36ee57fe7651..4ac155358253e 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -665,6 +665,7 @@ def ModuleConflict : DiagGroup<"module-conflict">; def ModuleFileExtension : DiagGroup<"module-file-extension">; def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">; def ModuleMap : DiagGroup<"module-map">; +def ModulesDriver : DiagGroup<"modules-driver">; def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">; def NewlineEOF : DiagGroup<"newline-eof">; def Nullability : DiagGroup<"nullability">; diff --git a/clang/include/clang/Driver/
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth created https://github.com/llvm/llvm-project/pull/152770 This patch is part of a series to support driver-managed module builds. It adds support for the discovery of module dependencies and for dependency graph generation from within the driver. The dependency scan and graph support both Clang modules and C++ named modules. The generated dependency graph can be output in the Graphviz format as a remark. This patch follows the discussion in the RFC linked below and links the driver against the following libraries: ``` clangDependencyScanning clangAST clangFrontend clangSerialization clangLex ``` RFC discussing linking the driver against additional libraries: https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex RFC for driver-managed module builds: https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system >From 89de9916577a76868aa74bad03a8de9fd6339623 Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig Date: Mon, 21 Jul 2025 22:34:14 +0200 Subject: [PATCH 1/4] Reland Reland [clang][modules-driver] Add scanner to detect C++20 module presence (#147630) This patch is part of a series to natively support C++20 module usage from the Clang driver (without requiring an external build system). This introduces a new scanner that detects C++20 module usage in source files without using the preprocessor or lexer. For now, it is enabled only with the `-fmodules-driver` flag and serves solely diagnostic purposes. In the future, the scanner will be enabled for any (modules-driver compatible) compilation with two or more inputs, and will help the driver determine whether to implicitly enable the modules driver. Since the scanner adds very little overhead, we are also exploring enabling it for compilations with only a single input. This approach could allow us to detect `import std` usage in a single-file compilation, which would then activate the modules driver. For performance measurements on this, see https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark. RFC: https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system This patch relands the reland (2d31fc8) for commit ded1426. The previous reland failed because the link dependency on clangLex was missing. Following the RFC linked below, the issue has now been addressed by properly linking against clangLex. https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex --- .../clang/Basic/DiagnosticDriverKinds.td | 7 + clang/include/clang/Basic/DiagnosticGroups.td | 1 + clang/include/clang/Driver/Driver.h | 32 +++ clang/include/clang/Driver/Options.td | 7 + .../clang/Lex/DependencyDirectivesScanner.h | 7 + clang/lib/Driver/CMakeLists.txt | 1 + clang/lib/Driver/Driver.cpp | 69 +++ clang/lib/Lex/DependencyDirectivesScanner.cpp | 50 + ...ules-driver-cxx20-module-usage-scanner.cpp | 192 ++ 9 files changed, 366 insertions(+) create mode 100644 clang/test/Driver/modules-driver-cxx20-module-usage-scanner.cpp diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 0f17f4aa761ea..6df8f9932f30f 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -581,6 +581,13 @@ def err_drv_reduced_module_output_overrided : Warning< "please consider use '-fmodule-output=' to specify the output file for reduced BMI explicitly">, InGroup>; +def remark_found_cxx20_module_usage : Remark< + "found C++20 module usage in file '%0'">, + InGroup; +def remark_performing_driver_managed_module_build : Remark< + "performing driver managed module build">, + InGroup; + def warn_drv_delayed_template_parsing_after_cxx20 : Warning< "-fdelayed-template-parsing is deprecated after C++20">, InGroup>; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index ccb18aa37447e..78726ecc869db 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -628,6 +628,7 @@ def ModuleConflict : DiagGroup<"module-conflict">; def ModuleFileExtension : DiagGroup<"module-file-extension">; def ModuleIncludeDirectiveTranslation : DiagGroup<"module-include-translation">; def ModuleMap : DiagGroup<"module-map">; +def ModulesDriver : DiagGroup<"modules-driver">; def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">; def NewlineEOF : DiagGroup<"newline-eof">; def Nullability : DiagGroup<"nullability">; diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 4d32552b7f85f..b9b187a
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth edited https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
llvmbot wrote:
@llvm/pr-subscribers-llvm-support
@llvm/pr-subscribers-clang-driver
Author: Naveen Seth Hanig (naveen-seth)
Changes
This patch is part of a series to support driver-managed module builds.
It adds support for the discovery of module dependencies and for dependency
graph generation from within the driver.
The dependency scan and graph support both Clang modules and C++ named modules.
The generated dependency graph can be output in the Graphviz format as a remark.
This patch follows the discussion in the RFC linked below and links
the driver against the following libraries:
```
clangDependencyScanning
clangAST
clangFrontend
clangSerialization
clangLex
```
RFC discussing linking the driver against additional libraries:
https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex
RFC for driver-managed module builds:
https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system
---
Patch is 66.40 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/152770.diff
13 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+12)
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1)
- (added) clang/include/clang/Driver/DependencyScanner.h (+388)
- (modified) clang/include/clang/Driver/Driver.h (+32)
- (modified) clang/include/clang/Driver/Options.td (+7)
- (modified) clang/include/clang/Lex/DependencyDirectivesScanner.h (+7)
- (modified) clang/lib/Driver/CMakeLists.txt (+3)
- (added) clang/lib/Driver/DependencyScanner.cpp (+696)
- (modified) clang/lib/Driver/Driver.cpp (+84)
- (modified) clang/lib/Lex/DependencyDirectivesScanner.cpp (+50)
- (added) clang/test/Driver/modules-driver-cxx20-module-usage-scanner.cpp
(+192)
- (added) clang/test/Driver/modules-driver-dependency-graph.cpp (+88)
- (modified) llvm/include/llvm/Support/GraphWriter.h (+2)
``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 0f17f4aa761ea..68532ba58a03b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -581,6 +581,18 @@ def err_drv_reduced_module_output_overrided : Warning<
"please consider use '-fmodule-output=' to specify the output file for
reduced BMI explicitly">,
InGroup>;
+def remark_found_cxx20_module_usage : Remark<
+ "found C++20 module usage in file '%0'">,
+ InGroup;
+def remark_performing_driver_managed_module_build : Remark<
+ "performing driver managed module build">,
+ InGroup;
+def err_failed_dependency_scan : Error <
+ "failed to perform dependency scan">;
+def remark_module_dependency_graph : Remark<
+ "printing module dependency graph">,
+ InGroup;
+
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
"-fdelayed-template-parsing is deprecated after C++20">,
InGroup>;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td
b/clang/include/clang/Basic/DiagnosticGroups.td
index ccb18aa37447e..78726ecc869db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -628,6 +628,7 @@ def ModuleConflict : DiagGroup<"module-conflict">;
def ModuleFileExtension : DiagGroup<"module-file-extension">;
def ModuleIncludeDirectiveTranslation :
DiagGroup<"module-include-translation">;
def ModuleMap : DiagGroup<"module-map">;
+def ModulesDriver : DiagGroup<"modules-driver">;
def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
def NewlineEOF : DiagGroup<"newline-eof">;
def Nullability : DiagGroup<"nullability">;
diff --git a/clang/include/clang/Driver/DependencyScanner.h
b/clang/include/clang/Driver/DependencyScanner.h
new file mode 100644
index 0..a2d56aba462ca
--- /dev/null
+++ b/clang/include/clang/Driver/DependencyScanner.h
@@ -0,0 +1,388 @@
+#ifndef LLVM_CLANG_DRIVER_DEPENDENCYSCANNER_H
+#define LLVM_CLANG_DRIVER_DEPENDENCYSCANNER_H
+
+#include "clang/Driver/Driver.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
+#include "llvm/ADT/DirectedGraph.h"
+#include "llvm/Support/DOTGraphTraits.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/GraphWriter.h"
+
+namespace clang {
+class SourceManager;
+class CharSourceRange;
+class DiagnosticsEngine;
+} // namespace clang
+
+namespace llvm::opt {
+class DerivedArgList;
+} // namespace llvm::opt
+
+namespace clang {
+namespace driver {
+namespace dependencies {
+
+using clang::tooling::dependencies::TranslationUnitDeps;
+
+//===--===//
+// Dependency Scan
+//===--===//
+
+class DependencyScanError : public llvm::ErrorInfo {
+public:
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth updated
https://github.com/llvm/llvm-project/pull/152770
>From 89de9916577a76868aa74bad03a8de9fd6339623 Mon Sep 17 00:00:00 2001
From: Naveen Seth Hanig
Date: Mon, 21 Jul 2025 22:34:14 +0200
Subject: [PATCH 1/3] Reland Reland [clang][modules-driver] Add scanner to
detect C++20 module presence (#147630)
This patch is part of a series to natively support C++20 module usage
from the Clang driver (without requiring an external build system). This
introduces a new scanner that detects C++20 module usage in source files
without using the preprocessor or lexer.
For now, it is enabled only with the `-fmodules-driver` flag and serves
solely diagnostic purposes. In the future, the scanner will be enabled
for any (modules-driver compatible) compilation with two or more inputs,
and will help the driver determine whether to implicitly enable the
modules driver.
Since the scanner adds very little overhead, we are also exploring
enabling it for compilations with only a single input. This approach
could allow us to detect `import std` usage in a single-file
compilation, which would then activate the modules driver. For
performance measurements on this, see
https://github.com/naveen-seth/llvm-dev-cxx-modules-check-benchmark.
RFC:
https://discourse.llvm.org/t/rfc-modules-support-simple-c-20-modules-use-from-the-clang-driver-without-a-build-system
This patch relands the reland (2d31fc8) for commit ded1426.
The previous reland failed because the link dependency on clangLex
was missing. Following the RFC linked below, the issue has now been
addressed by properly linking against clangLex.
https://discourse.llvm.org/t/rfc-driver-link-the-driver-against-clangdependencyscanning-clangast-clangfrontend-clangserialization-and-clanglex
---
.../clang/Basic/DiagnosticDriverKinds.td | 7 +
clang/include/clang/Basic/DiagnosticGroups.td | 1 +
clang/include/clang/Driver/Driver.h | 32 +++
clang/include/clang/Driver/Options.td | 7 +
.../clang/Lex/DependencyDirectivesScanner.h | 7 +
clang/lib/Driver/CMakeLists.txt | 1 +
clang/lib/Driver/Driver.cpp | 69 +++
clang/lib/Lex/DependencyDirectivesScanner.cpp | 50 +
...ules-driver-cxx20-module-usage-scanner.cpp | 192 ++
9 files changed, 366 insertions(+)
create mode 100644
clang/test/Driver/modules-driver-cxx20-module-usage-scanner.cpp
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 0f17f4aa761ea..6df8f9932f30f 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -581,6 +581,13 @@ def err_drv_reduced_module_output_overrided : Warning<
"please consider use '-fmodule-output=' to specify the output file for
reduced BMI explicitly">,
InGroup>;
+def remark_found_cxx20_module_usage : Remark<
+ "found C++20 module usage in file '%0'">,
+ InGroup;
+def remark_performing_driver_managed_module_build : Remark<
+ "performing driver managed module build">,
+ InGroup;
+
def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
"-fdelayed-template-parsing is deprecated after C++20">,
InGroup>;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td
b/clang/include/clang/Basic/DiagnosticGroups.td
index ccb18aa37447e..78726ecc869db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -628,6 +628,7 @@ def ModuleConflict : DiagGroup<"module-conflict">;
def ModuleFileExtension : DiagGroup<"module-file-extension">;
def ModuleIncludeDirectiveTranslation :
DiagGroup<"module-include-translation">;
def ModuleMap : DiagGroup<"module-map">;
+def ModulesDriver : DiagGroup<"modules-driver">;
def RoundTripCC1Args : DiagGroup<"round-trip-cc1-args">;
def NewlineEOF : DiagGroup<"newline-eof">;
def Nullability : DiagGroup<"nullability">;
diff --git a/clang/include/clang/Driver/Driver.h
b/clang/include/clang/Driver/Driver.h
index 4d32552b7f85f..b9b187ada8add 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -512,6 +512,9 @@ class Driver {
/// BuildActions - Construct the list of actions to perform for the
/// given arguments, which are only done for a single architecture.
+ /// If the compilation is an explicit module build, delegates to
+ /// BuildDriverManagedModuleBuildActions. Otherwise, BuildDefaultActions is
+ /// used.
///
/// \param C - The compilation that is being built.
/// \param Args - The input arguments.
@@ -796,6 +799,35 @@ class Driver {
/// compilation based on which -f(no-)?lto(=.*)? option occurs last.
void setLTOMode(const llvm::opt::ArgList &Args);
+ /// BuildDefaultActions - Constructs the list of actions to perform
+ /// for the provided arguments, which are only done for a single
architecture.
+ ///
+ /// \param C - The compilation that is being built
[clang] [llvm] [clang][modules-driver] Add dependency scan and dependency graph (PR #152770)
https://github.com/naveen-seth converted_to_draft https://github.com/llvm/llvm-project/pull/152770 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
