Skip to content
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

Local variable gets initialised in wrong scope #1301

Open
superaxander opened this issue Jan 6, 2025 · 0 comments
Open

Local variable gets initialised in wrong scope #1301

superaxander opened this issue Jan 6, 2025 · 0 comments
Labels
A-Bug F-C Frontend: C F-CPP Frontend: C++

Comments

@superaxander
Copy link
Member

In C we can declare variables inside a loop and take the address of these variables. If we do that, the variable will be replaced by a pointer. In the VariableToPointer pass we add a method call to inhale permission to access the pointer at the start of the Scope (meaning the Scope COL node) where it is declared. Unfortunately, since the Scope containing LocalDecl is empty until the CollectLocalDeclarations pass the Scope node is removed by the PrettifyBlocks pass. Therefore the permission for the pointer is inhaled in the scope outside of the loop which means that the permission is not available inside the loop since it isn't included in the loop invariant.

The solution will probably be to either keep the Scopes around for longer, automatically re-add the Scope if we happen to be inside of a Loop, or we move VariableToPointer before CollectLocalDeclarations and do the initialisation for LocalDecls as well as Scopes.

Crash Message

An error condition was reached, which should be statically unreachable. Assigning to a local can never fail.. Inner failure:
 > ======================================
 > At /tmp/vercors-interpreted-17040729019032010151.i
 > --------------------------------------
 >     8  int main() {
 >     9      while (0 == 0) {
 >                   [------
 >    10          int p = 10;
 >                    ------]
 >    11          int *pp = &p;
 >    12          p = 5;
 > --------------------------------------
 > At /home/alexander/vercors-2/test.c
 > --------------------------------------
 >     1  int main() {
 >     2      while (0 == 0) {
 >       [---------------------
 >     3          int p = 10;
 >        ---------------------]
 >     4          int *pp = &p;
 >     5          p = 5;
 > --------------------------------------
 > Insufficient permission to assign to field. (https://utwente.nl/vercors#assignFieldFailed)
 > ======================================

File Inputs

/home/alexander/vercors-2/test.c
int main() {
    while (0 == 0) {
        int p = 10;
        int *pp = &p;
        p = 5;
    }

    return 0;
}
@superaxander superaxander added A-Bug F-C Frontend: C F-CPP Frontend: C++ labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Bug F-C Frontend: C F-CPP Frontend: C++
Projects
None yet
Development

No branches or pull requests

1 participant