Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker produces unknown value for merged value assigned to array element #2737

Open
Tracked by #101149
sbomer opened this issue Apr 11, 2022 · 0 comments
Open
Tracked by #101149
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Apr 11, 2022

Example:

Type[] arr = new Type[1];
arr[0] = string.Empty.Length == 0 ? GetMethods() : GetFields();
// IL2062 (Unknown value)
RequireAll(arr[0]);

I would expect this to instead produce two instances of IL2072, warning about GetMethods/GetFields, like what happens in this example:

Type[] arr = new Type[1];
if (string.Empty.Length == 0)
    arr[0] = GetMethods();
else
    arr[0] = GetFields();
RequireAll(arr[0]); // IL2072 (GetMethods/GetFields)

I debugged this a little - what happens is this:

  • We put a reference to an ArrayValue on the stack.
  • After the call to GetMethods() in one branch, and GetFields() in another, we merge stacks
  • Merging stacks allocates a new dictionary of array values for the merged stack slot holding the array reference.
    • This dictionary is now a different one than the original dictionary of values tracked in the locals of the method
  • We assign a merged value to the new dictionary.
  • We read arr[0] from the original ArrayValue which doesn't have any elements assigned.

I think this is a specific case of #2158 - we need to ensure that the array reference on the stack and that in the tracked locals are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant