提交 1f80e1cf 编写于 作者: C Charles Stoner

InvalidOperationException emitting reference to void* parameter with custom modifiers

上级 cf920d44
......@@ -109,12 +109,12 @@ internal sealed override AssemblySymbol CorLibrary
public sealed override IEnumerable<string> LinkedAssembliesDebugInfo => SpecializedCollections.EmptyEnumerable<string>();
// C# currently doesn't emit compilation level imports (TODO: scripting).
public override ImmutableArray<Cci.UsedNamespaceOrType> GetImports() => ImmutableArray<Cci.UsedNamespaceOrType>.Empty;
public sealed override ImmutableArray<Cci.UsedNamespaceOrType> GetImports() => ImmutableArray<Cci.UsedNamespaceOrType>.Empty;
// C# doesn't allow to define default namespace for compilation.
public override string DefaultNamespace => null;
public sealed override string DefaultNamespace => null;
protected override IEnumerable<Cci.IAssemblyReference> GetAssemblyReferencesFromAddedModules(DiagnosticBag diagnostics)
protected sealed override IEnumerable<Cci.IAssemblyReference> GetAssemblyReferencesFromAddedModules(DiagnosticBag diagnostics)
{
ImmutableArray<ModuleSymbol> modules = SourceModule.ContainingAssembly.Modules;
......@@ -178,7 +178,7 @@ internal sealed override IEnumerable<Cci.INestedTypeDefinition> GetSynthesizedNe
return null;
}
public override MultiDictionary<Cci.DebugSourceDocument, Cci.DefinitionWithLocation> GetSymbolToLocationMap()
public sealed override MultiDictionary<Cci.DebugSourceDocument, Cci.DefinitionWithLocation> GetSymbolToLocationMap()
{
var result = new MultiDictionary<Cci.DebugSourceDocument, Cci.DefinitionWithLocation>();
......@@ -355,7 +355,7 @@ internal virtual bool TryGetAnonymousTypeName(NamedTypeSymbol template, out stri
return false;
}
internal override ImmutableArray<Cci.INamespaceTypeDefinition> GetAnonymousTypes()
internal sealed override ImmutableArray<Cci.INamespaceTypeDefinition> GetAnonymousTypes()
{
if (EmitOptions.EmitMetadataOnly)
{
......@@ -436,7 +436,7 @@ private static void GetExportedTypes(NamespaceOrTypeSymbol symbol, int parentInd
}
}
public override ImmutableArray<Cci.ExportedType> GetExportedTypes(DiagnosticBag diagnostics)
public sealed override ImmutableArray<Cci.ExportedType> GetExportedTypes(DiagnosticBag diagnostics)
{
Debug.Assert(HaveDeterminedTopLevelTypes);
......@@ -1073,7 +1073,7 @@ public static Cci.TypeMemberVisibility MemberVisibility(Symbol symbol)
}
}
internal override Cci.IMethodReference Translate(MethodSymbol symbol, DiagnosticBag diagnostics, bool needDeclaration)
internal sealed override Cci.IMethodReference Translate(MethodSymbol symbol, DiagnosticBag diagnostics, bool needDeclaration)
{
return Translate(symbol, null, diagnostics, null, needDeclaration);
}
......
......@@ -668,5 +668,74 @@ static void Main()
CompileAndVerify(comp, expectedOutput: "2");
}
[WorkItem(294553, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=294553")]
[Fact]
public void VoidPointerWithCustomModifiers()
{
var ilSource =
@".class public A
{
// F1(void* p)
.method public static void F1(void* p) { ret }
// F2(const void* p)
.method public static void F2(void modopt([mscorlib]System.Runtime.CompilerServices.IsConst)* p) { ret }
// F3(void* const p)
.method public static void F3(void* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) p) { ret }
// F4(const void* const p)
.method public static void F4(void modopt([mscorlib]System.Runtime.CompilerServices.IsConst)* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) p) { ret }
}";
var source =
@"class B
{
static void Main()
{
unsafe
{
A.F1(null);
A.F2(null);
A.F3(null);
A.F4(null);
}
}
}";
var compilation = CreateCompilationWithCustomILSource(source, ilSource, options: TestOptions.UnsafeReleaseExe);
compilation.VerifyDiagnostics();
CompileAndVerify(compilation);
}
[Fact]
public void IntPointerWithCustomModifiers()
{
var ilSource =
@".class public A
{
// F1(int* p)
.method public static void F1(int32* p) { ret }
// F2(const int* p)
.method public static void F2(int32 modopt([mscorlib]System.Runtime.CompilerServices.IsConst)* p) { ret }
// F3(int* const p)
.method public static void F3(int32* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) p) { ret }
// F4(const int* const p)
.method public static void F4(int32 modopt([mscorlib]System.Runtime.CompilerServices.IsConst)* modopt([mscorlib]System.Runtime.CompilerServices.IsConst) p) { ret }
}";
var source =
@"class B
{
static void Main()
{
unsafe
{
A.F1(null);
A.F2(null);
A.F3(null);
A.F4(null);
}
}
}";
var compilation = CreateCompilationWithCustomILSource(source, ilSource, options: TestOptions.UnsafeReleaseExe);
compilation.VerifyDiagnostics();
CompileAndVerify(compilation);
}
}
}
......@@ -882,7 +882,7 @@ internal override bool SupportsPrivateImplClass
#endregion
public override Cci.ITypeReference GetPlatformType(Cci.PlatformType platformType, EmitContext context)
public sealed override Cci.ITypeReference GetPlatformType(Cci.PlatformType platformType, EmitContext context)
{
Debug.Assert((object)this == context.Module);
......
......@@ -3655,16 +3655,8 @@ private void SerializeTypeReference(SignatureTypeEncoder encoder, ITypeReference
if (pointerTypeReference != null)
{
typeReference = pointerTypeReference.GetTargetType(Context);
if (module.IsPlatformType(typeReference, PlatformType.SystemVoid))
{
encoder.VoidPointer();
return;
}
else
{
encoder = encoder.Pointer();
continue;
}
encoder = encoder.Pointer();
continue;
}
IGenericTypeParameterReference genericTypeParameterReference = typeReference.AsGenericTypeParameterReference;
......@@ -3803,6 +3795,13 @@ private static void SerializePrimitiveType(SignatureTypeEncoder encoder, Primiti
encoder.String();
break;
case PrimitiveTypeCode.Void:
// "void" is handled specifically for "void*" with custom modifiers.
// If SignatureTypeEncoder supports such cases directly, this can
// be removed. See https://github.com/dotnet/corefx/issues/14571.
encoder.Builder.WriteByte((byte)System.Reflection.Metadata.PrimitiveTypeCode.Void);
break;
default:
throw ExceptionUtilities.UnexpectedValue(primitiveType);
}
......
......@@ -78,7 +78,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
End Get
End Property
Public Overrides ReadOnly Property GenerateVisualBasicStylePdb As Boolean
Public NotOverridable Overrides ReadOnly Property GenerateVisualBasicStylePdb As Boolean
Get
Return True
End Get
......@@ -122,7 +122,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
End Get
End Property
Protected Overrides Iterator Function GetAssemblyReferencesFromAddedModules(diagnostics As DiagnosticBag) As IEnumerable(Of Cci.IAssemblyReference)
Protected NotOverridable Overrides Iterator Function GetAssemblyReferencesFromAddedModules(diagnostics As DiagnosticBag) As IEnumerable(Of Cci.IAssemblyReference)
Dim modules As ImmutableArray(Of ModuleSymbol) = SourceModule.ContainingAssembly.Modules
For i As Integer = 1 To modules.Length - 1
......@@ -188,7 +188,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return SourceModule.GetCustomAttributesToEmit(Me.CompilationState)
End Function
Public Overrides Function GetSymbolToLocationMap() As MultiDictionary(Of Cci.DebugSourceDocument, Cci.DefinitionWithLocation)
Public NotOverridable Overrides Function GetSymbolToLocationMap() As MultiDictionary(Of Cci.DebugSourceDocument, Cci.DefinitionWithLocation)
Dim result As New MultiDictionary(Of Cci.DebugSourceDocument, Cci.DefinitionWithLocation)()
Dim namespacesAndTypesToProcess As New Stack(Of NamespaceOrTypeSymbol)()
......@@ -330,7 +330,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return False
End Function
Friend Overrides Function GetAnonymousTypes() As ImmutableArray(Of Cci.INamespaceTypeDefinition)
Friend NotOverridable Overrides Function GetAnonymousTypes() As ImmutableArray(Of Cci.INamespaceTypeDefinition)
If EmitOptions.EmitMetadataOnly Then
Return ImmutableArray(Of Cci.INamespaceTypeDefinition).Empty
End If
......@@ -379,7 +379,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return ImmutableArray(Of NamedTypeSymbol).Empty
End Function
Public Overrides Function GetExportedTypes(diagnostics As DiagnosticBag) As ImmutableArray(Of Cci.ExportedType)
Public NotOverridable Overrides Function GetExportedTypes(diagnostics As DiagnosticBag) As ImmutableArray(Of Cci.ExportedType)
Debug.Assert(HaveDeterminedTopLevelTypes)
If _lazyExportedTypes.IsDefault Then
......@@ -598,11 +598,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return typeSymbol
End Function
Public Overrides Function GetInitArrayHelper() As Cci.IMethodReference
Public NotOverridable Overrides Function GetInitArrayHelper() As Cci.IMethodReference
Return DirectCast(Compilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_RuntimeHelpers__InitializeArrayArrayRuntimeFieldHandle), MethodSymbol)
End Function
Public Overrides Function IsPlatformType(typeRef As Cci.ITypeReference, platformType As Cci.PlatformType) As Boolean
Public NotOverridable Overrides Function IsPlatformType(typeRef As Cci.ITypeReference, platformType As Cci.PlatformType) As Boolean
Dim namedType = TryCast(typeRef, NamedTypeSymbol)
If namedType IsNot Nothing Then
......@@ -616,7 +616,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return False
End Function
Protected Overrides Function GetCorLibraryReferenceToEmit(context As EmitContext) As Cci.IAssemblyReference
Protected NotOverridable Overrides Function GetCorLibraryReferenceToEmit(context As EmitContext) As Cci.IAssemblyReference
Dim corLib = CorLibrary
If Not corLib.IsMissing AndAlso
......@@ -643,7 +643,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return _disableJITOptimization.ContainsKey(methodSymbol)
End Function
Protected Overrides Function CreatePrivateImplementationDetailsStaticConstructor(details As PrivateImplementationDetails, syntaxOpt As SyntaxNode, diagnostics As DiagnosticBag) As Cci.IMethodDefinition
Protected NotOverridable Overrides Function CreatePrivateImplementationDetailsStaticConstructor(details As PrivateImplementationDetails, syntaxOpt As SyntaxNode, diagnostics As DiagnosticBag) As Cci.IMethodDefinition
Return New SynthesizedPrivateImplementationDetailsSharedConstructor(SourceModule, details, GetUntranslatedSpecialType(SpecialType.System_Void, syntaxOpt, diagnostics))
End Function
End Class
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册