Skip to content
Merged
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
Fix assert in NativeAOT when handling data flow on compiler generated…
… code.

The problem occurs when an entire type/assembly is preserved through explicit rooting (command line, rd.xml, ...). If such type contains a local function (for example) which is only called from a branch which is going to be removed by constant-prop/branch removal the internal tracking of compiler generated methods will see this local function as orphaned (not belonging to any user method). This leads to a case where we will try to run data flow on the local function - but that should never happen for compiler generated methods directly -> assert.

The fix is (just like in the linker), to never run data flow on compiler generated methods directly - they should only run data flow as part of their respective user method.

Fixes #73027
  • Loading branch information
vitek-karas committed Jul 29, 2022
commit 7d59fde891b6edf454c2943098bdbd2b30aa9783
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ private void AddDataflowDependency(ref DependencyList dependencies, NodeFactory
methodILDefinition = FlowAnnotations.ILProvider.GetMethodIL(userMethod);
}

// Data-flow (reflection scanning) for compiler-generated methods will happen as part of the
Copy link
Member

Choose a reason for hiding this comment

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

I only understood what's going on after re-reading the pull request description - could you add a sentence describing when this can happen (the lines before this are supposed to do this conversion to user code).

// data-flow scan of the user-defined method which uses this compiler-generated method.
if (CompilerGeneratedState.IsNestedFunctionOrStateMachineMember(methodILDefinition.OwningMethod))
return;

dependencies = dependencies ?? new DependencyList();
dependencies.Add(factory.DataflowAnalyzedMethod(methodILDefinition), reason);
}
Expand Down