Skip to content

Commit 503cef7

Browse files
authored
Merge pull request #4790 from DavidGoldman/stable2022indexignorepcms
Add `-index-ignore-pcms` to prevent indexing PCMs for imports/deps
2 parents 83ea1bd + 0654642 commit 503cef7

File tree

5 files changed

+68
-50
lines changed

5 files changed

+68
-50
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ def index_unit_output_path : Separate<["-"], "index-unit-output-path">, MetaVarN
646646
def index_ignore_macros : Flag<["-"], "index-ignore-macros">, Flags<[CC1Option]>,
647647
HelpText<"Ignore macros during indexing">,
648648
MarshallingInfoFlag<FrontendOpts<"IndexIgnoreMacros">>;
649+
def index_ignore_pcms : Flag<["-"], "index-ignore-pcms">, Flags<[CC1Option]>,
650+
HelpText<"Ignore symbols from imported pcm modules">,
651+
MarshallingInfoFlag<FrontendOpts<"IndexIgnorePcms">>;
649652

650653
// Make sure all other -ccc- options are rejected.
651654
def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>;

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class FrontendOptions {
347347
unsigned IndexIgnoreSystemSymbols : 1;
348348
unsigned IndexRecordCodegenName : 1;
349349
unsigned IndexIgnoreMacros : 1;
350+
unsigned IndexIgnorePcms : 1;
350351

351352
/// Output (and read) PCM files regardless of compiler errors.
352353
unsigned AllowPCMWithCompilerErrors : 1;

clang/include/clang/Index/IndexingOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct IndexingOptions {
3333
// callback is not available (e.g. after parsing has finished). Note that
3434
// macro references are not available in Preprocessor.
3535
bool IndexMacrosInPreprocessor = false;
36+
bool IndexPcms = true;
3637
// Has no effect if IndexFunctionLocals are false.
3738
bool IndexParametersInDeclarations = false;
3839
bool IndexTemplateParameters = false;

clang/lib/Index/IndexingAction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,15 @@ static void writeUnitData(const CompilerInstance &CI,
850850
[&](const FileEntry *Source, unsigned Line, const FileEntry *Target) {
851851
UnitWriter.addInclude(Source, Line, Target);
852852
});
853+
bool IndexPcms = IndexOpts.IndexPcms;
854+
bool WithoutUnitName = !IndexPcms;
853855
DepProvider.visitModuleImports(CI, [&](serialization::ModuleFile &Mod,
854856
bool isSystemMod) {
855857
Module *UnitMod = HS.lookupModule(Mod.ModuleName, Mod.ImportLoc,
856858
/*AllowSearch=*/false);
857-
UnitWriter.addASTFileDependency(Mod.File, isSystemMod, UnitMod);
858-
if (Mod.isModule()) {
859+
UnitWriter.addASTFileDependency(Mod.File, isSystemMod, UnitMod,
860+
WithoutUnitName);
861+
if (Mod.isModule() && IndexPcms) {
859862
produceIndexDataForModuleFile(Mod, CI, IndexOpts, RecordOpts, UnitWriter);
860863
}
861864
});
@@ -1027,6 +1030,7 @@ getIndexOptionsFromFrontendOptions(const FrontendOptions &FEOpts) {
10271030
}
10281031
IndexOpts.IndexMacros = !FEOpts.IndexIgnoreMacros;
10291032
IndexOpts.IndexMacrosInPreprocessor = !FEOpts.IndexIgnoreMacros;
1033+
IndexOpts.IndexPcms = !FEOpts.IndexIgnorePcms;
10301034
RecordOpts.RecordSymbolCodeGenName = FEOpts.IndexRecordCodegenName;
10311035
return {IndexOpts, RecordOpts};
10321036
}
Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,66 @@
11
// RUN: rm -rf %t.idx %t.mcp
22
// RUN: %clang -arch x86_64 -mmacosx-version-min=10.7 -c %s -o %t.o -index-store-path %t.idx -fmodules -fmodules-cache-path=%t.mcp -Xclang -fdisable-module-hash -I %S/Inputs/module
3-
// RUN: c-index-test core -print-unit %t.idx | FileCheck %s
3+
// RUN: c-index-test core -print-unit %t.idx | FileCheck %s --check-prefixes=ALL,MODULES
4+
5+
// RUN: rm -rf %t.idx %t.mcp
6+
// RUN: %clang -arch x86_64 -mmacosx-version-min=10.7 -c %s -o %t.o -index-store-path %t.idx -index-ignore-pcms -fmodules -fmodules-cache-path=%t.mcp -Xclang -fdisable-module-hash -I %S/Inputs/module
7+
// RUN: c-index-test core -print-unit %t.idx | FileCheck %s --check-prefixes=ALL,IGNORE
48

59
@import ModDep;
610
@import ModSystem;
711

8-
// CHECK: ModDep.pcm
9-
// CHECK: provider: clang-
10-
// CHECK: is-system: 0
11-
// CHECK: is-module: 1
12-
// CHECK: module-name: ModDep
13-
// CHECK: has-main: 0
14-
// CHECK: main-path: {{$}}
15-
// CHECK: out-file: {{.*}}{{/|\\}}ModDep.pcm
16-
// CHECK: DEPEND START
17-
// CHECK: Unit | user | ModTop | {{.*}}{{/|\\}}ModTop.pcm | ModTop.pcm
18-
// CHECK: Record | user | ModDep | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModDep.h | ModDep.h
19-
// CHECK: DEPEND END (2)
12+
// IGNORE-NOT: ModDep.pcm
13+
// MODULES: ModDep.pcm
14+
// MODULES: provider: clang-
15+
// MODULES: is-system: 0
16+
// MODULES: is-module: 1
17+
// MODULES: module-name: ModDep
18+
// MODULES: has-main: 0
19+
// MODULES: main-path: {{$}}
20+
// MODULES: out-file: {{.*}}{{/|\\}}ModDep.pcm
21+
// MODULES: DEPEND START
22+
// MODULES: Unit | user | ModTop | {{.*}}{{/|\\}}ModTop.pcm | ModTop.pcm
23+
// MODULES: Record | user | ModDep | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModDep.h | ModDep.h
24+
// MODULES: DEPEND END (2)
2025

21-
// CHECK: ModSystem.pcm
22-
// CHECK: is-system: 1
23-
// CHECK: is-module: 1
24-
// CHECK: module-name: ModSystem
25-
// CHECK: has-main: 0
26-
// CHECK: main-path: {{$}}
27-
// CHECK: out-file: {{.*}}{{/|\\}}ModSystem.pcm
28-
// CHECK: DEPEND START
29-
// CHECK: Record | system | ModSystem | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModSystem.h | ModSystem.h
30-
// CHECK: DEPEND END (1)
26+
// IGNORE-NOT: ModSystem.pcm
27+
// MODULES: ModSystem.pcm
28+
// MODULES: is-system: 1
29+
// MODULES: is-module: 1
30+
// MODULES: module-name: ModSystem
31+
// MODULES: has-main: 0
32+
// MODULES: main-path: {{$}}
33+
// MODULES: out-file: {{.*}}{{/|\\}}ModSystem.pcm
34+
// MODULES: DEPEND START
35+
// MODULES: Record | system | ModSystem | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModSystem.h | ModSystem.h
36+
// MODULES: DEPEND END (1)
3137

32-
// CHECK: ModTop.pcm
33-
// CHECK: is-system: 0
34-
// CHECK: is-module: 1
35-
// CHECK: module-name: ModTop
36-
// CHECK: has-main: 0
37-
// CHECK: main-path: {{$}}
38-
// CHECK: out-file: {{.*}}{{/|\\}}ModTop.pcm
39-
// CHECK: DEPEND START
40-
// CHECK: Record | user | ModTop | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTop.h | ModTop.h
41-
// CHECK: Record | user | ModTop.Sub1 | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTopSub1.h | ModTopSub1.h
42-
// CHECK: File | user | ModTop.Sub2 | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTopSub2.h{{$}}
43-
// CHECK: DEPEND END (3)
38+
// IGNORE-NOT: ModTop.pcm
39+
// MODULES: ModTop.pcm
40+
// MODULES: is-system: 0
41+
// MODULES: is-module: 1
42+
// MODULES: module-name: ModTop
43+
// MODULES: has-main: 0
44+
// MODULES: main-path: {{$}}
45+
// MODULES: out-file: {{.*}}{{/|\\}}ModTop.pcm
46+
// MODULES: DEPEND START
47+
// MODULES: Record | user | ModTop | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTop.h | ModTop.h
48+
// MODULES: Record | user | ModTop.Sub1 | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTopSub1.h | ModTopSub1.h
49+
// MODULES: File | user | ModTop.Sub2 | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}ModTopSub2.h{{$}}
50+
// MODULES: DEPEND END (3)
4451

45-
// CHECK: print-units-with-modules.m.tmp.o
46-
// CHECK: is-system: 0
47-
// CHECK: is-module: 0
48-
// CHECK: module-name: <none>
49-
// CHECK: has-main: 1
50-
// CHECK: main-path: {{.*}}{{/|\\}}print-units-with-modules.m
51-
// CHECK: out-file: {{.*}}{{/|\\}}print-units-with-modules.m.tmp.o
52-
// CHECK: DEPEND START
53-
// CHECK: Unit | user | ModDep | {{.*}}{{/|\\}}ModDep.pcm | ModDep.pcm
54-
// CHECK: Unit | system | ModSystem | {{.*}}{{/|\\}}ModSystem.pcm | ModSystem.pcm
55-
// CHECK: File | user | {{.*}}{{/|\\}}print-units-with-modules.m{{$}}
56-
// CHECK: File | user | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}module.modulemap{{$}}
57-
// CHECK: DEPEND END (4)
52+
// ALL: print-units-with-modules.m.tmp.o
53+
// ALL: is-system: 0
54+
// ALL: is-module: 0
55+
// ALL: module-name: <none>
56+
// ALL: has-main: 1
57+
// ALL: main-path: {{.*}}{{/|\\}}print-units-with-modules.m
58+
// ALL: out-file: {{.*}}{{/|\\}}print-units-with-modules.m.tmp.o
59+
// ALL: DEPEND START
60+
// MODULES: Unit | user | ModDep | {{.*}}{{/|\\}}ModDep.pcm | ModDep.pcm
61+
// MODULES: Unit | system | ModSystem | {{.*}}{{/|\\}}ModSystem.pcm | ModSystem.pcm
62+
// IGNORE: Unit | user | ModDep | {{.*}}{{/|\\}}ModDep.pcm
63+
// IGNORE: Unit | system | ModSystem | {{.*}}{{/|\\}}ModSystem.pcm
64+
// ALL: File | user | {{.*}}{{/|\\}}print-units-with-modules.m{{$}}
65+
// ALL: File | user | {{.*}}{{/|\\}}Inputs{{/|\\}}module{{/|\\}}module.modulemap{{$}}
66+
// ALL: DEPEND END (4)

0 commit comments

Comments
 (0)