Skip to content

Ouliner generates incorrect code for variable length array decls using variables defined inside the region: #6

Description

@tiagolascasas

For example, this code has a variable length array (VLA) declaration that uses a variable, W, defined inside the region:

#pragma clava begin_outline imsmooth_out1
int W;
W = (int) ceil(4 * s);
float temp[2 * W + 1];
F2D *buffer;
float acc;
acc = 0.0;
#pragma clava end_outline imsmooth_out1

This leads to :

float acc;
F2D *buffer;
float temp[2 * W + 1];
int W;
imsmooth_out1(&W, &s, &acc);

Which is incorrect, because it declares W and defines it on the outlined function, both after W is used for defining the array. In this case, we could fix this by moving temp below the outlined function, that would only work for this case; it wouldn't fix the more generic case where temp can be used inside the region itself. Fixing this isn't trivial, and I see no way of doing it without turning the array dynamic. Converting all VLAs to malloc/calloc might make further sense considering that VLAs are banned in C++ and discouraged in modern C:

float acc;
F2D *buffer;
float *temp;
int W;
imsmooth_out1(&W, &s, &acc);
temp = (float*)malloc((2 * W + 1) * sizeof(float));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions