-
Notifications
You must be signed in to change notification settings - Fork 18k
[clang][ModulesDriver] Add support for Clang modules to -fmodules-driver #187606
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
naveen-seth
merged 5 commits into
llvm:main
from
naveen-seth:modules-driver-clang-modules-only
Apr 8, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c48ed20
[clang][ModulesDriver] Add support for Clang modules to -fmodules-driver
naveen-seth 71b3a2b
Merge branch 'main' into modules-driver-clang-modules-only
naveen-seth 9f1ab12
Install scan command-lines for all jobs
naveen-seth cd66e7b
Avoid copy + const correctness
naveen-seth 386a8f5
Fix/improve doc comment
naveen-seth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
clang/test/Driver/modules-driver-clang-modules-only.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| // Checks that -fmodules-driver correctly handles compilations using Clang modules. | ||
|
|
||
| // RUN: split-file %s %t | ||
| // RUN: rm -rf %t/modules-cache | ||
|
|
||
| // RUN: %clang -std=c++23 \ | ||
| // RUN: -fmodules-driver -Rmodules-driver \ | ||
| // RUN: -fmodules -Rmodule-import \ | ||
| // RUN: -fmodule-map-file=%t/module.modulemap \ | ||
| // RUN: -fmodules-cache-path=%t/modules-cache \ | ||
| // RUN: -fsyntax-only %t/main.cpp 2>&1 \ | ||
| // RUN: | sed 's:\\\\\?:/:g' \ | ||
| // RUN: | FileCheck -DPREFIX=%/t --check-prefix=CHECK-REMARKS %s | ||
|
|
||
| // RUN: rm -rf %t/modules-cache | ||
| // RUN: %clang -std=c++23 \ | ||
| // RUN: -fmodules-driver \ | ||
| // RUN: -fmodules \ | ||
| // RUN: -fmodule-map-file=%t/module.modulemap \ | ||
| // RUN: -fmodules-cache-path=%t/modules-cache \ | ||
| // RUN: -fsyntax-only %t/main.cpp \ | ||
| // RUN: -### 2>&1 \ | ||
| // RUN: | sed 's:\\\\\?:/:g' \ | ||
| // RUN: | FileCheck --check-prefix=CHECK-CC1 %s | ||
|
|
||
| // The scan itself will also produce [-Rmodule-import] remarks. | ||
| // Let's skip past them, we only care about the final -cc1 commands. | ||
| // CHECK-REMARKS: clang: remark: printing module dependency graph [-Rmodules-driver] | ||
| // CHECK-REMARKS-NEXT: digraph "Module Dependency Graph" { | ||
| // CHECK-REMARKS: } | ||
|
|
||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'root' from | ||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'direct1' into 'root' | ||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive1' into 'direct1' | ||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive2' into 'direct1' | ||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'direct2' into 'root' | ||
| // CHECK-REMARKS: [[PREFIX]]/main.cpp:1:2: remark: importing module 'transitive2' into 'direct2' | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-o" "[[TRANSITIVE2PCM:[^"]+]]" | ||
| // CHECK-CC1-SAME: "-emit-module" | ||
| // CHECK-CC1-SAME: "-fmodule-name=transitive2" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-o" "[[DIRECT2PCM:[^"]+]]" | ||
| // CHECK-CC1-SAME: "-emit-module" | ||
| // CHECK-CC1-SAME: "-fmodule-file=transitive2=[[TRANSITIVE2PCM]]" | ||
| // CHECK-CC1-SAME: "-fmodule-name=direct2" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-o" "[[TRANSITIVE1PCM:[^"]+]]" | ||
| // CHECK-CC1-SAME: "-emit-module" | ||
| // CHECK-CC1-SAME: "-fmodule-name=transitive1" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-o" "[[DIRECT1PCM:[^"]+]]" | ||
| // CHECK-CC1-SAME: "-emit-module" | ||
| // CHECK-CC1-SAME: "-fmodule-file=transitive1=[[TRANSITIVE1PCM]]" | ||
| // CHECK-CC1-SAME: "-fmodule-file=transitive2=[[TRANSITIVE2PCM]]" | ||
| // CHECK-CC1-SAME: "-fmodule-name=direct1" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-o" "[[ROOTPCM:[^"]+]]" | ||
| // CHECK-CC1-SAME: "-emit-module" | ||
| // CHECK-CC1-SAME: "-fmodule-file=direct1=[[DIRECT1PCM]]" | ||
| // CHECK-CC1-SAME: "-fmodule-file=direct2=[[DIRECT2PCM]]" | ||
| // CHECK-CC1-SAME: "-fmodule-name=root" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // CHECK-CC1: "-cc1" | ||
| // CHECK-CC1-SAME: "-fsyntax-only" | ||
| // CHECK-CC1-SAME: "{{.*}}/main.cpp" | ||
| // CHECK-CC1-SAME: "-fmodule-file=root=[[ROOTPCM]]" | ||
| // CHECK-CC1-SAME: "-fno-implicit-modules" | ||
|
|
||
| // (Because of missing include guards, this example would also run into | ||
| // redefinition errors when compiling without modules.) | ||
|
|
||
| /--- module.modulemap | ||
| module root { header "root.h"} | ||
| module transitive1 { header "transitive1.h" } | ||
| module transitive2 { header "transitive2.h" } | ||
| module direct1 { header "direct1.h" } | ||
| module direct2 { header "direct2.h" } | ||
|
|
||
| //--- root.h | ||
| #include "direct1.h" | ||
| #include "direct2.h" | ||
| int fromRoot() { | ||
| return fromDirect1() + fromDirect2(); | ||
| } | ||
|
|
||
| //--- direct1.h | ||
| #include "transitive1.h" | ||
| #include "transitive2.h" | ||
|
|
||
| int fromDirect1() { | ||
| return fromTransitive1() + fromTransitive2(); | ||
| } | ||
|
|
||
| //--- direct2.h | ||
| #include "transitive2.h" | ||
|
|
||
| int fromDirect2() { | ||
| return fromTransitive2() + 2; | ||
| } | ||
|
|
||
| //--- transitive1.h | ||
| int fromTransitive1() { | ||
| return 20; | ||
| } | ||
|
|
||
| //--- transitive2.h | ||
| int fromTransitive2() { | ||
| return 10; | ||
| } | ||
|
|
||
| //--- main.cpp | ||
| #include "root.h" | ||
|
|
||
| int main() { | ||
| fromRoot(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.