Skip to content

Commit 2e83b87

Browse files
committed
Repo Update
- Fix range check error with negative integers in ExtractLLVMValue()
1 parent 24f66a6 commit 2e83b87

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

examples/testbed/UTestbed.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ procedure RunTests();
5656
03: TTestBitwise.RunAllTests();
5757
04: TTestComparison.RunAllTests();
5858
05: TTestControlFlow.RunAllTests();
59-
//06: TTestFunctionCall.RunAllTests(); // TODO: fix range check error
59+
06: TTestFunctionCall.RunAllTests();
6060
07: TTestFunction.RunAllTests();
6161
08: TTestJIT.RunAllTests();
6262
09: TTestMemory.RunAllTests();

src/libLLVM.pas

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,22 +600,32 @@ function TLLVM.LLVMTypeToBasicType(ALLVMType: LLVMTypeRef): TLLDataType;
600600
end;
601601

602602
// Direct TValue <-> LLVM conversion (NO TPaValue!)
603+
604+
procedure test1();
605+
begin
606+
end;
607+
608+
procedure test2();
609+
begin
610+
end;
611+
612+
603613
function TLLVM.ExtractLLVMValue(const AModuleId: string; const AValue: TValue): LLVMValueRef;
604614
var
605615
LModuleState: TLLModuleState;
606616
begin
607617
LModuleState := GetModuleState(AModuleId);
608-
618+
609619
if AValue.IsEmpty then
610620
raise Exception.Create('Cannot convert empty TValue to LLVM value')
611621
else if AValue.IsType<LLVMValueRef> then
612622
Result := AValue.AsType<LLVMValueRef> // Already an LLVM value
613623
else if AValue.IsType<string> then
614624
Result := ExtractLLVMValue(AModuleId, StringValue(AModuleId, AValue.AsString))
615625
else if AValue.IsType<Integer> then
616-
Result := LLVMConstInt(GetBasicType(dtInt32, LModuleState.Context), AValue.AsInteger, 1)
626+
Result := LLVMConstInt(GetBasicType(dtInt32, LModuleState.Context), UInt64(AValue.AsInteger), 1)
617627
else if AValue.IsType<Int64> then
618-
Result := LLVMConstInt(GetBasicType(dtInt64, LModuleState.Context), AValue.AsInt64, 1)
628+
Result := LLVMConstInt(GetBasicType(dtInt64, LModuleState.Context), UInt64(AValue.AsInt64), 1)
619629
else if AValue.IsType<Boolean> then
620630
Result := LLVMConstInt(GetBasicType(dtInt1, LModuleState.Context), Ord(AValue.AsBoolean), 0)
621631
else if AValue.IsType<Double> then

src/tests/libLLVM.Test.FunctionCall.pas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class procedure TTestFunctionCall.TestVoidFunctionCalls();
476476
begin
477477
try
478478
CreateModule('void_test')
479-
479+
480480
// Global variables for side effect demonstration
481481
.DeclareGlobal('void_test', 'counter', dtInt32, 0)
482482
.DeclareGlobal('void_test', 'accumulator', dtInt32, 0)
@@ -580,6 +580,8 @@ class procedure TTestFunctionCall.TestVoidFunctionCalls();
580580
Free();
581581
end;
582582
end;
583+
584+
writeln('got there');
583585
end;
584586

585587
(**

0 commit comments

Comments
 (0)