diff --git a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java index c525ae6a07..4debd09931 100644 --- a/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CTriggerObjectsGenerator.java @@ -731,6 +731,9 @@ private static String deferredFillTriggerTable( } var cumulativePortWidth = 0; for (PortInstance port : Iterables.filter(reaction.effects, PortInstance.class)) { + // If this port does not have any destinations, do not generate code for it. + if (port.eventualDestinations().isEmpty()) continue; + code.pr("for (int i = 0; i < "+reaction.getParent().getTotalWidth()+"; i++) triggers_index[i] = "+cumulativePortWidth+";"); for (SendRange srcRange : port.eventualDestinations()) { if (currentFederate.contains(port.getParent())) { diff --git a/test/C/src/MultipleOutputs.lf b/test/C/src/MultipleOutputs.lf new file mode 100644 index 0000000000..8db9e5e6f9 --- /dev/null +++ b/test/C/src/MultipleOutputs.lf @@ -0,0 +1,35 @@ +// This test checks for one of the issues arised in the solution of EECS149 Lab +// Chapter 7. In this case, a reactor has two output ports, the first one of +// which is dangling. The generated code should not have any segmentation +// faults. +target C { + timeout: 1 sec, + fast: true +} + +reactor C { + output x: int + output z: int + timer t(0, 100 msec) + + reaction(t) -> x, z {= + lf_set(x, 42); + lf_set(z, 44); + =} +} + +main reactor { + c = new C() + state triggered: bool(true) + + reaction(c.z) {= + lf_print("c.z = %d", c.z->value); + self->triggered = true; + =} + + reaction(shutdown) {= + if (!self->triggered) { + lf_print_error_and_exit("Reaction never triggered.\n"); + } + =} +}