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

Fix a native integer decoding bug #43885

Merged
4 commits merged into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private TypeSymbol TransformType(TypeSymbol type)
return TransformPointerType((PointerTypeSymbol)type);
case TypeKind.TypeParameter:
case TypeKind.Dynamic:
IgnoreIndex();
Copy link
Member Author

Choose a reason for hiding this comment

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

This part is the bug fix.

return type;
case TypeKind.Class:
case TypeKind.Struct:
Expand All @@ -84,6 +85,8 @@ private NamedTypeSymbol TransformNamedType(NamedTypeSymbol type)
return _transformFlags[index] ? TransformTypeDefinition(type) : type;
}

Debug.Assert(!_transformFlags[index]);

var allTypeArguments = ArrayBuilder<TypeWithAnnotations>.GetInstance();
type.GetAllTypeArgumentsNoUseSiteDiagnostics(allTypeArguments);

Expand All @@ -106,13 +109,13 @@ private NamedTypeSymbol TransformNamedType(NamedTypeSymbol type)

private ArrayTypeSymbol TransformArrayType(ArrayTypeSymbol type)
{
Increment();
IgnoreIndex();
return type.WithElementType(TransformTypeWithAnnotations(type.ElementTypeWithAnnotations));
}

private PointerTypeSymbol TransformPointerType(PointerTypeSymbol type)
{
Increment();
IgnoreIndex();
return type.WithPointedAtType(TransformTypeWithAnnotations(type.PointedAtTypeWithAnnotations));
}

Expand All @@ -125,6 +128,12 @@ private int Increment()
throw new ArgumentException();
Copy link
Member

@gafter gafter May 1, 2020

Choose a reason for hiding this comment

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

throw new ArgumentException [](start = 12, length = 27)

If we're worried about handwritten attribute data, this could crash the compiler as well. Please add a test. #Resolved

Copy link
Member Author

@333fred 333fred May 1, 2020

Choose a reason for hiding this comment

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

It can't crash the compiler, it's caught above. I already tried to crash it with this :). #Resolved

Copy link
Member

Choose a reason for hiding this comment

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

There should be existing tests for this case.


In reply to: 418757779 [](ancestors = 418757779)

}

private void IgnoreIndex()
{
var index = Increment();
Debug.Assert(!_transformFlags[index]);
Copy link
Member

@cston cston May 1, 2020

Choose a reason for hiding this comment

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

Debug.Assert(!_transformFlags[index]) [](start = 12, length = 37)

This may fail for handwritten attribute data.

Please add a test.

}

private static NamedTypeSymbol TransformTypeDefinition(NamedTypeSymbol type)
{
switch (type.SpecialType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,33 @@ public void AttributeFieldExists()
});
}

[Theory]
[InlineData("C<dynamic, nint, System.IntPtr>", "C<dynamic, System.IntPtr, System.IntPtr>", "False, False, True, False")]
[InlineData("C<dynamic, nuint, System.UIntPtr>", "C<dynamic, System.UIntPtr, System.UIntPtr>", "False, False, True, False")]
[InlineData("C<T, nint, System.IntPtr>", "C<T, System.IntPtr, System.IntPtr>", "False, False, True, False")]
[InlineData("C<T, nuint, System.UIntPtr>", "C<T, System.UIntPtr, System.UIntPtr>", "False, False, True, False")]
public void NestedNativeIntegerWithPrecedingType(string sourceType, string metadataType, string expectedAttribute)
{
var comp = CompileAndVerify($@"
class C<T, U, V>
{{
public {sourceType} F;
}}
Copy link
Member

@cston cston May 1, 2020

Choose a reason for hiding this comment

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

Please consider writing out all the cases inline as separate fields in a single test, for readability and to match other tests.

", options: TestOptions.ReleaseDll, parseOptions: TestOptions.RegularPreview, symbolValidator: symbolValidator);

void symbolValidator(ModuleSymbol module)
Copy link
Member

Choose a reason for hiding this comment

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

void [](start = 12, length = 4)

Consider making static or inline in CompileAndVerify to match the other tests.

{
var expectedAttributes = $@"
C<T, U, V>
[NativeInteger({{ {expectedAttribute} }})] {metadataType} F";

AssertNativeIntegerAttributes(module, expectedAttributes);
var c = module.GlobalNamespace.GetTypeMember("C");
var field = c.GetField("F");
Assert.Equal(sourceType, field.Type.ToTestDisplayString());
}
}

private static TypeDefinition GetTypeDefinitionByName(MetadataReader reader, string name)
{
return reader.GetTypeDefinition(reader.TypeDefinitions.Single(h => reader.StringComparer.Equals(reader.GetTypeDefinition(h).Name, name)));
Expand Down