@@ -1174,26 +1174,47 @@ ASTWriter::createSignature() const {
1174
1174
return std::make_pair (ASTBlockHash, Signature);
1175
1175
}
1176
1176
1177
+ ASTFileSignature ASTWriter::createSignatureForNamedModule () const {
1178
+ llvm::SHA1 Hasher;
1179
+ Hasher.update (StringRef (Buffer.data (), Buffer.size ()));
1180
+
1181
+ assert (WritingModule);
1182
+ assert (WritingModule->isNamedModule ());
1183
+
1184
+ // We need to combine all the export imported modules no matter
1185
+ // we used it or not.
1186
+ for (auto [ExportImported, _] : WritingModule->Exports )
1187
+ Hasher.update (ExportImported->Signature );
1188
+
1189
+ return ASTFileSignature::create (Hasher.result ());
1190
+ }
1191
+
1192
+ static void BackpatchSignatureAt (llvm::BitstreamWriter &Stream,
1193
+ const ASTFileSignature &S, uint64_t BitNo) {
1194
+ for (uint8_t Byte : S) {
1195
+ Stream.BackpatchByte (BitNo, Byte);
1196
+ BitNo += 8 ;
1197
+ }
1198
+ }
1199
+
1177
1200
ASTFileSignature ASTWriter::backpatchSignature () {
1201
+ if (isWritingStdCXXNamedModules ()) {
1202
+ ASTFileSignature Signature = createSignatureForNamedModule ();
1203
+ BackpatchSignatureAt (Stream, Signature, SignatureOffset);
1204
+ return Signature;
1205
+ }
1206
+
1178
1207
if (!WritingModule ||
1179
1208
!PP->getHeaderSearchInfo ().getHeaderSearchOpts ().ModulesHashContent )
1180
1209
return {};
1181
1210
1182
1211
// For implicit modules, write the hash of the PCM as its signature.
1183
-
1184
- auto BackpatchSignatureAt = [&](const ASTFileSignature &S, uint64_t BitNo) {
1185
- for (uint8_t Byte : S) {
1186
- Stream.BackpatchByte (BitNo, Byte);
1187
- BitNo += 8 ;
1188
- }
1189
- };
1190
-
1191
1212
ASTFileSignature ASTBlockHash;
1192
1213
ASTFileSignature Signature;
1193
1214
std::tie (ASTBlockHash, Signature) = createSignature ();
1194
1215
1195
- BackpatchSignatureAt (ASTBlockHash, ASTBlockHashOffset);
1196
- BackpatchSignatureAt (Signature, SignatureOffset);
1216
+ BackpatchSignatureAt (Stream, ASTBlockHash, ASTBlockHashOffset);
1217
+ BackpatchSignatureAt (Stream, Signature, SignatureOffset);
1197
1218
1198
1219
return Signature;
1199
1220
}
@@ -1210,9 +1231,11 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
1210
1231
RecordData Record;
1211
1232
Stream.EnterSubblock (UNHASHED_CONTROL_BLOCK_ID, 5 );
1212
1233
1213
- // For implicit modules, write the hash of the PCM as its signature.
1214
- if (WritingModule &&
1215
- PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModulesHashContent ) {
1234
+ // For implicit modules and C++20 named modules, write the hash of the PCM as
1235
+ // its signature.
1236
+ if (isWritingStdCXXNamedModules () ||
1237
+ (WritingModule &&
1238
+ PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModulesHashContent )) {
1216
1239
// At this point, we don't know the actual signature of the file or the AST
1217
1240
// block - we're only able to compute those at the end of the serialization
1218
1241
// process. Let's store dummy signatures for now, and replace them with the
@@ -1223,21 +1246,24 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
1223
1246
auto Dummy = ASTFileSignature::createDummy ();
1224
1247
SmallString<128 > Blob{Dummy.begin (), Dummy.end ()};
1225
1248
1226
- auto Abbrev = std::make_shared<BitCodeAbbrev>();
1227
- Abbrev->Add (BitCodeAbbrevOp (AST_BLOCK_HASH));
1228
- Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob));
1229
- unsigned ASTBlockHashAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
1249
+ // We don't need AST Block hash in named modules.
1250
+ if (!isWritingStdCXXNamedModules ()) {
1251
+ auto Abbrev = std::make_shared<BitCodeAbbrev>();
1252
+ Abbrev->Add (BitCodeAbbrevOp (AST_BLOCK_HASH));
1253
+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob));
1254
+ unsigned ASTBlockHashAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
1230
1255
1231
- Abbrev = std::make_shared<BitCodeAbbrev>();
1256
+ Record.push_back (AST_BLOCK_HASH);
1257
+ Stream.EmitRecordWithBlob (ASTBlockHashAbbrev, Record, Blob);
1258
+ ASTBlockHashOffset = Stream.GetCurrentBitNo () - Blob.size () * 8 ;
1259
+ Record.clear ();
1260
+ }
1261
+
1262
+ auto Abbrev = std::make_shared<BitCodeAbbrev>();
1232
1263
Abbrev->Add (BitCodeAbbrevOp (SIGNATURE));
1233
1264
Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob));
1234
1265
unsigned SignatureAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
1235
1266
1236
- Record.push_back (AST_BLOCK_HASH);
1237
- Stream.EmitRecordWithBlob (ASTBlockHashAbbrev, Record, Blob);
1238
- ASTBlockHashOffset = Stream.GetCurrentBitNo () - Blob.size () * 8 ;
1239
- Record.clear ();
1240
-
1241
1267
Record.push_back (SIGNATURE);
1242
1268
Stream.EmitRecordWithBlob (SignatureAbbrev, Record, Blob);
1243
1269
SignatureOffset = Stream.GetCurrentBitNo () - Blob.size () * 8 ;
0 commit comments