forked from PLC-lang/rusty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(codegen): Convert pointer to actual type when passing by-value (P…
…LC-lang#1039) We were missing an edge-case where an argument is passed into a function A by-ref (INOUT) which in turn is passed into a function B by-val (INPUT) which generated the following IR for a DINT array ``` %call = call i32 @function1(i32 %load_x)` // we want `@function1([5 x i32] %load_x)` however ``` This commit fixes it, in that the commented IR is generated - specifically before passing the argument into function B it is bit-cast into its actual type.
- Loading branch information
Showing
5 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...sts/snapshots/rusty__codegen__tests__function_tests__argument_fed_by_ref_then_by_val.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
source: src/codegen/tests/function_tests.rs | ||
expression: result | ||
--- | ||
; ModuleID = 'main' | ||
source_filename = "main" | ||
|
||
define i32 @main() { | ||
entry: | ||
%main = alloca i32, align 4 | ||
%arr = alloca [5 x i32], align 4 | ||
%0 = bitcast [5 x i32]* %arr to i8* | ||
call void @llvm.memset.p0i8.i64(i8* align 1 %0, i8 0, i64 ptrtoint ([5 x i32]* getelementptr ([5 x i32], [5 x i32]* null, i32 1) to i64), i1 false) | ||
store i32 0, i32* %main, align 4 | ||
%1 = bitcast [5 x i32]* %arr to i32* | ||
%call = call i32 @fn_by_ref(i32* %1) | ||
%main_ret = load i32, i32* %main, align 4 | ||
ret i32 %main_ret | ||
} | ||
|
||
define i32 @fn_by_ref(i32* %0) { | ||
entry: | ||
%fn_by_ref = alloca i32, align 4 | ||
%arg_by_ref = alloca i32*, align 8 | ||
store i32* %0, i32** %arg_by_ref, align 8 | ||
store i32 0, i32* %fn_by_ref, align 4 | ||
%deref = load i32*, i32** %arg_by_ref, align 8 | ||
%1 = bitcast i32* %deref to [5 x i32]* | ||
%load_arg_by_ref = load [5 x i32], [5 x i32]* %1, align 4 | ||
%call = call i32 @fn_by_val([5 x i32] %load_arg_by_ref) | ||
%fn_by_ref_ret = load i32, i32* %fn_by_ref, align 4 | ||
ret i32 %fn_by_ref_ret | ||
} | ||
|
||
define i32 @fn_by_val([5 x i32] %0) { | ||
entry: | ||
%fn_by_val = alloca i32, align 4 | ||
%arg_by_val = alloca [5 x i32], align 4 | ||
store [5 x i32] %0, [5 x i32]* %arg_by_val, align 4 | ||
store i32 0, i32* %fn_by_val, align 4 | ||
%fn_by_val_ret = load i32, i32* %fn_by_val, align 4 | ||
ret i32 %fn_by_val_ret | ||
} | ||
|
||
; Function Attrs: argmemonly nofree nounwind willreturn writeonly | ||
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #0 | ||
|
||
attributes #0 = { argmemonly nofree nounwind willreturn writeonly } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters