@@ -401,7 +401,8 @@ static ValidationInfo validateControlBlock(
401
401
402
402
static bool validateInputBlock (
403
403
llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t > &scratch,
404
- SmallVectorImpl<SerializationOptions::FileDependency> &dependencies) {
404
+ SmallVectorImpl<SerializationOptions::FileDependency> *dependencies,
405
+ SmallVectorImpl<SearchPath> *searchPaths) {
405
406
SmallVector<StringRef, 4 > dependencyDirectories;
406
407
SmallString<256 > dependencyFullPathBuffer;
407
408
@@ -430,33 +431,43 @@ static bool validateInputBlock(
430
431
}
431
432
unsigned kind = maybeKind.get ();
432
433
switch (kind) {
433
- case input_block::FILE_DEPENDENCY: {
434
- bool isHashBased = scratch[2 ] != 0 ;
435
- bool isSDKRelative = scratch[3 ] != 0 ;
436
-
437
- StringRef path = blobData;
438
- size_t directoryIndex = scratch[4 ];
439
- if (directoryIndex != 0 ) {
440
- if (directoryIndex > dependencyDirectories.size ())
441
- return true ;
442
- dependencyFullPathBuffer = dependencyDirectories[directoryIndex-1 ];
443
- llvm::sys::path::append (dependencyFullPathBuffer, blobData);
444
- path = dependencyFullPathBuffer;
445
- }
434
+ case input_block::FILE_DEPENDENCY:
435
+ if (dependencies) {
436
+ bool isHashBased = scratch[2 ] != 0 ;
437
+ bool isSDKRelative = scratch[3 ] != 0 ;
438
+
439
+ StringRef path = blobData;
440
+ size_t directoryIndex = scratch[4 ];
441
+ if (directoryIndex != 0 ) {
442
+ if (directoryIndex > dependencyDirectories.size ())
443
+ return true ;
444
+ dependencyFullPathBuffer = dependencyDirectories[directoryIndex - 1 ];
445
+ llvm::sys::path::append (dependencyFullPathBuffer, blobData);
446
+ path = dependencyFullPathBuffer;
447
+ }
446
448
447
- if (isHashBased) {
448
- dependencies. push_back (
449
- SerializationOptions::FileDependency::hashBased (
450
- path, isSDKRelative, scratch[0 ], scratch[1 ]));
451
- } else {
452
- dependencies. push_back (
453
- SerializationOptions::FileDependency::modTimeBased (
454
- path, isSDKRelative, scratch[0 ], scratch[1 ]));
449
+ if (isHashBased)
450
+ dependencies-> push_back (
451
+ SerializationOptions::FileDependency::hashBased (
452
+ path, isSDKRelative, scratch[0 ], scratch[1 ]));
453
+ else
454
+ dependencies-> push_back (
455
+ SerializationOptions::FileDependency::modTimeBased (
456
+ path, isSDKRelative, scratch[0 ], scratch[1 ]));
455
457
}
456
458
break ;
457
- }
458
459
case input_block::DEPENDENCY_DIRECTORY:
459
- dependencyDirectories.push_back (blobData);
460
+ if (dependencies)
461
+ dependencyDirectories.push_back (blobData);
462
+ break ;
463
+ case input_block::SEARCH_PATH:
464
+ if (searchPaths) {
465
+ bool isFramework;
466
+ bool isSystem;
467
+ input_block::SearchPathLayout::readRecord (scratch, isFramework,
468
+ isSystem);
469
+ searchPaths->push_back ({std::string (blobData), isFramework, isSystem});
470
+ }
460
471
break ;
461
472
default :
462
473
// Unknown metadata record, possibly for use by a future version of the
@@ -467,7 +478,6 @@ static bool validateInputBlock(
467
478
return false ;
468
479
}
469
480
470
-
471
481
bool serialization::isSerializedAST (StringRef data) {
472
482
StringRef signatureStr (reinterpret_cast <const char *>(SWIFTMODULE_SIGNATURE),
473
483
llvm::array_lengthof (SWIFTMODULE_SIGNATURE));
@@ -477,7 +487,8 @@ bool serialization::isSerializedAST(StringRef data) {
477
487
ValidationInfo serialization::validateSerializedAST (
478
488
StringRef data, bool requiresOSSAModules, StringRef requiredSDK,
479
489
bool requiresRevisionMatch, ExtendedValidationInfo *extendedInfo,
480
- SmallVectorImpl<SerializationOptions::FileDependency> *dependencies) {
490
+ SmallVectorImpl<SerializationOptions::FileDependency> *dependencies,
491
+ SmallVectorImpl<SearchPath> *searchPaths) {
481
492
ValidationInfo result;
482
493
483
494
// Check 32-bit alignment.
@@ -523,7 +534,7 @@ ValidationInfo serialization::validateSerializedAST(
523
534
extendedInfo, localObfuscator);
524
535
if (result.status == Status::Malformed)
525
536
return result;
526
- } else if (dependencies &&
537
+ } else if (( dependencies || searchPaths) &&
527
538
result.status == Status::Valid &&
528
539
topLevelEntry.ID == INPUT_BLOCK_ID) {
529
540
if (llvm::Error Err = cursor.EnterSubBlock (INPUT_BLOCK_ID)) {
@@ -532,7 +543,7 @@ ValidationInfo serialization::validateSerializedAST(
532
543
result.status = Status::Malformed;
533
544
return result;
534
545
}
535
- if (validateInputBlock (cursor, scratch, * dependencies)) {
546
+ if (validateInputBlock (cursor, scratch, dependencies, searchPaths )) {
536
547
result.status = Status::Malformed;
537
548
return result;
538
549
}
0 commit comments