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

Nested arrays gives initArray and setLength undefined values #145

Open
emwap opened this issue Mar 19, 2014 · 2 comments
Open

Nested arrays gives initArray and setLength undefined values #145

emwap opened this issue Mar 19, 2014 · 2 comments
Labels

Comments

@emwap
Copy link
Member

emwap commented Mar 19, 2014

If initArray or setLength are passed a pointer to an uninitialized array they will cause a segmentation fault as exemplified by this code:

vectorInPairInVector :: Data WordN -> Pull DIM1 (Data WordN, Pull1 WordN)
vectorInPairInVector l = indexed1 l $ \i -> (i, indexed1 i id)

In the generated code below, the second setLength (second line in the outer loop) is fed an uninitialized value.

void test(uint32_t v0, struct s_arr_unsignedS32_1_arr_s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD_UD * out)
{
  (*out).member1 = setLength((*out).member1, sizeof(uint32_t), 1);
  at(uint32_t,(*out).member1,0) = v0;
  (*out).member2 = initArray((*out).member2, sizeof(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD), v0);
  for (uint32_t v3 = 0; v3 < v0; v3 += 1)
  {
    (at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member1 = v3;
    ((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member1 = setLength(((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member1, sizeof(uint32_t), 1);
    at(uint32_t,((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member1,0) = v3;
    ((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member2 = initArray(((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member2, sizeof(uint32_t), v3);
    for (uint32_t v6 = 0; v6 < v3; v6 += 1)
    {
      at(uint32_t,((at(struct s_unsignedS32_s_arr_unsignedS32_1_arr_unsignedS32_UD,(*out).member2,v3)).member2).member2,v6) = v6;
    }
  }
}
@emwap emwap added the bug label Mar 19, 2014
emwap added a commit that referenced this issue Mar 19, 2014
@pjonsson pjonsson changed the title initArray and setLength can not handle uninitialized arrays Nested arrays gives initArray and setLength undefined values Mar 19, 2014
@pjonsson
Copy link
Member

Is this something you hit frequently? We have a single application that suffers from this problem now that the multidim work is in the main branch.

We have type information available at compile time. Can we use that to decide whether to zero the memory block or not?

@emwap
Copy link
Member Author

emwap commented Mar 19, 2014

Yes, I have seen it when there is some nested structure in the result, e.g. Pull DIM1 (Data WordN, Pull1 WordN). Then the data structure for the inner array is not properly initialized.

Yes, I think we have enough information at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants