Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ private uint GetClassTypeIndex(TypeDesc type, bool needsCompleteType)
bool hasNonGcStatics = NodeFactory.MetadataManager.HasNonGcStaticBase(defType);
bool hasGcStatics = NodeFactory.MetadataManager.HasGcStaticBase(defType);
bool hasThreadStatics = NodeFactory.MetadataManager.HasThreadStaticBase(defType);
bool hasInstanceFields = defType.IsValueType || NodeFactory.MetadataManager.HasConstructedEEType(defType);

bool isCanonical = defType.IsCanonicalSubtype(CanonicalFormKind.Any);

Expand Down Expand Up @@ -622,8 +621,11 @@ private uint GetClassTypeIndex(TypeDesc type, bool needsCompleteType)
}
else
{
if (!hasInstanceFields)
continue;
// Allow instance fields to be emitted even for types that are never instantiated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this is problematic because we're going to be looking at layout of types that we didn't look at before (no constructed type means we never had to calculate type size or look at instance fields). If there's a problem with the type (e.g. has an instance field of a type that doesn't resolve because e.g. NuGet was a mismatched version), we're likely to crash here a couple lines down. We had crashes like that before, this is what the code around line 636 is dealing with.

I'm going to ask about the motivation in the original issue. Right now I'm leaning toward By Design/Won't fix on this.

// This ensures DWARF debug info is generated for all type fields, which is
// important for debugging scenarios where types are referenced but not constructed.
// Previously, a guard would skip instance fields when hasInstanceFields was false,
// preventing debug info generation for types like: var nullObj = (MyClass)null;
}

LayoutInt fieldOffset = fieldDesc.Offset;
Expand Down