Skip to content

Commit c1ecc0d

Browse files
[clang] Allow generating module interfaces with parsing errors (#121485)
Fixes a regression introduced in commit da00c60 This functionality was originally added in commit 5834996 Co-authored-by: Tomasz Kaminski <[email protected]>
1 parent 7531672 commit c1ecc0d

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,15 @@ class CXX20ModulesGenerator : public PCHGenerator {
997997
virtual Module *getEmittingModule(ASTContext &Ctx) override;
998998

999999
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1000-
StringRef OutputFile, bool GeneratingReducedBMI);
1000+
StringRef OutputFile, bool GeneratingReducedBMI,
1001+
bool AllowASTWithErrors);
10011002

10021003
public:
10031004
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1004-
StringRef OutputFile)
1005+
StringRef OutputFile, bool AllowASTWithErrors = false)
10051006
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1006-
/*GeneratingReducedBMI=*/false) {}
1007+
/*GeneratingReducedBMI=*/false,
1008+
AllowASTWithErrors) {}
10071009

10081010
void HandleTranslationUnit(ASTContext &Ctx) override;
10091011
};
@@ -1013,9 +1015,10 @@ class ReducedBMIGenerator : public CXX20ModulesGenerator {
10131015

10141016
public:
10151017
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1016-
StringRef OutputFile)
1018+
StringRef OutputFile, bool AllowASTWithErrors = false)
10171019
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1018-
/*GeneratingReducedBMI=*/true) {}
1020+
/*GeneratingReducedBMI=*/true,
1021+
AllowASTWithErrors) {}
10191022
};
10201023

10211024
/// If we can elide the definition of \param D in reduced BMI.

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,14 @@ GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
279279
!CI.getFrontendOpts().ModuleOutputPath.empty()) {
280280
Consumers.push_back(std::make_unique<ReducedBMIGenerator>(
281281
CI.getPreprocessor(), CI.getModuleCache(),
282-
CI.getFrontendOpts().ModuleOutputPath));
282+
CI.getFrontendOpts().ModuleOutputPath,
283+
+CI.getFrontendOpts().AllowPCMWithCompilerErrors));
283284
}
284285

285286
Consumers.push_back(std::make_unique<CXX20ModulesGenerator>(
286287
CI.getPreprocessor(), CI.getModuleCache(),
287-
CI.getFrontendOpts().OutputFile));
288+
CI.getFrontendOpts().OutputFile,
289+
+CI.getFrontendOpts().AllowPCMWithCompilerErrors));
288290

289291
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
290292
}

clang/lib/Serialization/GeneratePCH.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ void PCHGenerator::anchor() {}
102102
CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
103103
InMemoryModuleCache &ModuleCache,
104104
StringRef OutputFile,
105-
bool GeneratingReducedBMI)
105+
bool GeneratingReducedBMI,
106+
bool AllowASTWithErrors)
106107
: PCHGenerator(
107108
PP, ModuleCache, OutputFile, llvm::StringRef(),
108109
std::make_shared<PCHBuffer>(),
109110
/*Extensions=*/ArrayRef<std::shared_ptr<ModuleFileExtension>>(),
110-
/*AllowASTWithErrors*/ false, /*IncludeTimestamps=*/false,
111+
AllowASTWithErrors, /*IncludeTimestamps=*/false,
111112
/*BuildingImplicitModule=*/false, /*ShouldCacheASTInMemory=*/false,
112113
GeneratingReducedBMI) {}
113114

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
5+
// RUN: %clang_cc1 -std=c++23 m.cppm -emit-module-interface -o m.pcm -fallow-pcm-with-compiler-errors -verify
6+
// RUN: %clang_cc1 -std=c++23 main.cpp -fmodule-file=m=m.pcm -verify -fallow-pcm-with-compiler-errors -verify
7+
8+
// RUN: %clang_cc1 -std=c++23 m.cppm -fmodules-reduced-bmi -emit-module-interface -o m.pcm -fallow-pcm-with-compiler-errors -verify
9+
// RUN: %clang_cc1 -std=c++23 main.cpp -fmodule-file=m=m.pcm -verify -fallow-pcm-with-compiler-errors -verify
10+
11+
//--- m.cppm
12+
export module m;
13+
14+
export int f() {
15+
return 0;
16+
}
17+
18+
export struct Foo {
19+
__Int bar; // expected-error {{unknown type name '__Int'}}
20+
};
21+
22+
//--- main.cpp
23+
// expected-no-diagnostics
24+
import m; // ok
25+
26+
static_assert(__is_same(decltype(f), int())); // ok

0 commit comments

Comments
 (0)