[C++20] [Modules] Don't check input files for C++20 Modules
Close https://github.com/llvm/llvm-project/issues/62269 Currently, the compiler will emit errors when we compile C++20 modules if the referenced files changed or got removed. This is because we reuse the existing logic from Clang implicit modules. It is helpful for clang implicit modules since it is implicit and we want to be sure things don't go wrong. But it is not necessary for C++20 modules. The C++20 modules is explicit and it is build systems' responsibility to maintain the dependencies. So the check in the compiler side may be an overkill.
This commit is contained in:
parent
a29a97d76b
commit
5b388f86aa
@ -164,6 +164,9 @@ public:
|
||||
/// Whether this precompiled header is a relocatable PCH file.
|
||||
bool RelocatablePCH = false;
|
||||
|
||||
/// Whether this mdoule file is a standard c++ module.
|
||||
bool StandardCXXModule = false;
|
||||
|
||||
/// Whether timestamps are included in this module file.
|
||||
bool HasTimestamps = false;
|
||||
|
||||
|
||||
@ -2389,12 +2389,15 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
|
||||
StringRef Filename = FI.Filename;
|
||||
uint64_t StoredContentHash = FI.ContentHash;
|
||||
|
||||
// For standard C++ modules, we don't need to check the inputs.
|
||||
bool SkipChecks = F.StandardCXXModule;
|
||||
|
||||
OptionalFileEntryRefDegradesToFileEntryPtr File = OptionalFileEntryRef(
|
||||
expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)));
|
||||
|
||||
// For an overridden file, create a virtual file with the stored
|
||||
// size/timestamp.
|
||||
if ((Overridden || Transient) && !File)
|
||||
if ((Overridden || Transient || SkipChecks) && !File)
|
||||
File = FileMgr.getVirtualFileRef(Filename, StoredSize, StoredTime);
|
||||
|
||||
if (!File) {
|
||||
@ -2417,7 +2420,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
|
||||
// PCH.
|
||||
SourceManager &SM = getSourceManager();
|
||||
// FIXME: Reject if the overrides are different.
|
||||
if ((!Overridden && !Transient) && SM.isFileOverridden(File)) {
|
||||
if ((!Overridden && !Transient) && !SkipChecks && SM.isFileOverridden(File)) {
|
||||
if (Complain)
|
||||
Error(diag::err_fe_pch_file_overridden, Filename);
|
||||
|
||||
@ -2476,7 +2479,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
|
||||
};
|
||||
|
||||
bool IsOutOfDate = false;
|
||||
auto FileChange = HasInputFileChanged();
|
||||
auto FileChange = SkipChecks ? Change{Change::None} : HasInputFileChanged();
|
||||
// For an overridden file, there is nothing to validate.
|
||||
if (!Overridden && FileChange.Kind != Change::None) {
|
||||
if (Complain && !Diags.isDiagnosticInFlight()) {
|
||||
@ -2821,7 +2824,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
|
||||
return VersionMismatch;
|
||||
}
|
||||
|
||||
bool hasErrors = Record[6];
|
||||
bool hasErrors = Record[7];
|
||||
if (hasErrors && !DisableValidation) {
|
||||
// If requested by the caller and the module hasn't already been read
|
||||
// or compiled, mark modules on error as out-of-date.
|
||||
@ -2845,7 +2848,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
|
||||
if (F.RelocatablePCH)
|
||||
F.BaseDirectory = isysroot.empty() ? "/" : isysroot;
|
||||
|
||||
F.HasTimestamps = Record[5];
|
||||
F.StandardCXXModule = Record[5];
|
||||
|
||||
F.HasTimestamps = Record[6];
|
||||
|
||||
const std::string &CurBranch = getClangFullRepositoryVersion();
|
||||
StringRef ASTBranch = Blob;
|
||||
|
||||
@ -1243,6 +1243,8 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj.
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min.
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable
|
||||
// Standard C++ module
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors
|
||||
MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag
|
||||
@ -1250,15 +1252,15 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
|
||||
assert((!WritingModule || isysroot.empty()) &&
|
||||
"writing module as a relocatable PCH?");
|
||||
{
|
||||
RecordData::value_type Record[] = {
|
||||
METADATA,
|
||||
VERSION_MAJOR,
|
||||
VERSION_MINOR,
|
||||
CLANG_VERSION_MAJOR,
|
||||
CLANG_VERSION_MINOR,
|
||||
!isysroot.empty(),
|
||||
IncludeTimestamps,
|
||||
ASTHasCompilerErrors};
|
||||
RecordData::value_type Record[] = {METADATA,
|
||||
VERSION_MAJOR,
|
||||
VERSION_MINOR,
|
||||
CLANG_VERSION_MAJOR,
|
||||
CLANG_VERSION_MINOR,
|
||||
!isysroot.empty(),
|
||||
isWritingStdCXXNamedModules(),
|
||||
IncludeTimestamps,
|
||||
ASTHasCompilerErrors};
|
||||
Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record,
|
||||
getClangFullRepositoryVersion());
|
||||
}
|
||||
|
||||
56
clang/test/Modules/cxx20-no-check-input.cppm
Normal file
56
clang/test/Modules/cxx20-no-check-input.cppm
Normal file
@ -0,0 +1,56 @@
|
||||
// RUN: rm -rf %t
|
||||
// RUN: split-file %s %t
|
||||
// RUN: cd %t
|
||||
//
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.cppm -emit-module-interface -o %t/a.pcm
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/use.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.pcm -emit-llvm -o - | FileCheck %t/a.ll
|
||||
//
|
||||
// RUN: echo "//Update" >> %t/foo.h
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/use.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.pcm -emit-llvm -o - | FileCheck %t/a.ll
|
||||
//
|
||||
// RUN: echo "//Update" >> %t/a.cppm
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/use.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.pcm -emit-llvm -o - | FileCheck %t/a.ll
|
||||
//
|
||||
// RUN: rm -f %t/foo.h
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/use.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.pcm -emit-llvm -o - | FileCheck %t/a.ll
|
||||
//
|
||||
// RUN: rm -f %t/a.cppm
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/use.cpp -fmodule-file=a=%t/a.pcm -verify -fsyntax-only
|
||||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \
|
||||
// RUN: %t/a.pcm -emit-llvm -o - | FileCheck %t/a.ll
|
||||
|
||||
//--- foo.h
|
||||
inline int foo = 43;
|
||||
|
||||
//--- a.cppm
|
||||
// expected-no-diagnostics
|
||||
module;
|
||||
#include "foo.h"
|
||||
export module a;
|
||||
export using ::foo;
|
||||
|
||||
//--- a.ll
|
||||
// check the LLVM IR are generated succesfully.
|
||||
// CHECK: define{{.*}}@_ZGIW1a
|
||||
|
||||
//--- use.cpp
|
||||
// expected-no-diagnostics
|
||||
import a;
|
||||
int use() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user