Skip to content

Commit

Permalink
Fix assert in NativeAOT when handling data flow on compiler generated…
Browse files Browse the repository at this point in the history
… 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 dotnet#73027
  • Loading branch information
vitek-karas committed Jul 29, 2022
1 parent b6115b0 commit 7d59fde
Showing 1 changed file with 5 additions and 0 deletions.
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
// 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

0 comments on commit 7d59fde

Please sign in to comment.