Skip to content

Commit f1d9265

Browse files
committed
Constrain to only allow on-demand imports for stdlib system modules.
1 parent 2d87451 commit f1d9265

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,11 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
18761876
});
18771877
}
18781878
}
1879+
// Only allow on-demand imports of standard library modules.
1880+
llvm::erase_if(Manifest.ModuleEntries, [](const auto &ModuleEntry) {
1881+
return !ModuleEntry.IsStdlib;
1882+
});
1883+
18791884
modules::buildStdModuleManifestInputs(Manifest, *C, Inputs);
18801885
}
18811886

clang/test/Driver/modules-driver-dep-graph-with-system-inputs.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// This test checks the on-demand scanning of system inputs, in particular:
22
// 1. Inputs for unused system modules are not scanned.
33
// 2. Imports between system modules are supported and scanned on demand.
4-
// 3. Arbitrary modules may be declared in the manifest (modules other than
5-
// std and std.compat).
64

75
// RUN: split-file %s %t
86

@@ -42,11 +40,11 @@
4240
// CHECK-NEXT: "[[PREFIX]]/foo.cpp" [ fillcolor=[[COLOR1]],label="{ Kind: Non-module | Filename: [[PREFIX]]/foo.cpp }"];
4341
// CHECK-NEXT: "std" [ fillcolor=[[COLOR2:[0-9]+]],label="{ Kind: C++ named module | Module name: std | Filename: [[PREFIX]]/Inputs/usr/lib/share/libc++/v1/std.cppm | Input origin: System | Hash: {{.*}} }"];
4442
// CHECK-NEXT: "std.compat" [ fillcolor=[[COLOR2]],label="{ Kind: C++ named module | Module name: std.compat | Filename: [[PREFIX]]/Inputs/usr/lib/share/libc++/v1/std.compat.cppm | Input origin: System | Hash: {{.*}} }"];
45-
// CHECK-NEXT: "nonstd" [ fillcolor=[[COLOR2]],label="{ Kind: C++ named module | Module name: nonstd | Filename: [[PREFIX]]/non-std.cxxm | Input origin: System | Hash: {{.*}} }"];
43+
// CHECK-NEXT: "core" [ fillcolor=[[COLOR2]],label="{ Kind: C++ named module | Module name: core | Filename: [[PREFIX]]/core.cxxm | Input origin: System | Hash: {{.*}} }"];
4644

4745
// CHECK: "[[PREFIX]]/main.cpp" -> "std";
4846
// CHECK-NEXT: "[[PREFIX]]/main.cpp" -> "std.compat";
49-
// CHECK-NEXT: "[[PREFIX]]/foo.cpp" -> "nonstd";
47+
// CHECK-NEXT: "[[PREFIX]]/foo.cpp" -> "core";
5048
// CHECK-NEXT: "std.compat" -> "std";
5149
// CHECK-NEXT: }
5250

@@ -56,7 +54,7 @@ import std;
5654
import std.compat;
5755

5856
//--- foo.cpp
59-
import nonstd;
57+
import core;
6058

6159
//--- std.cppm
6260
export module std;
@@ -65,8 +63,11 @@ export module std;
6563
export module std.compat;
6664
import std;
6765

68-
//--- non-std.cxxm
69-
export module nonstd;
66+
// The module 'core' is isn't really a system module in libc++ or libstdc++.
67+
// This is only to test that any module marked with '"is-std-library": true' can
68+
// be imported on demand.
69+
//--- core.cxxm
70+
export module core;
7071

7172
//--- unused.cppm
7273
export module unused;
@@ -87,14 +88,14 @@ export module unused;
8788
"is-std-library": true
8889
},
8990
{
90-
"logical-name": "nonstd",
91-
"source-path": "DIR/non-std.cxxm",
92-
"is-std-library": false
91+
"logical-name": "core",
92+
"source-path": "DIR/core.cxxm",
93+
"is-std-library": true
9394
},
9495
{
9596
"logical-name": "unused",
9697
"source-path": "DIR/unused.cppm",
97-
"is-std-library": false
98+
"is-std-library": true
9899
}
99100
]
100101
}

0 commit comments

Comments
 (0)