Skip to content

[SUGGESTION][FIX] Add pointer deduce type support #94

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

Conversation

filipsajdak
Copy link
Contributor

Current implementation is not handling deduced pointer types when analysing safety checks.

It means that this code will pass safety checks

i : int = 42;
pi := i&;
pi = 0; // this should trigger error

This change introduce support for deduced pointer types and makes safety checks work with below code:

main: (argc : int, argv : **char) -> int = {
    a:     int = 2;
    pa:   *int = a&;
    ppa: **int = pa&;

    pa = 0; // error

    pa2:= ppa*;
    pa2 = 0; // error

    pa3 := a&;
    pa3 = 0;  // error
    pa3 += 2; // error

    ppa2 := pa2&;
    pa4 := ppa2*;

    pa4 = 0; // error

    pppa := ppa&;
    pa5 := pppa**;
    pa5 = 0; // error

    return a*pa**ppa**; // 8
}

and will cause errors

tests/pointer-to-pointer.cpp2...
pointer-to-pointer.cpp2(6,8): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(9,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(12,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(13,9): error: += - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(18,9): error: = - pointer assignment from null or integer is illegal
pointer-to-pointer.cpp2(22,9): error: = - pointer assignment from null or integer is illegal
  ==> program violates lifetime safety guarantee - see previous errors

Based on #93

@filipsajdak
Copy link
Contributor Author

Pointers from cpp1 are handled here #96

@filipsajdak filipsajdak force-pushed the fsajdak-pointer-deduce-type-support branch 3 times, most recently from d3ce69d to 5ac1621 Compare November 7, 2022 23:35
@filipsajdak filipsajdak force-pushed the fsajdak-pointer-deduce-type-support branch 3 times, most recently from 91b5885 to 8cb1fd1 Compare November 29, 2022 22:27
@filipsajdak filipsajdak force-pushed the fsajdak-pointer-deduce-type-support branch 2 times, most recently from e9acabd to 4cf81ba Compare December 4, 2022 01:39
@filipsajdak filipsajdak force-pushed the fsajdak-pointer-deduce-type-support branch from 4cf81ba to e1b6443 Compare December 6, 2022 22:19
@filipsajdak
Copy link
Contributor Author

Replaced by #196

@filipsajdak filipsajdak closed this Jan 3, 2023
@filipsajdak filipsajdak deleted the fsajdak-pointer-deduce-type-support branch January 12, 2023 21:22
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.

1 participant