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

Modal models with banks cause segmentation fault #1943

Closed
edwardalee opened this issue Aug 13, 2023 · 4 comments
Closed

Modal models with banks cause segmentation fault #1943

edwardalee opened this issue Aug 13, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@edwardalee
Copy link
Collaborator

The following program segfaults when executed. Below is a second program that does the same thing without banks. The second program works fine.

target C {
    timeout: 100 ms
}
reactor B(bank_index: int = 0) {
  input in:int
  output out:int
  reaction(in) -> out {=
    lf_set(out, self->bank_index);
  =}
}
reactor Modal {
  input in:int
  output out1:int
  output out2:int
  output out3:int
  initial mode A {
    reaction(startup) -> B {=
      lf_set_mode(B);
    =}
  }
  mode B {
    b = new[3] B()
    (in)+ -> b.in
    b.out -> out1, out2, out3
  }
}
main reactor {
  m = new Modal()
  timer t(0, 10 ms)
  reaction(t) -> m.in {=
    lf_set(m.in, 42);
  =}
  reaction(m.out3) {=
    lf_print("out3 = %d", m.out3->value);
  =}
}

The following variant does not segfault:

target C {
    timeout: 100 ms
}
reactor B(b: int = 0) {
  input in:int
  output out:int
  reaction(in) -> out {=
    lf_set(out, self->b);
  =}
}
reactor Modal {
  input in:int
  output out1:int
  output out2:int
  output out3:int
  initial mode A {
    reaction(startup) -> B {=
      lf_set_mode(B);
    =}
  }
  mode B {
    b1 = new B(b = 0)
    b2 = new B(b = 1)
    b3 = new B(b = 2)
    (in)+ -> b1.in, b2.in, b3.in
    b1.out, b2.out, b3.out -> out1, out2, out3
  }
}
main reactor {
  m = new Modal()
  timer t(0, 10 ms)
  reaction(t) -> m.in {=
    lf_set(m.in, 42);
  =}
  reaction(m.out3) {=
    lf_print("out3 = %d", m.out3->value);
  =}
}
@edwardalee edwardalee added bug Something isn't working modal models labels Aug 13, 2023
@a-sr
Copy link
Collaborator

a-sr commented Aug 24, 2023

I was able to follow the error and it is not related to modes.
The following program also results in a segmentation fault.

target C {
    timeout: 100 ms
}
reactor B(bank_index: int = 0) {
  input in:int
  output out_problem:int
  reaction(in) -> out_problem {=
    lf_set(out_problem, self->bank_index);
  =}
}
reactor A {
  input in:int
  output out1:int
  output out2:int
  output out3:int
  
  b = new[3] B()
  (in)+ -> b.in
  b.out_problem -> out1, out2, out3
}
main reactor {
  m = new A()
  timer t(0, 10 ms)
  reaction(t) -> m.in {=
    lf_set(m.in, 42);
  =}
  reaction(m.out3) {=
    lf_print("out3 = %d", m.out3->value);
  =}
}

The segmentation fault occurs in

void _lf_set_present(lf_port_base_t* port) {
    environment_t *env = port->source_reactor->environment;
    [...]

because source_reactor is NULL caused by lf_set(out_problem, self->bank_index); in bank reactor 0.
It seems like the there is something wrong with the connection of port in banks because the port source_reactor of port out_problem is only set once for index 2 in _lf_initialize_trigger_objects.

    // For reference counting, set num_destinations for port Banks1.m.B.b.out_problem.
    // Iterate over range Banks1.m.B.b.out_problem(2,1)->[Banks1.m.out3(0,1)].
    {
        int src_runtime = 2; SUPPRESS_UNUSED_WARNING(src_runtime); // Runtime index.
        int src_channel = 0; SUPPRESS_UNUSED_WARNING(src_channel); // Channel index.
        int src_bank = 2; SUPPRESS_UNUSED_WARNING(src_bank); // Bank index.
        int range_count = 0; SUPPRESS_UNUSED_WARNING(range_count);
        banks1_m_b_b_self[src_runtime]->_lf_out_problem._base.num_destinations = 1;
        banks1_m_b_b_self[src_runtime]->_lf_out_problem._base.source_reactor = (self_base_t*)banks1_m_b_b_self[src_runtime];
    }

It looks like there may be a loop missing but I am not sure. Could someone help me with this?

@a-sr a-sr removed the modal models label Aug 24, 2023
@a-sr
Copy link
Collaborator

a-sr commented Aug 24, 2023

I just realized that only port out3 is connected and unconnected ports sometimes cause problems (#1489 & #1321) and this may be related.

@lhstrh
Copy link
Member

lhstrh commented Sep 7, 2023

Could be related to #1953.

@edwardalee
Copy link
Collaborator Author

This was fixed via #2011 and 275 in reactor-c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants