Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions source/compiler-core/slang-diagnostic-sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,18 @@ static void _sourceLocationNoteDiagnostic(
return;
}

UnownedStringSlice content = sourceFile->getContent();

// Make sure the offset is within content.
// Check if the source file has actual content available.
// This is important because it's possible to have a 'SourceFile' that doesn't contain any
// content (for example when reconstructed via serialization with just line offsets, the actual
// source text 'content' isn't available).
if (!sourceFile->hasContent())
{
return;
}

UnownedStringSlice content = sourceFile->getContent();

// Make sure the offset is within content.
const int offset = sourceView->getRange().getOffset(sourceLoc);
if (offset < 0 || offset >= content.getLength())
{
Expand Down Expand Up @@ -388,12 +394,18 @@ static void _tokenLengthNoteDiagnostic(
return;
}

UnownedStringSlice content = sourceFile->getContent();

// Make sure the offset is within content.
// Check if the source file has actual content available.
// This is important because it's possible to have a 'SourceFile' that doesn't contain any
// content (for example when reconstructed via serialization with just line offsets, the actual
// source text 'content' isn't available).
if (!sourceFile->hasContent())
{
return;
}

UnownedStringSlice content = sourceFile->getContent();

// Make sure the offset is within content.
const int offset = sourceView->getRange().getOffset(sourceLoc);
if (offset < 0 || offset >= content.getLength())
{
Expand Down
20 changes: 13 additions & 7 deletions source/slang/slang-session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,13 +2039,19 @@ SlangResult Linkage::loadSerializedModuleContents(
//
SourceLoc serializedModuleLoc;
{
auto sourceFile =
sourceManager->findSourceFileByPathRecursively(moduleFilePathInfo.foundPath);
if (!sourceFile)
{
sourceFile = sourceManager->createSourceFileWithString(moduleFilePathInfo, String());
sourceManager->addSourceFile(moduleFilePathInfo.getMostUniqueIdentity(), sourceFile);
}
// For the purposes of diagnostics, we create a source file to represent
// the binary module file. We intentionally create this with empty content
// to avoid displaying binary data in error messages.
//
// Note: We do NOT reuse any existing source file for this path, because
// an earlier code path (e.g., IncludeSystem::loadFile) may have loaded
// the binary module content into a source file, and we don't want to
// display that binary data when showing diagnostic source lines.
//
auto sourceFile = sourceManager->createSourceFileWithString(moduleFilePathInfo, String());
sourceManager->addSourceFileIfNotExist(
moduleFilePathInfo.getMostUniqueIdentity(),
sourceFile);
auto sourceView =
sourceManager->createSourceView(sourceFile, &moduleFilePathInfo, SourceLoc());
serializedModuleLoc = sourceView->getRange().begin;
Expand Down