Repository: dotnet/runtime
File: src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/StackTraceLineNumbersNode.cs (C#)

Code before:
                    continue;

                Vertex blob = CreateLineNumbersBlob(nativeWriter, _documents, debugInfo);
                if (blob == null)
                    continue;

                Vertex methodPointer = nativeWriter.GetUnsignedConstant(_externalReferences.GetIndex(entrypointSymbol));
                var hashtableEntry = nativeWriter.GetTuple(methodPointer, blob);

                uint hashcode = VersionResilientHashCode.CombineTwoValuesIntoHash((uint)mapping.OwningTypeHandle, (uint)mapping.MethodHandle);
                hashtable.Append(hashcode, nativeSection.Place(hashtableEntry));
            }

            static Vertex CreateLineNumbersBlob(NativeWriter writer, StackTraceDocumentsNode documents, INodeWithDebugInfo debugInfoNode)
            {
                var encoder = default(NativePrimitiveEncoder);
                encoder.Init();

                int currentNativeOffset = 0;
                int currentLineNumber = 0;
                string currentDocument = null;

                uint numEntries = 0;

                foreach (NativeSequencePoint sequencePoint in debugInfoNode.GetNativeSequencePoints())
                {
                    if (currentDocument != sequencePoint.FileName)
                    {
                        // We start with currentDocument == null, so the reader knows the first byte of the output
                        // is a document number. Otherwise we use NativeOffsetDelta == 0 as a marker that the next
                        // byte is a document number and not a native offset delta.
                        if (currentDocument != null)
                            encoder.WriteSigned(0);
                        encoder.WriteSigned(documents.GetDocumentId(sequencePoint.FileName));
                    }

                    int nativeOffsetDelta = sequencePoint.NativeOffset - currentNativeOffset;
                    encoder.WriteSigned(nativeOffsetDelta);

                    int lineNumberDelta = sequencePoint.LineNumber - currentLineNumber;
                    encoder.WriteSigned(lineNumberDelta);

                    numEntries++;

                    currentLineNumber = sequencePoint.LineNumber;
                    currentNativeOffset = sequencePoint.NativeOffset;
                    currentDocument = sequencePoint.FileName;
                }

                var ms = new MemoryStream();
                encoder.Save(ms);

Review comment (bug):
```suggestion
                {
                    // Make sure a zero native offset delta is not possible because we use it below
                    // to indicate an update to the current document.
                    Debug.Assert(currentDocument == null || currentNativeOffset != sequencePoint.NativeOffset);
```

Code after:
                    continue;

                Vertex blob = CreateLineNumbersBlob(nativeWriter, _documents, debugInfo);
                if (blob == null)
                    continue;

                Vertex methodPointer = nativeWriter.GetUnsignedConstant(_externalReferences.GetIndex(entrypointSymbol));
                var hashtableEntry = nativeWriter.GetTuple(methodPointer, blob);

                uint hashcode = VersionResilientHashCode.CombineTwoValuesIntoHash((uint)mapping.OwningTypeHandle, (uint)mapping.MethodHandle);
                hashtable.Append(hashcode, nativeSection.Place(hashtableEntry));
            }

            static Vertex CreateLineNumbersBlob(NativeWriter writer, StackTraceDocumentsNode documents, INodeWithDebugInfo debugInfoNode)
            {
                var encoder = default(NativePrimitiveEncoder);
                encoder.Init();

                int currentNativeOffset = 0;
                int currentLineNumber = 0;
                string currentDocument = null;

                uint numEntries = 0;

                foreach (NativeSequencePoint sequencePoint in debugInfoNode.GetNativeSequencePoints())
                {
                    // Make sure a zero native offset delta is not possible because we use it below
                    // to indicate an update to the current document.
                    Debug.Assert(currentDocument == null || currentNativeOffset != sequencePoint.NativeOffset);
                    if (currentDocument != sequencePoint.FileName)
                    {
                        // We start with currentDocument == null, so the reader knows the first byte of the output
                        // is a document number. Otherwise we use NativeOffsetDelta == 0 as a marker that the next
                        // byte is a document number and not a native offset delta.
                        if (currentDocument != null)
                            encoder.WriteSigned(0);
                        encoder.WriteSigned(documents.GetDocumentId(sequencePoint.FileName));
                    }

                    int nativeOffsetDelta = sequencePoint.NativeOffset - currentNativeOffset;
                    encoder.WriteSigned(nativeOffsetDelta);

                    int lineNumberDelta = sequencePoint.LineNumber - currentLineNumber;
                    encoder.WriteSigned(lineNumberDelta);

                    numEntries++;

                    currentLineNumber = sequencePoint.LineNumber;
                    currentNativeOffset = sequencePoint.NativeOffset;
                    currentDocument = sequencePoint.FileName;
                }