You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
InstructionBuilder.SDiv creates UDiv instead of SDiv.
Here's some example code to demonstrate the issue.
publicvoidSDivBug(){Contextcontext=newContext();BitcodeModulemodule=context.CreateBitcodeModule();// We're going to create the LLVM equivalent of this C function:// int test(int x)// {// return x / -3;// }IFunctionTypefunction_type=context.GetFunctionType(context.Int32Type,newITypeRef[]{context.Int32Type});IrFunctionfunction=module.CreateFunction("test",function_type);BasicBlockblock=function.AppendBasicBlock("entry");InstructionBuilderbuilder=newInstructionBuilder(block);Valuelhs=function.Parameters[0];Valuerhs=context.CreateConstant(-3);// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvValuesdiv=builder.SDiv(lhs,rhs);// <== Creating SDiv// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^builder.Return(sdiv);if(!module.Verify(outstringmsg)){Console.WriteLine("module.Verify gave error: {0}",msg);}else{Console.WriteLine("module.Verify was okay");}Console.WriteLine(module.WriteToString());}
Running this gives the following output:
module.Verify was okay
define i32 @test(i32 %0) {
entry:
%1 = udiv i32 %0, -3
ret i32 %1
}
Note that we have udiv instead of sdiv.
It looks like the following part of the InstructionBuilder code is selecting the wrong op builder:
InstructionBuilder.SDiv creates UDiv instead of SDiv.
Here's some example code to demonstrate the issue.
Running this gives the following output:
Note that we have udiv instead of sdiv.
It looks like the following part of the InstructionBuilder code is selecting the wrong op builder:
Llvm.NET/src/Ubiquity.NET.Llvm/Instructions/InstructionBuilder.cs
Lines 219 to 229 in aabdd51
The text was updated successfully, but these errors were encountered: