Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Merging values on branch ends drops unknowns - underreports warnings #2624

Closed

Description

@vitek-karas

For example:

		[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
		public static Type TestBackwardEdgeWithLdElem (Type[] types = null)
		{
			Type resultType = null; // returning null is fine, it fulfills any annotation
			foreach (var type in types) {  // this is effectively ldelem, which should produce "unknown" value
				resultType = type;   // assigns "unknown" to the result
			}

			return resultType; // IL2063: "unknown" doesn't have requires annotations
		}

Internally the "unknown" value loaded from the array is represented as StackSlot with null Value. The null literal is represented as NullValue. What happens inside the loop is that we're storing a second value for a local, so we merge the "unknown" and NullValue. But because the "unknown" is represented as null, the merge ignores it, and we end up with just the NullValue, which won't produce a warning.

Activity

  1. vitek-karas commented on Feb 17, 2022

    @vitek-karas
    MemberAuthor

    @MichalStrehovsky for potential ideas... if you feel like diving back into the method body scanner.

  2. added a commit that references this issue on Feb 18, 2022
    ba7c11d
  3. MichalStrehovsky commented on Feb 18, 2022

    @MichalStrehovsky
    Member

    @MichalStrehovsky for potential ideas... if you feel like diving back into the method body scanner.

    Hehe, I never really dived much into it - that was part of the appeal of just reusing existing code - just make it build, delete features we don't need and done. It was a mechanical port without much thinking.

    I took a shot at it in #2631.

  4. MichalStrehovsky commented on Feb 22, 2022

    @MichalStrehovsky
    Member

    I think all that's left here is to enable the test. This was fixed somewhere in #2614.

  5. vitek-karas commented on Feb 22, 2022

    @vitek-karas
    MemberAuthor

    The test is already enabled for linker (came with the big merge). Analyzer will be a bit harder since the CFG's way of modeling foreach makes it rather difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions