Skip to content

Commit 8926842

Browse files
authored
Fixed bug causing Appending Module flags to fail (#51)
* Restored Entrypoint names on overloaded P/Invokes * Added tests to validate appending ModuleFLags operate correctly.
1 parent f37479a commit 8926842

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Llvm.NET/Native/CustomGenerated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ internal static partial class NativeMethods
356356
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
357357
internal static extern int LLVMGetValueID( LLVMValueRef @val );
358358

359-
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
359+
[DllImport( LibraryPath, EntryPoint = "LLVMBuildIntCast2", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
360360
internal static extern LLVMValueRef LLVMBuildIntCast( LLVMBuilderRef @param0, LLVMValueRef @Val, LLVMTypeRef @DestTy, [MarshalAs( UnmanagedType.Bool )]bool isSigned, [MarshalAs( UnmanagedType.LPStr )] string @Name );
361361

362362
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
@@ -401,7 +401,7 @@ internal static partial class NativeMethods
401401
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
402402
internal static extern void LLVMAddModuleFlag( LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs( UnmanagedType.LPStr )] string @name, UInt32 @value );
403403

404-
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
404+
[DllImport( LibraryPath, EntryPoint = "LLVMAddModuleFlagMetadata", CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]
405405
internal static extern void LLVMAddModuleFlag( LLVMModuleRef @M, LLVMModFlagBehavior behavior, [MarshalAs( UnmanagedType.LPStr )] string @name, LLVMMetadataRef @value );
406406

407407
[DllImport( LibraryPath, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true )]

src/Llvm.NETTests/MDNodeTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ public class MDNodeTests
2323
// Assert.Inconclusive( );
2424
//}
2525
*/
26+
[TestMethod]
27+
public void AppendingModuleFlagsTest( )
28+
{
29+
var targetMachine = TargetTests.GetTargetMachine( );
30+
using( var ctx = new Context( ) )
31+
using( var module = ctx.CreateBitcodeModule( "test.bc", SourceLanguage.CSharp, "test.cs", "unittests" ) )
32+
{
33+
module.AddModuleFlag( ModuleFlagBehavior.Append, "testMD", module.CreateMDNode( "testValue" ) );
34+
Assert.AreEqual( 1, module.ModuleFlags.Count );
35+
var flag = module.ModuleFlags[ "testMD" ];
36+
Assert.IsNotNull( flag );
37+
Assert.AreEqual( ModuleFlagBehavior.Append, flag.Behavior );
38+
Assert.AreEqual( "testMD", flag.Name );
39+
Assert.IsInstanceOfType( flag.Metadata, typeof( MDTuple ) );
40+
var tuple = ( MDTuple )flag.Metadata;
41+
Assert.AreEqual( "testValue", tuple.GetOperandString( 0 ) );
42+
}
43+
}
2644

2745
[TestMethod]
2846
public void OperandsAreAccessibleTest()

0 commit comments

Comments
 (0)