Fix closed-generic .cctor ordering causing NullReferenceException - #3493
Conversation
- Add EnsureGenericCctorCompleted() to force a closed generic type .cctor to run before its first use. - Gate CEE_NEWOBJ, static CEE_CALL, CEE_LDSFLD, CEE_LDSFLDA, and CEE_STSFLD on the new check, removed the old post-access reschedule-on-null fallback. - Extend the gate to open declaring TypeSpecs (e.g. SZGenericArrayEnumerator<!!0>) that resolve to a closed instantiation via the caller's method generic context. - Update docs with the generic .cctor lifecycle and call contract. Assisted by Claude Opus 4.8
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Central YAML (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe interpreter centralizes generic static constructor completion in ChangesGeneric static constructor enforcement
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ILInterpreter
participant EnsureGenericCctorCompleted
participant GenericCctorExecution
participant StaticFieldResolver
ILInterpreter->>EnsureGenericCctorCompleted: process generic call, newobj, or static field access
EnsureGenericCctorCompleted->>GenericCctorExecution: inspect or update .cctor state
GenericCctorExecution-->>ILInterpreter: return completion, restart, or reschedule status
ILInterpreter->>StaticFieldResolver: resolve static field after completion
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/CLR/Core/Interpreter.cpp`:
- Around line 3066-3077: In the NEWOBJ .cctor type-selection block, reverse the
priority so valid stack->m_call.genericType is selected before
calleeInst.genericType. Preserve the existing validity checks and fallback
behavior, aligning this gate with the caller-first context selection used by the
object-creation path.
- Around line 1099-1118: Roll back the generic constructor record flags when
initialization or frame scheduling fails. In the flow that sets c_Scheduled and
c_Executed before CLR_RT_MethodDef_Instance::InitializeFromIndex and
CLR_RT_StackFrame::Push, clear both flags before returning either failure
HRESULT so a later trigger can retry the .cctor.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: dbf60a7e-eda4-411e-903a-6b09bb305ab2
📒 Files selected for processing (2)
src/CLR/Core/CLAUDE.mdsrc/CLR/Core/Interpreter.cpp
Description
Motivation and Context
How Has This Been Tested?
Screenshots
Types of changes
Checklist