Skip to content

fix(codegen): Convert pointer to actual type when passing by-value #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 7, 2023

Conversation

volsa
Copy link
Member

@volsa volsa commented Nov 28, 2023

Resolves #1037

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 PR fixes it, in that the commented IR is generated - specifically before passing the argument into function B it is bitcast into its actual type.


(A minimal example to reproduce on master)

TYPE mytype : ARRAY [0..2] of DWORD; END_TYPE

FUNCTION main : DINT
    VAR
        arr : mytype;
    END_VAR

	function1(arr);
END_FUNCTION

FUNCTION function1 : DINT
    VAR_IN_OUT
        val   : mytype;
    END_VAR

    function2(val);
END_FUNCTION

FUNCTION function2 : DINT
    VAR_INPUT
        stat : mytype;
    END_VAR
END_FUNCTION

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (cf34cf6) 95.71% compared to head (4dcc25b) 95.73%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/codegen/generators/expression_generator.rs 88.57% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1039      +/-   ##
==========================================
+ Coverage   95.71%   95.73%   +0.02%     
==========================================
  Files         153      153              
  Lines       42715    42883     +168     
==========================================
+ Hits        40883    41054     +171     
+ Misses       1832     1829       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@volsa volsa mentioned this pull request Nov 28, 2023
@volsa volsa marked this pull request as draft November 29, 2023 08:53
@volsa volsa changed the title fix(codegen): Avoid casting if the types do not differ fix(codegen): Convert pointer to actual type when passing by-value Dec 6, 2023
@volsa volsa marked this pull request as ready for review December 6, 2023 09:46
@volsa volsa requested review from ghaith and mhasel December 6, 2023 09:48
Copy link
Member

@mhasel mhasel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@volsa volsa merged commit 1e88fe5 into master Dec 7, 2023
@volsa volsa deleted the cast-unreachable branch December 7, 2023 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entered unreachable!() code in llvm_typesystem.rs
3 participants